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.

268 lines
7.0 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. SakVlLs.cpp
  5. Abstract:
  6. Managed Volume node implementation.
  7. Author:
  8. Michael Moore [mmoore] 30-Sep-1998
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "SakVlLs.h"
  13. CSakVolList::CSakVolList()
  14. : CListCtrl(),
  15. m_nVolumeIcon(-1)
  16. {
  17. }
  18. CSakVolList::~CSakVolList()
  19. {
  20. }
  21. //-----------------------------------------------------------------------------
  22. //
  23. // PreSubclassWindow
  24. //
  25. // Create the image list for the list control. Set the desired
  26. // extended styles. Finally, Initilize the list header.
  27. //
  28. //
  29. void
  30. CSakVolList::PreSubclassWindow()
  31. {
  32. CreateImageList( );
  33. //
  34. // The style we want to see it Checkboxes and full row select
  35. //
  36. SetExtendedStyle( LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT );
  37. //
  38. // Create the columns for the list box
  39. //
  40. CString temp;
  41. INT index;
  42. LV_COLUMN col;
  43. INT column = 0;
  44. //
  45. // Also need to calculate some buffer space
  46. // Use 4 dialog units (for numeral)
  47. //
  48. CRect padRect( 0, 0, 8, 8 );
  49. ::MapDialogRect( GetParent()->m_hWnd, &padRect );
  50. //
  51. // Name Column
  52. //
  53. temp.LoadString(IDS_NAME);
  54. col.mask = ( LVCF_FMT | LVCF_WIDTH | LVCF_TEXT );
  55. col.fmt = LVCFMT_LEFT;
  56. col.cx = GetStringWidth( temp ) + padRect.Width( ) * 10;
  57. col.pszText = (LPTSTR)(LPCTSTR)temp;
  58. index = InsertColumn( column, &col );
  59. column++;
  60. //
  61. // Capacity Column
  62. //
  63. temp.LoadString( IDS_CAPACITY );
  64. col.cx = GetStringWidth( temp ) + padRect.Width( );
  65. col.pszText = (LPTSTR)(LPCTSTR)temp;
  66. InsertColumn( column, &col );
  67. column++;
  68. //
  69. // Free Space Column
  70. //
  71. temp.LoadString( IDS_FREESPACE );
  72. col.cx = GetStringWidth( temp ) + padRect.Width( );
  73. col.pszText = (LPTSTR)(LPCTSTR)temp;
  74. InsertColumn( column, &col );
  75. column++;
  76. CListCtrl::PreSubclassWindow();
  77. }
  78. //-----------------------------------------------------------------------------
  79. //
  80. // CreateImageList
  81. //
  82. // Load an image list with a single icon to represent a volume
  83. // and set the image list to be the newly created list.
  84. //
  85. //
  86. BOOL CSakVolList::CreateImageList ( )
  87. {
  88. BOOL bRet = TRUE;
  89. HICON hIcon;
  90. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  91. CWinApp* pApp = AfxGetApp( );
  92. bRet = m_imageList.Create( ::GetSystemMetrics( SM_CXSMICON ),
  93. ::GetSystemMetrics( SM_CYSMICON ),
  94. ILC_COLOR | ILC_MASK, 2,5 );
  95. if ( bRet )
  96. {
  97. hIcon = pApp->LoadIcon( IDI_NODEMANVOL );
  98. if ( hIcon != NULL )
  99. {
  100. m_nVolumeIcon = m_imageList.Add( hIcon );
  101. ::DeleteObject( hIcon );
  102. SetImageList( &m_imageList, LVSIL_SMALL );
  103. }
  104. else
  105. {
  106. bRet = FALSE;
  107. }
  108. }
  109. return( bRet );
  110. }
  111. //-----------------------------------------------------------------------------
  112. //
  113. // SetExtendedStyle
  114. //
  115. // The alternatives that are #if'd out are to call CListCtrl::SetExtendedStyle
  116. // or the ComCtrl.h declared ListView_SetExtendedListViewStyle. We will
  117. // eventually get rid of this function when the mfc headers and libs are
  118. // updated from then NT group.
  119. //
  120. //
  121. DWORD
  122. CSakVolList::SetExtendedStyle( DWORD dwNewStyle )
  123. {
  124. #if 0 // (_WIN32_IE >= 0x0400)
  125. return CListCtrl::SetExtendeStyle( dwNewStyle );
  126. #elif 0 //(_WIN32_IE >= 0x0300)
  127. return ListView_SetExtendedListViewStyle( m_hWnd, dwNewStyle );
  128. #else
  129. ASSERT(::IsWindow(m_hWnd));
  130. return (DWORD) ::SendMessage(m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM) dwNewStyle);
  131. #endif
  132. }
  133. //-----------------------------------------------------------------------------
  134. //
  135. // GetCheck
  136. //
  137. // The alternatives that are #if'd out are to call CListCtrl::GetCheck
  138. // or the ComCtrl.h declared ListView_GetCheckState. We will
  139. // eventually get rid of this function when the mfc headers and libs are
  140. // updated from then NT group.
  141. //
  142. // Note: I could not get the ListView_Get... to compile under our current
  143. // environment.
  144. //
  145. //
  146. BOOL
  147. CSakVolList::GetCheck ( int nItem ) const
  148. {
  149. #if 0 //(_WIN32_IE >= 0x0400)
  150. return CListCtrl::GetCheck( nItem );
  151. #elif 0 //(_WIN32_IE >= 0x0300)
  152. return ListView_GetCheckState( m_hWnd, nItem );
  153. #else
  154. ASSERT(::IsWindow(m_hWnd));
  155. int nState = (int)::SendMessage(m_hWnd, LVM_GETITEMSTATE, (WPARAM)nItem,
  156. (LPARAM)LVIS_STATEIMAGEMASK);
  157. // Return zero if it's not checked, or nonzero otherwise.
  158. return ((BOOL)(nState >> 12) -1);
  159. #endif
  160. }
  161. //-----------------------------------------------------------------------------
  162. //
  163. // SetCheck
  164. //
  165. // The alternatives that are #if'd out are to call CListCtrl::SetCheck
  166. // or the ComCtrl.h declared ListView_SetCheckState. We will
  167. // eventually get rid of this function when the mfc headers and libs are
  168. // updated from then NT group.
  169. //
  170. // Note: I could not get the ListView_Set... to compile under our current
  171. // environment.
  172. //
  173. //
  174. BOOL
  175. CSakVolList::SetCheck( int nItem, BOOL fCheck )
  176. {
  177. #if 0 //(_WIN32_IE >= 0x0400)
  178. return CListCtrl::SetCheck( nItem, fCheck );
  179. #elif 0 //(_WIN32_IE >= 0x0300)
  180. return ListView_SetCheckState( m_hWnd, nItem, fCheck );
  181. #else
  182. ASSERT(::IsWindow(m_hWnd));
  183. LVITEM lvi;
  184. lvi.stateMask = LVIS_STATEIMAGEMASK;
  185. /*
  186. Since state images are one-based, 1 in this macro turns the check off, and
  187. 2 turns it on.
  188. */
  189. lvi.state = INDEXTOSTATEIMAGEMASK((fCheck ? 2 : 1));
  190. return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)&lvi);
  191. #endif
  192. }
  193. //-----------------------------------------------------------------------------
  194. //
  195. // AppendItem
  196. //
  197. // Insert an item into the list with the Volume Icon with name, capacity
  198. // and free space. Return TRUE if successful and set pIndex = to the
  199. // index of the inserted list item.
  200. //
  201. //
  202. BOOL
  203. CSakVolList::AppendItem( LPCTSTR name, LPCTSTR capacity, LPCTSTR freeSpace , int * pIndex)
  204. {
  205. BOOL bRet = FALSE;
  206. int subItem = 1;
  207. int index = InsertItem( GetItemCount(), name, m_nVolumeIcon );
  208. if ( index != -1 )
  209. {
  210. LVITEM capItem;
  211. capItem.mask = LVIF_TEXT;
  212. capItem.pszText = (LPTSTR)capacity;
  213. capItem.iItem = index;
  214. capItem.iSubItem = subItem;
  215. subItem++;
  216. LVITEM freeItem;
  217. freeItem.mask = LVIF_TEXT;
  218. freeItem.pszText = (LPTSTR)freeSpace;
  219. freeItem.iItem = index;
  220. freeItem.iSubItem = subItem;
  221. subItem++;
  222. bRet = ( SetItem( &capItem ) && SetItem ( &freeItem) );
  223. }
  224. if ( pIndex != NULL )
  225. *pIndex = index;
  226. return bRet;
  227. }
  228. BEGIN_MESSAGE_MAP(CSakVolList, CListCtrl)
  229. //{{AFX_MSG_MAP(CSakVolList)
  230. //}}AFX_MSG_MAP
  231. END_MESSAGE_MAP()