Source code of Windows XP (NT5)
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.

216 lines
5.3 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991-1996 **/
  4. /**********************************************************************/
  5. /*
  6. UserList.cpp
  7. CListBox class for owner draw list that displays users and groups
  8. FILE HISTORY:
  9. jony Apr-1996 created
  10. */
  11. #include "stdafx.h"
  12. #include "resource.h"
  13. #include "UserList.h"
  14. const unsigned short BITMAP_HEIGHT = 18;
  15. const unsigned short BITMAP_WIDTH = 18;
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CUserList
  23. CUserList::CUserList()
  24. {
  25. m_pBitmap[0] = new CTransBmp;
  26. m_pBitmap[0]->LoadBitmap(IDB_USER_BITMAP);
  27. m_pBitmap[1] = new CTransBmp;
  28. m_pBitmap[1]->LoadBitmap(IDB_GLOBAL_GROUP_BITMAP);
  29. m_pBitmap[2] = new CTransBmp;
  30. m_pBitmap[2]->LoadBitmap(IDB_WORLD);
  31. m_pBitmap[3] = new CTransBmp;
  32. m_pBitmap[3]->LoadBitmap(IDB_LOCAL_GROUP_BITMAP);
  33. m_sHScrollWidth = 0;
  34. }
  35. CUserList::~CUserList()
  36. {
  37. delete m_pBitmap[0];
  38. delete m_pBitmap[1];
  39. delete m_pBitmap[2];
  40. delete m_pBitmap[3];
  41. }
  42. BEGIN_MESSAGE_MAP(CUserList, CListBox)
  43. //{{AFX_MSG_MAP(CUserList)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CUserList message handlers
  48. void CUserList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  49. {
  50. // is this a valid item?
  51. if ((GetCount() == LB_ERR) || (lpDrawItemStruct->itemID > (UINT)GetCount())) return;
  52. COLORREF crefOldText;
  53. COLORREF crefOldBk;
  54. CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
  55. pDC->SetBkMode(TRANSPARENT);
  56. HBRUSH hBrush;
  57. CTransBmp* pTempBmp = (CTransBmp*)lpDrawItemStruct->itemData;
  58. switch (lpDrawItemStruct->itemAction)
  59. {
  60. case ODA_SELECT:
  61. case ODA_DRAWENTIRE:
  62. // Display the text associated with the item.
  63. HBITMAP hBitmapOld;
  64. // Is the item selected?
  65. if (lpDrawItemStruct->itemState & ODS_SELECTED)
  66. {
  67. hBrush = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT));
  68. hBitmapOld = (HBITMAP)pDC->SelectObject(pTempBmp);
  69. crefOldText = pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT) );
  70. crefOldBk = pDC->SetBkColor(GetSysColor(COLOR_HIGHLIGHT) );
  71. }
  72. else
  73. {
  74. hBrush = (HBRUSH)GetStockObject( GetSysColor(COLOR_WINDOW));
  75. hBitmapOld = (HBITMAP)pDC->SelectObject(pTempBmp);
  76. crefOldText = pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
  77. crefOldBk = pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
  78. }
  79. pDC->FillRect(&(lpDrawItemStruct->rcItem), CBrush::FromHandle(hBrush));
  80. // display text
  81. TCHAR* pName = (TCHAR*)malloc(255 * sizeof(TCHAR));
  82. if (pName == NULL)
  83. {
  84. AfxMessageBox(IDS_GENERIC_NO_HEAP, MB_ICONEXCLAMATION);
  85. exit(1);
  86. }
  87. GetText(lpDrawItemStruct->itemID, pName);
  88. TCHAR* pName2;
  89. pName = _tcstok(pName, _T(";")); // gets the name
  90. pName2 = _tcstok(NULL, _T(";")); // gets the comment
  91. // format the name + comment
  92. int nTop = (lpDrawItemStruct->rcItem.bottom + lpDrawItemStruct->rcItem.top) / 2;
  93. pDC->TextOut(BITMAP_WIDTH + 6,
  94. (nTop - 8),
  95. pName);
  96. pDC->TextOut(130,
  97. (nTop - 8),
  98. pName2);
  99. free(pName);
  100. // Display bitmap
  101. nTop = (lpDrawItemStruct->rcItem.bottom + lpDrawItemStruct->rcItem.top - BITMAP_HEIGHT) / 2;
  102. pTempBmp->DrawTrans(pDC, lpDrawItemStruct->rcItem.left, nTop);
  103. pDC->SetBkColor(crefOldBk );
  104. pDC->SetTextColor(crefOldText );
  105. pDC->SelectObject(hBitmapOld);
  106. break;
  107. }
  108. }
  109. int CUserList::AddString(LPCTSTR lpItem)
  110. {
  111. int nPos = CListBox::AddString((const TCHAR*) lpItem);
  112. if (nPos == LB_ERR) return LB_ERR;
  113. SetItemData(nPos, (unsigned long)m_pBitmap[1]);
  114. return nPos;
  115. }
  116. int CUserList::AddString(LPCTSTR lpItem, USHORT usBitmapID)
  117. {
  118. int nPos = CListBox::AddString((const TCHAR*) lpItem);
  119. if (nPos == LB_ERR) return LB_ERR;
  120. SetItemData(nPos, (DWORD)m_pBitmap[usBitmapID]);
  121. return nPos;
  122. }
  123. void CUserList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  124. {
  125. lpMeasureItemStruct->itemHeight = 20;
  126. }
  127. int CUserList::VKeyToItem(UINT nKey, UINT nIndex)
  128. {
  129. // TODO: Add your code to handle a particular virtual key
  130. // return -1 = default action
  131. // return -2 = no further action
  132. // return index = perform default action for keystroke on
  133. // item specified by index
  134. if (nKey == 46) DeleteString(GetCurSel());
  135. return -1;
  136. }
  137. int CUserList::AddString(short nType, LPCTSTR lpItem)
  138. {
  139. int nPos = CListBox::AddString((const TCHAR*) lpItem);
  140. if (nPos == LB_ERR) return LB_ERR;
  141. SetItemData(nPos, (DWORD)m_pBitmap[nType]);
  142. return nPos;
  143. }
  144. short CUserList::GetBitmapID()
  145. {
  146. USHORT sSel = GetCurSel();
  147. if (sSel == LB_ERR) return -1;
  148. USHORT sCount = 0;
  149. while ((sCount < 4) && ((CBitmap*)GetItemData(sSel) != m_pBitmap[sCount])) sCount++;
  150. return sCount;
  151. }
  152. short CUserList::GetBitmapID(USHORT sSel)
  153. {
  154. USHORT sCount = 0;
  155. DWORD dwData = GetItemData(sSel);
  156. DWORD dwBmp = (DWORD)m_pBitmap[0];
  157. while ((sCount < 4) && (dwData != dwBmp))
  158. {
  159. sCount++;
  160. dwBmp = (DWORD)m_pBitmap[sCount];
  161. }
  162. return sCount;
  163. }