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.

189 lines
4.8 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1999 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. addtoss.cpp
  7. The add scope to superscope dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "AddToSS.h"
  12. #include "server.h"
  13. #include "scope.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CAddScopeToSuperscope dialog
  21. CAddScopeToSuperscope::CAddScopeToSuperscope
  22. (
  23. ITFSNode * pScopeNode,
  24. LPCTSTR pszTitle,
  25. CWnd* pParent /*=NULL*/
  26. ) : CBaseDialog(CAddScopeToSuperscope::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CAddScopeToSuperscope)
  29. // NOTE: the ClassWizard will add member initialization here
  30. //}}AFX_DATA_INIT
  31. m_strTitle = pszTitle;
  32. m_spScopeNode.Set(pScopeNode);
  33. }
  34. void CAddScopeToSuperscope::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CBaseDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CAddScopeToSuperscope)
  38. DDX_Control(pDX, IDOK, m_buttonOk);
  39. DDX_Control(pDX, IDC_LIST_SUPERSCOPES, m_listSuperscopes);
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CAddScopeToSuperscope, CBaseDialog)
  43. //{{AFX_MSG_MAP(CAddScopeToSuperscope)
  44. ON_LBN_SELCHANGE(IDC_LIST_SUPERSCOPES, OnSelchangeListSuperscopes)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CAddScopeToSuperscope message handlers
  49. BOOL CAddScopeToSuperscope::OnInitDialog()
  50. {
  51. CBaseDialog::OnInitDialog();
  52. SPITFSNode spServerNode;
  53. SPITFSNode spCurrentNode;
  54. SPITFSNodeEnum spNodeEnum;
  55. ULONG nNumReturned = 0;
  56. m_spScopeNode->GetParent(&spServerNode);
  57. spServerNode->GetEnum(&spNodeEnum);
  58. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  59. while (nNumReturned)
  60. {
  61. if (spCurrentNode->GetData(TFS_DATA_TYPE) == DHCPSNAP_SUPERSCOPE)
  62. {
  63. // found a superscope
  64. //
  65. CString strName;
  66. CDhcpSuperscope * pSuperscope = GETHANDLER(CDhcpSuperscope, spCurrentNode);
  67. strName = pSuperscope->GetName();
  68. m_listSuperscopes.AddString(strName);
  69. }
  70. spCurrentNode.Release();
  71. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  72. }
  73. SetButtons();
  74. if (!m_strTitle.IsEmpty())
  75. SetWindowText(m_strTitle);
  76. return TRUE; // return TRUE unless you set the focus to a control
  77. // EXCEPTION: OCX Property Pages should return FALSE
  78. }
  79. void CAddScopeToSuperscope::OnOK()
  80. {
  81. DWORD err;
  82. CString strSuperscope;
  83. // Get the currently selected node
  84. int nCurSel = m_listSuperscopes.GetCurSel();
  85. Assert(nCurSel != LB_ERR);
  86. m_listSuperscopes.GetText(nCurSel, strSuperscope);
  87. if (strSuperscope.IsEmpty())
  88. Assert(FALSE);
  89. // now try to set this scope as part of the superscope
  90. CDhcpScope * pScope = GETHANDLER(CDhcpScope, m_spScopeNode);
  91. BEGIN_WAIT_CURSOR;
  92. err = pScope->SetSuperscope(strSuperscope, FALSE);
  93. END_WAIT_CURSOR;
  94. if (err != ERROR_SUCCESS)
  95. {
  96. ::DhcpMessageBox(err);
  97. return;
  98. }
  99. // that worked, now move the UI stuff around.
  100. SPITFSNode spServerNode;
  101. SPITFSNode spCurrentNode;
  102. SPITFSNodeEnum spNodeEnum;
  103. ULONG nNumReturned = 0;
  104. m_spScopeNode->GetParent(&spServerNode);
  105. spServerNode->GetEnum(&spNodeEnum);
  106. // remove the scope from the UI
  107. spServerNode->RemoveChild(m_spScopeNode);
  108. pScope->SetInSuperscope(FALSE);
  109. // find the superscope we want to add this scope to and refresh it so that
  110. // the scope shows up in that node
  111. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  112. while (nNumReturned)
  113. {
  114. if (spCurrentNode->GetData(TFS_DATA_TYPE) == DHCPSNAP_SUPERSCOPE)
  115. {
  116. // found a superscope
  117. CString strName;
  118. CDhcpSuperscope * pSuperscope = GETHANDLER(CDhcpSuperscope, spCurrentNode);
  119. strName = pSuperscope->GetName();
  120. // is this the one?
  121. if (strName.Compare(strSuperscope) == 0)
  122. {
  123. // this is the one we are adding to. Force a refresh.
  124. pSuperscope->OnRefresh(spCurrentNode, NULL, 0, 0, 0);
  125. break;
  126. }
  127. }
  128. // go to the next one
  129. spCurrentNode.Release();
  130. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  131. }
  132. CBaseDialog::OnOK();
  133. }
  134. void CAddScopeToSuperscope::OnSelchangeListSuperscopes()
  135. {
  136. SetButtons();
  137. }
  138. void CAddScopeToSuperscope::SetButtons()
  139. {
  140. if (m_listSuperscopes.GetCurSel() != LB_ERR)
  141. {
  142. m_buttonOk.EnableWindow(TRUE);
  143. }
  144. else
  145. {
  146. m_buttonOk.EnableWindow(FALSE);
  147. }
  148. }