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.

306 lines
7.2 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. delowner.cpp
  7. Delete owner dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "DelOwner.h"
  12. #include "server.h"
  13. #include "actreg.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CDeleteOwner dialog
  21. int CALLBACK DelOwnerCompareFunc
  22. (
  23. LPARAM lParam1,
  24. LPARAM lParam2,
  25. LPARAM lParamSort
  26. )
  27. {
  28. return ((CDeleteOwner *) lParamSort)->HandleSort(lParam1, lParam2);
  29. }
  30. CDeleteOwner::CDeleteOwner(ITFSNode * pNode, CWnd* pParent /*=NULL*/)
  31. : CBaseDialog(CDeleteOwner::IDD, pParent)
  32. {
  33. m_spActRegNode.Set(pNode);
  34. m_nSortColumn = -1;
  35. for (int i = 0; i < COLUMN_MAX; i++)
  36. {
  37. m_aSortOrder[i] = TRUE; // ascending
  38. }
  39. //{{AFX_DATA_INIT(CDeleteOwner)
  40. // NOTE: the ClassWizard will add member initialization here
  41. //}}AFX_DATA_INIT
  42. }
  43. void CDeleteOwner::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CDeleteOwner)
  47. DDX_Control(pDX, IDC_RADIO_DELETE_RECORDS, m_radioDelete);
  48. DDX_Control(pDX, IDC_LIST_OWNER, m_listOwner);
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CDeleteOwner, CBaseDialog)
  52. //{{AFX_MSG_MAP(CDeleteOwner)
  53. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_OWNER, OnItemchangedListOwner)
  54. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_OWNER, OnColumnclickListOwner)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CDeleteOwner message handlers
  59. BOOL CDeleteOwner::OnInitDialog()
  60. {
  61. CBaseDialog::OnInitDialog();
  62. CString strOwner;
  63. strOwner.LoadString(IDS_OWNER);
  64. m_listOwner.InsertColumn(COLUMN_IP, strOwner, LVCFMT_LEFT, 100, 1);
  65. CString strID;
  66. strID.LoadString(IDS_HIGHESTID);
  67. m_listOwner.InsertColumn(COLUMN_VERSION, strID, LVCFMT_LEFT, 125, -1);
  68. CString strName;
  69. strName.LoadString(IDS_NAME);
  70. m_listOwner.InsertColumn(COLUMN_NAME, strName, LVCFMT_LEFT, 100, -1);
  71. m_listOwner.SetFullRowSel(TRUE);
  72. // grab the owner info array
  73. SPITFSNode spActRegNode;
  74. CActiveRegistrationsHandler * pActReg;
  75. spActRegNode = GetTFSNode();
  76. pActReg = GETHANDLER(CActiveRegistrationsHandler, spActRegNode);
  77. pActReg->GetOwnerInfo(m_ServerInfoArray);
  78. // set default radio selection
  79. m_radioDelete.SetCheck(TRUE);
  80. FillOwnerInfo();
  81. GetDlgItem(IDOK)->EnableWindow(FALSE);
  82. return TRUE; // return TRUE unless you set the focus to a control
  83. // EXCEPTION: OCX Property Pages should return FALSE
  84. }
  85. void CDeleteOwner::OnOK()
  86. {
  87. m_dwSelectedOwner = GetSelectedOwner();
  88. m_fDeleteRecords = m_radioDelete.GetState();
  89. // warn the user
  90. if (m_fDeleteRecords)
  91. {
  92. if (AfxMessageBox(IDS_WARN_DELETE_OWNER, MB_YESNO) == IDNO)
  93. {
  94. return;
  95. }
  96. }
  97. else
  98. {
  99. if (AfxMessageBox(IDS_WARN_TOMBSTONE, MB_YESNO) == IDNO)
  100. {
  101. return;
  102. }
  103. }
  104. CBaseDialog::OnOK();
  105. }
  106. void CDeleteOwner::OnItemchangedListOwner(NMHDR* pNMHDR, LRESULT* pResult)
  107. {
  108. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  109. BOOL fEnable = (GetSelectedOwner() != -1) ? TRUE : FALSE;
  110. GetDlgItem(IDOK)->EnableWindow(fEnable);
  111. *pResult = 0;
  112. }
  113. void CDeleteOwner::FillOwnerInfo()
  114. {
  115. for (int i = 0; i < m_ServerInfoArray.GetSize(); i++)
  116. {
  117. if (m_ServerInfoArray[i].m_liVersion.QuadPart == OWNER_DELETED)
  118. {
  119. // this owner has been deleted...
  120. continue;
  121. }
  122. CString strIPAdd;
  123. ::MakeIPAddress(m_ServerInfoArray[i].m_dwIp, strIPAdd);
  124. CString strVers = GetVersionInfo(m_ServerInfoArray[i].m_liVersion.LowPart,
  125. m_ServerInfoArray[i].m_liVersion.HighPart);
  126. int nItem = m_listOwner.InsertItem(i, strIPAdd, 0);
  127. m_listOwner.SetItemText(nItem, 1, m_ServerInfoArray[i].m_strName);
  128. m_listOwner.SetItemText(nItem, 2, strVers);
  129. m_listOwner.SetItemData(nItem, i);
  130. }
  131. Sort(COLUMN_IP);
  132. }
  133. void CDeleteOwner::Sort(int nCol)
  134. {
  135. if (m_nSortColumn == nCol)
  136. {
  137. // if the user is clicking the same column again, reverse the sort order
  138. m_aSortOrder[nCol] = m_aSortOrder[nCol] ? FALSE : TRUE;
  139. }
  140. else
  141. {
  142. m_nSortColumn = nCol;
  143. }
  144. m_listOwner.SortItems(DelOwnerCompareFunc, (LPARAM) this);
  145. }
  146. int CDeleteOwner::HandleSort(LPARAM lParam1, LPARAM lParam2)
  147. {
  148. int nCompare = 0;
  149. switch (m_nSortColumn)
  150. {
  151. case COLUMN_IP:
  152. {
  153. DWORD dwIp1 = m_ServerInfoArray.GetAt((int) lParam1).m_dwIp;
  154. DWORD dwIp2 = m_ServerInfoArray.GetAt((int) lParam2).m_dwIp;
  155. if (dwIp1 > dwIp2)
  156. nCompare = 1;
  157. else
  158. if (dwIp1 < dwIp2)
  159. nCompare = -1;
  160. }
  161. break;
  162. case COLUMN_NAME:
  163. {
  164. CString strName1, strName2;
  165. if (!m_ServerInfoArray.GetAt((int) lParam1).m_strName.IsEmpty())
  166. strName1 = m_ServerInfoArray.GetAt((int) lParam1).m_strName;
  167. if (!m_ServerInfoArray.GetAt((int) lParam2).m_strName.IsEmpty())
  168. strName2 = m_ServerInfoArray.GetAt((int) lParam2).m_strName;
  169. nCompare = strName1.CompareNoCase(strName2);
  170. }
  171. break;
  172. case COLUMN_VERSION:
  173. {
  174. LARGE_INTEGER li1, li2;
  175. li1.QuadPart = m_ServerInfoArray.GetAt((int) lParam1).m_liVersion.QuadPart;
  176. li2.QuadPart = m_ServerInfoArray.GetAt((int) lParam2).m_liVersion.QuadPart;
  177. if (li1.QuadPart > li2.QuadPart)
  178. nCompare = 1;
  179. else
  180. if (li1.QuadPart < li2.QuadPart)
  181. nCompare = -1;
  182. }
  183. break;
  184. }
  185. if (m_aSortOrder[m_nSortColumn] == FALSE)
  186. {
  187. // descending
  188. return -nCompare;
  189. }
  190. else
  191. {
  192. // ascending
  193. return nCompare;
  194. }
  195. }
  196. DWORD
  197. CDeleteOwner::GetSelectedOwner()
  198. {
  199. int nCount = m_listOwner.GetItemCount();
  200. int nSelected = -1;
  201. for (int i = 0; i < nCount; i++)
  202. {
  203. UINT uState = m_listOwner.GetItemState(i, LVIS_SELECTED);
  204. if (uState)
  205. {
  206. DWORD_PTR nData = m_listOwner.GetItemData(i);
  207. DWORD dwSelOwner = m_ServerInfoArray.GetAt((int) nData).m_dwIp;
  208. return dwSelOwner;
  209. }
  210. }
  211. return 0;
  212. }
  213. CString
  214. CDeleteOwner::GetVersionInfo(LONG lLowWord, LONG lHighWord)
  215. {
  216. CString strVersionCount;
  217. TCHAR sz[20];
  218. TCHAR *pch = sz;
  219. ::wsprintf(sz, _T("%08lX%08lX"), lHighWord, lLowWord);
  220. // Kill leading zero's
  221. while (*pch == '0')
  222. {
  223. ++pch;
  224. }
  225. // At least one digit...
  226. if (*pch == '\0')
  227. {
  228. --pch;
  229. }
  230. strVersionCount = pch;
  231. return strVersionCount;
  232. }
  233. void CDeleteOwner::OnColumnclickListOwner(NMHDR* pNMHDR, LRESULT* pResult)
  234. {
  235. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  236. // sort depending on what column was clicked;
  237. Sort(pNMListView->iSubItem);
  238. *pResult = 0;
  239. }