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.

224 lines
6.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: servbind.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // servbind.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "servbind.h"
  14. #include "server.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. #define BINDINGS_COLUMNS 2
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CServerBindings dialog
  23. CServerBindings::CServerBindings(CWnd* pParent /*=NULL*/)
  24. : CBaseDialog(CServerBindings::IDD, pParent)
  25. {
  26. //{{AFX_DATA_INIT(CServerBindings)
  27. // NOTE: the ClassWizard will add member initialization here
  28. //}}AFX_DATA_INIT
  29. }
  30. CServerBindings::CServerBindings(CDhcpServer *pServer, CWnd *pParent)
  31. : CBaseDialog(CServerBindings::IDD, pParent)
  32. {
  33. m_Server = pServer;
  34. m_BindingsInfo = NULL;
  35. }
  36. CServerBindings::~CServerBindings()
  37. {
  38. ::DhcpRpcFreeMemory(m_BindingsInfo);
  39. m_BindingsInfo = NULL;
  40. //
  41. // if needed destory the list ctrl also
  42. //
  43. if( m_listctrlBindingsList.GetSafeHwnd() != NULL ) {
  44. m_listctrlBindingsList.SetImageList(NULL, LVSIL_STATE);
  45. m_listctrlBindingsList.DeleteAllItems();
  46. }
  47. m_listctrlBindingsList.DestroyWindow();
  48. }
  49. void CServerBindings::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CBaseDialog::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(CServerBindings)
  53. DDX_Control(pDX, IDC_LIST_BINDINGS, m_listctrlBindingsList);
  54. //}}AFX_DATA_MAP
  55. }
  56. BEGIN_MESSAGE_MAP(CServerBindings, CBaseDialog)
  57. //{{AFX_MSG_MAP(CServerBindings)
  58. ON_BN_CLICKED(IDCANCEL, OnBindingsCancel)
  59. ON_BN_CLICKED(IDOK, OnBindingsOK)
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CServerBindings message handlers
  64. BOOL CServerBindings::OnInitDialog()
  65. {
  66. ULONG dwError;
  67. CBaseDialog::OnInitDialog();
  68. // initialize the list ctrl
  69. InitListCtrl();
  70. BEGIN_WAIT_CURSOR;
  71. // get the state from the server..
  72. dwError = m_Server->GetBindings(m_BindingsInfo);
  73. END_WAIT_CURSOR;
  74. if( 0 != dwError) {
  75. ::DhcpMessageBox(dwError);
  76. m_BindingsInfo = NULL;
  77. // can't do anything if we don't have what we want.
  78. // so cancel the window itself.
  79. OnCancel();
  80. } else {
  81. int col_width = 0, col2_width = 0, base_width;
  82. // basic fudge factor
  83. base_width = 15 + m_listctrlBindingsList.GetStringWidth(TEXT("++"));
  84. // now set each item..
  85. for( ULONG i = 0; i < m_BindingsInfo->NumElements ; i ++ ) {
  86. LPWSTR IpString = NULL;
  87. if( 0 != m_BindingsInfo->Elements[i].AdapterPrimaryAddress ) {
  88. IpString = ::UtilDupIpAddrToWstr(
  89. htonl(m_BindingsInfo->Elements[i].AdapterPrimaryAddress)
  90. );
  91. }
  92. int width = m_listctrlBindingsList.GetStringWidth(IpString);
  93. if( col_width < width) col_width = width;
  94. if( m_BindingsInfo->Elements[i].IfDescription != NULL ) {
  95. width = m_listctrlBindingsList.GetStringWidth(
  96. m_BindingsInfo->Elements[i].IfDescription
  97. );
  98. if( col2_width < width) col2_width = width;
  99. }
  100. int nIndex = m_listctrlBindingsList.AddItem(
  101. IpString, m_BindingsInfo->Elements[i].IfDescription,
  102. LISTVIEWEX_NOT_CHECKED
  103. );
  104. if( m_BindingsInfo->Elements[i].fBoundToDHCPServer ) {
  105. m_listctrlBindingsList.CheckItem(nIndex);
  106. }
  107. if( IpString ) delete IpString;
  108. }
  109. m_listctrlBindingsList.SetColumnWidth(0, col_width + base_width);
  110. m_listctrlBindingsList.SetColumnWidth(1, col2_width + base_width/2);
  111. // if there are any elements, set focus on this window.
  112. if( m_BindingsInfo->NumElements ) {
  113. m_listctrlBindingsList.SelectItem(0);
  114. m_listctrlBindingsList.SetFocus();
  115. //
  116. // return false to indicate that we have set focus.
  117. //
  118. return FALSE;
  119. }
  120. }
  121. return TRUE; // return TRUE unless you set the focus to a control
  122. // EXCEPTION: OCX Property Pages should return FALSE
  123. }
  124. void CServerBindings::InitListCtrl()
  125. {
  126. // set image lists
  127. m_StateImageList.Create(IDB_LIST_STATE, 16, 1, RGB(255, 0, 0));
  128. m_listctrlBindingsList.SetImageList(NULL, LVSIL_NORMAL);
  129. m_listctrlBindingsList.SetImageList(NULL, LVSIL_SMALL);
  130. m_listctrlBindingsList.SetImageList(&m_StateImageList, LVSIL_STATE);
  131. // insert a column so we can see the items
  132. LV_COLUMN lvc;
  133. CString strColumnHeader;
  134. for (int i = 0; i < BINDINGS_COLUMNS; i++)
  135. {
  136. lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT;;
  137. lvc.iSubItem = i;
  138. lvc.fmt = LVCFMT_LEFT;
  139. lvc.pszText = NULL;
  140. m_listctrlBindingsList.InsertColumn(i, &lvc);
  141. }
  142. m_listctrlBindingsList.SetFullRowSel(TRUE);
  143. }
  144. void CServerBindings::OnBindingsCancel()
  145. {
  146. CBaseDialog::OnCancel();
  147. }
  148. void CServerBindings::OnBindingsOK()
  149. {
  150. DWORD dwError;
  151. if( NULL != m_BindingsInfo ) {
  152. //
  153. // Save that onto the dhcp server
  154. //
  155. UpdateBindingInfo();
  156. dwError = m_Server->SetBindings(m_BindingsInfo);
  157. if( NO_ERROR != dwError ) {
  158. ::DhcpMessageBox(dwError);
  159. } else {
  160. CBaseDialog::OnOK();
  161. }
  162. } else {
  163. CBaseDialog::OnOK();
  164. }
  165. }
  166. void CServerBindings::UpdateBindingInfo()
  167. {
  168. for( int i = 0; i < m_listctrlBindingsList.GetItemCount() ; i ++ ) {
  169. BOOL fBound;
  170. if( m_listctrlBindingsList.GetCheck(i) ) {
  171. m_BindingsInfo->Elements[i].fBoundToDHCPServer = TRUE;
  172. } else {
  173. m_BindingsInfo->Elements[i].fBoundToDHCPServer = FALSE;
  174. }
  175. }
  176. }