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.

307 lines
7.6 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. CThemeContextActivator themeActivator;
  88. m_dwSelectedOwner = GetSelectedOwner();
  89. m_fDeleteRecords = m_radioDelete.GetState();
  90. // warn the user
  91. if (m_fDeleteRecords)
  92. {
  93. if (AfxMessageBox(IDS_WARN_DELETE_OWNER, MB_YESNO) == IDNO)
  94. {
  95. return;
  96. }
  97. }
  98. else
  99. {
  100. if (AfxMessageBox(IDS_WARN_TOMBSTONE, MB_YESNO) == IDNO)
  101. {
  102. return;
  103. }
  104. }
  105. CBaseDialog::OnOK();
  106. }
  107. void CDeleteOwner::OnItemchangedListOwner(NMHDR* pNMHDR, LRESULT* pResult)
  108. {
  109. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  110. BOOL fEnable = (GetSelectedOwner() != -1) ? TRUE : FALSE;
  111. GetDlgItem(IDOK)->EnableWindow(fEnable);
  112. *pResult = 0;
  113. }
  114. void CDeleteOwner::FillOwnerInfo()
  115. {
  116. for (int i = 0; i < m_ServerInfoArray.GetSize(); i++)
  117. {
  118. if (m_ServerInfoArray[i].m_liVersion.QuadPart == OWNER_DELETED)
  119. {
  120. // this owner has been deleted...
  121. continue;
  122. }
  123. CString strIPAdd;
  124. ::MakeIPAddress(m_ServerInfoArray[i].m_dwIp, strIPAdd);
  125. CString strVers = GetVersionInfo(m_ServerInfoArray[i].m_liVersion.LowPart,
  126. m_ServerInfoArray[i].m_liVersion.HighPart);
  127. int nItem = m_listOwner.InsertItem(i, strIPAdd, 0);
  128. m_listOwner.SetItemText(nItem, 1, m_ServerInfoArray[i].m_strName);
  129. m_listOwner.SetItemText(nItem, 2, strVers);
  130. m_listOwner.SetItemData(nItem, i);
  131. }
  132. Sort(COLUMN_IP);
  133. }
  134. void CDeleteOwner::Sort(int nCol)
  135. {
  136. if (m_nSortColumn == nCol)
  137. {
  138. // if the user is clicking the same column again, reverse the sort order
  139. m_aSortOrder[nCol] = m_aSortOrder[nCol] ? FALSE : TRUE;
  140. }
  141. else
  142. {
  143. m_nSortColumn = nCol;
  144. }
  145. m_listOwner.SortItems(DelOwnerCompareFunc, (LPARAM) this);
  146. }
  147. int CDeleteOwner::HandleSort(LPARAM lParam1, LPARAM lParam2)
  148. {
  149. int nCompare = 0;
  150. switch (m_nSortColumn)
  151. {
  152. case COLUMN_IP:
  153. {
  154. DWORD dwIp1 = m_ServerInfoArray.GetAt((int) lParam1).m_dwIp;
  155. DWORD dwIp2 = m_ServerInfoArray.GetAt((int) lParam2).m_dwIp;
  156. if (dwIp1 > dwIp2)
  157. nCompare = 1;
  158. else
  159. if (dwIp1 < dwIp2)
  160. nCompare = -1;
  161. }
  162. break;
  163. case COLUMN_NAME:
  164. {
  165. CString strName1, strName2;
  166. if (!m_ServerInfoArray.GetAt((int) lParam1).m_strName.IsEmpty())
  167. strName1 = m_ServerInfoArray.GetAt((int) lParam1).m_strName;
  168. if (!m_ServerInfoArray.GetAt((int) lParam2).m_strName.IsEmpty())
  169. strName2 = m_ServerInfoArray.GetAt((int) lParam2).m_strName;
  170. nCompare = strName1.CompareNoCase(strName2);
  171. }
  172. break;
  173. case COLUMN_VERSION:
  174. {
  175. LARGE_INTEGER li1, li2;
  176. li1.QuadPart = m_ServerInfoArray.GetAt((int) lParam1).m_liVersion.QuadPart;
  177. li2.QuadPart = m_ServerInfoArray.GetAt((int) lParam2).m_liVersion.QuadPart;
  178. if (li1.QuadPart > li2.QuadPart)
  179. nCompare = 1;
  180. else
  181. if (li1.QuadPart < li2.QuadPart)
  182. nCompare = -1;
  183. }
  184. break;
  185. }
  186. if (m_aSortOrder[m_nSortColumn] == FALSE)
  187. {
  188. // descending
  189. return -nCompare;
  190. }
  191. else
  192. {
  193. // ascending
  194. return nCompare;
  195. }
  196. }
  197. DWORD
  198. CDeleteOwner::GetSelectedOwner()
  199. {
  200. int nCount = m_listOwner.GetItemCount();
  201. int nSelected = -1;
  202. for (int i = 0; i < nCount; i++)
  203. {
  204. UINT uState = m_listOwner.GetItemState(i, LVIS_SELECTED);
  205. if (uState)
  206. {
  207. DWORD_PTR nData = m_listOwner.GetItemData(i);
  208. DWORD dwSelOwner = m_ServerInfoArray.GetAt((int) nData).m_dwIp;
  209. return dwSelOwner;
  210. }
  211. }
  212. return 0;
  213. }
  214. CString
  215. CDeleteOwner::GetVersionInfo(LONG lLowWord, LONG lHighWord)
  216. {
  217. CString strVersionCount;
  218. TCHAR sz[20];
  219. TCHAR *pch = sz;
  220. ::wsprintf(sz, _T("%08lX%08lX"), lHighWord, lLowWord);
  221. // Kill leading zero's
  222. while (*pch == '0')
  223. {
  224. ++pch;
  225. }
  226. // At least one digit...
  227. if (*pch == '\0')
  228. {
  229. --pch;
  230. }
  231. strVersionCount = pch;
  232. return strVersionCount;
  233. }
  234. void CDeleteOwner::OnColumnclickListOwner(NMHDR* pNMHDR, LRESULT* pResult)
  235. {
  236. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  237. // sort depending on what column was clicked;
  238. Sort(pNMListView->iSubItem);
  239. *pResult = 0;
  240. }