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.

415 lines
9.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1995 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. dhcpipar.cpp
  7. IP Array dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "dlgiparr.h"
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CDhcpIpArrayDlg dialog
  18. CDhcpIpArrayDlg::CDhcpIpArrayDlg(
  19. CDhcpOption * pdhcType,
  20. DHCP_OPTION_SCOPE_TYPE dhcScopeType,
  21. CWnd* pParent /*=NULL*/
  22. )
  23. : CBaseDialog(CDhcpIpArrayDlg::IDD, pParent),
  24. m_p_type( pdhcType ),
  25. m_option_type( dhcScopeType )
  26. {
  27. //{{AFX_DATA_INIT(CDhcpIpArrayDlg)
  28. //}}AFX_DATA_INIT
  29. ASSERT( m_p_type != NULL ) ;
  30. }
  31. void
  32. CDhcpIpArrayDlg::DoDataExchange(
  33. CDataExchange* pDX
  34. )
  35. {
  36. CBaseDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CDhcpIpArrayDlg)
  38. DDX_Control(pDX, IDC_BUTN_RESOLVE, m_butn_resolve);
  39. DDX_Control(pDX, IDC_STATIC_OPTION_NAME, m_static_option_name);
  40. DDX_Control(pDX, IDC_STATIC_APPLICATION, m_static_application);
  41. DDX_Control(pDX, IDC_LIST_IP_ADDRS, m_list_ip_addrs);
  42. DDX_Control(pDX, IDC_EDIT_SERVER_NAME, m_edit_server);
  43. DDX_Control(pDX, IDC_BUTN_ADD, m_butn_add);
  44. DDX_Control(pDX, IDC_BUTN_DELETE, m_butn_delete);
  45. DDX_Control(pDX, IDC_BUTN_UP, m_button_Up);
  46. DDX_Control(pDX, IDC_BUTN_DOWN, m_button_Down);
  47. //}}AFX_DATA_MAP
  48. // The IP address custom control
  49. DDX_Control(pDX, IDC_IPADDR_NEW, m_ipa_new );
  50. }
  51. BEGIN_MESSAGE_MAP(CDhcpIpArrayDlg, CBaseDialog)
  52. //{{AFX_MSG_MAP(CDhcpIpArrayDlg)
  53. ON_BN_CLICKED(IDC_BUTN_ADD, OnClickedButnAdd)
  54. ON_BN_CLICKED(IDC_BUTN_DELETE, OnClickedButnDelete)
  55. ON_BN_CLICKED(IDC_BUTN_DOWN, OnClickedButnDown)
  56. ON_BN_CLICKED(IDC_BUTN_UP, OnClickedButnUp)
  57. ON_BN_CLICKED(IDC_HELP, OnClickedHelp)
  58. ON_LBN_SELCHANGE(IDC_LIST_IP_ADDRS, OnSelchangeListIpAddrs)
  59. ON_EN_CHANGE(IDC_EDIT_SERVER_NAME, OnChangeEditServerName)
  60. ON_BN_CLICKED(IDC_BUTN_RESOLVE, OnClickedButnResolve)
  61. ON_COMMAND(EN_SETFOCUS, OnSetFocusEditIpAddr)
  62. //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CDhcpIpArrayDlg message handlers
  66. BOOL
  67. CDhcpIpArrayDlg::OnInitDialog()
  68. {
  69. CBaseDialog::OnInitDialog();
  70. DWORD err = 0 ;
  71. int cStrId = m_option_type == DhcpDefaultOptions
  72. ? IDS_INFO_TITLE_DEFAULT_OPTIONS
  73. : (m_option_type == DhcpGlobalOptions
  74. ? IDS_INFO_TITLE_GLOBAL_OPTIONS
  75. : IDS_INFO_TITLE_SCOPE_OPTIONS ) ;
  76. CString str ;
  77. CATCH_MEM_EXCEPTION
  78. {
  79. m_static_option_name.SetWindowText( m_p_type->QueryName() ) ;
  80. str.LoadString( cStrId ) ;
  81. m_static_application.SetWindowText( str ) ;
  82. //
  83. // Fill the internal list from the current value.
  84. //
  85. INT cMax = m_p_type->QueryValue().QueryUpperBound() ;
  86. for (int i = 0; i < cMax; i++)
  87. {
  88. if (m_p_type->QueryValue().QueryIpAddr(i))
  89. {
  90. m_dw_array.Add((DWORD) m_p_type->QueryValue().QueryIpAddr( i ) ) ;
  91. }
  92. }
  93. //
  94. // Fill the list box without toggling redraw
  95. //
  96. Fill( 0, FALSE ) ;
  97. //
  98. // Set focus on the new IP address control.
  99. //
  100. m_ipa_new.SetFocus() ;
  101. m_ipa_new.SetModify( FALSE ) ;
  102. m_edit_server.SetModify( FALSE ) ;
  103. //
  104. // Set proper button states.
  105. //
  106. HandleActivation() ;
  107. }
  108. END_MEM_EXCEPTION( err ) ;
  109. if ( err )
  110. {
  111. ::DhcpMessageBox( err ) ;
  112. EndDialog(-1);
  113. }
  114. return FALSE ;
  115. }
  116. void
  117. CDhcpIpArrayDlg :: Fill (
  118. INT cFocus,
  119. BOOL bToggleRedraw
  120. )
  121. {
  122. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  123. CString strIp;
  124. if ( bToggleRedraw )
  125. {
  126. m_list_ip_addrs.SetRedraw( FALSE ) ;
  127. }
  128. m_list_ip_addrs.ResetContent() ;
  129. if (m_dw_array.GetSize())
  130. {
  131. for ( INT i = 0 ; i < m_dw_array.GetSize() ; i++ )
  132. {
  133. ASSERT(m_dw_array.GetAt(i));
  134. ::UtilCvtIpAddrToWstr( m_dw_array.GetAt(i), &strIp ) ;
  135. m_list_ip_addrs.AddString( strIp ) ;
  136. }
  137. }
  138. else
  139. {
  140. // Set the string to "<None>" iff the list is empty
  141. strIp.LoadString(IDS_INFO_FORMAT_IP_NONE);
  142. m_list_ip_addrs.AddString( strIp ) ;
  143. }
  144. if ( cFocus >= 0 )
  145. {
  146. m_list_ip_addrs.SetCurSel( cFocus ) ;
  147. }
  148. if ( bToggleRedraw )
  149. {
  150. m_list_ip_addrs.SetRedraw( TRUE ) ;
  151. m_list_ip_addrs.Invalidate() ;
  152. }
  153. }
  154. void
  155. CDhcpIpArrayDlg :: HandleActivation ()
  156. {
  157. INT cItems = m_list_ip_addrs.GetCount() ;
  158. INT cFocus = m_list_ip_addrs.GetCurSel() ;
  159. // REVIEW: Need to figure out how to handle the IP address control properly.
  160. // DWORD dwIpAddr ;
  161. // m_ipa_new.GetAddress( & dwIpAddr ) ;
  162. // m_butn_add.EnableWindow( /* dwIpAddr != 0 */) ;
  163. m_button_Up.EnableWindow(cFocus > 0) ;
  164. m_button_Down.EnableWindow(cFocus < cItems - 1) ;
  165. m_butn_delete.EnableWindow(m_dw_array.GetSize()>0) ;
  166. m_butn_resolve.EnableWindow( m_edit_server.GetModify() ) ;
  167. }
  168. void
  169. CDhcpIpArrayDlg::OnOK()
  170. {
  171. INT cItems = (INT)m_dw_array.GetSize() ;
  172. DWORD err = 0 ;
  173. CATCH_MEM_EXCEPTION
  174. {
  175. CDhcpOptionValue * pdhcValue = & m_p_type->QueryValue() ;
  176. pdhcValue->SetUpperBound( cItems ) ;
  177. for ( INT i = 0 ; i < cItems ; i++ )
  178. {
  179. pdhcValue->SetIpAddr( m_dw_array.GetAt(i), i ) ;
  180. }
  181. pdhcValue->SetIpAddr(0, i); // 0.0.0.0 IP Terminator
  182. m_p_type->SetDirty() ;
  183. }
  184. END_MEM_EXCEPTION(err)
  185. if ( err )
  186. {
  187. ::DhcpMessageBox( err ) ;
  188. OnCancel() ;
  189. }
  190. else
  191. {
  192. CBaseDialog::OnOK();
  193. }
  194. }
  195. void
  196. CDhcpIpArrayDlg::OnCancel()
  197. {
  198. CBaseDialog::OnCancel();
  199. }
  200. void
  201. CDhcpIpArrayDlg::OnClickedButnAdd()
  202. {
  203. INT cFocus = m_list_ip_addrs.GetCurSel() ;
  204. DWORD dhipa ;
  205. m_ipa_new.GetAddress( & dhipa ) ;
  206. // Empty IP address
  207. if (!dhipa)
  208. return;
  209. DWORD err = 0 ;
  210. CATCH_MEM_EXCEPTION
  211. {
  212. if ( cFocus < 0 )
  213. {
  214. cFocus = 0 ;
  215. }
  216. m_dw_array.InsertAt( cFocus, dhipa ) ;
  217. }
  218. END_MEM_EXCEPTION(err)
  219. if ( err )
  220. {
  221. ::DhcpMessageBox( err ) ;
  222. }
  223. //
  224. // Refill listbox, update controls.
  225. //
  226. m_ipa_new.ClearAddress();
  227. m_ipa_new.SetFocus();
  228. Fill( cFocus ) ;
  229. HandleActivation() ;
  230. }
  231. void
  232. CDhcpIpArrayDlg::OnClickedButnDelete()
  233. {
  234. INT cFocus = m_list_ip_addrs.GetCurSel() ;
  235. if ( cFocus < 0)
  236. {
  237. return ;
  238. }
  239. DHCP_IP_ADDRESS dhipa = m_dw_array.GetAt( cFocus ) ;
  240. if (!dhipa)
  241. return;
  242. m_dw_array.RemoveAt( cFocus ) ;
  243. m_ipa_new.SetAddress( dhipa ) ;
  244. m_ipa_new.SetFocus();
  245. Fill( cFocus ) ;
  246. HandleActivation() ;
  247. }
  248. void
  249. CDhcpIpArrayDlg::OnClickedButnDown()
  250. {
  251. INT cFocus = m_list_ip_addrs.GetCurSel() ;
  252. INT cItems = m_list_ip_addrs.GetCount() ;
  253. if ( cFocus < 0 || cFocus + 1 >= cItems )
  254. {
  255. return ;
  256. }
  257. DHCP_IP_ADDRESS dhipa ;
  258. DWORD err = 0 ;
  259. CATCH_MEM_EXCEPTION
  260. {
  261. dhipa = m_dw_array.GetAt( cFocus ) ;
  262. m_dw_array.RemoveAt( cFocus ) ;
  263. m_dw_array.InsertAt( cFocus + 1, dhipa ) ;
  264. }
  265. END_MEM_EXCEPTION(err)
  266. if ( err )
  267. {
  268. ::DhcpMessageBox( err ) ;
  269. }
  270. Fill( cFocus + 1 ) ;
  271. HandleActivation() ;
  272. }
  273. void
  274. CDhcpIpArrayDlg::OnClickedButnUp()
  275. {
  276. INT cFocus = m_list_ip_addrs.GetCurSel() ;
  277. INT cItems = m_list_ip_addrs.GetCount() ;
  278. if ( cFocus <= 0 )
  279. {
  280. return ;
  281. }
  282. DHCP_IP_ADDRESS dhipa ;
  283. DWORD err = 0 ;
  284. CATCH_MEM_EXCEPTION
  285. {
  286. dhipa = m_dw_array.GetAt( cFocus ) ;
  287. m_dw_array.RemoveAt( cFocus ) ;
  288. m_dw_array.InsertAt( cFocus - 1, dhipa ) ;
  289. }
  290. END_MEM_EXCEPTION(err)
  291. if ( err )
  292. {
  293. ::DhcpMessageBox( err ) ;
  294. }
  295. Fill( cFocus - 1 ) ;
  296. HandleActivation() ;
  297. }
  298. void
  299. CDhcpIpArrayDlg::OnClickedHelp()
  300. {
  301. }
  302. void
  303. CDhcpIpArrayDlg::OnSetFocusEditIpAddr()
  304. {
  305. // REVIEW t-danmo
  306. // Add code to change the default push button
  307. }
  308. void
  309. CDhcpIpArrayDlg::OnSelchangeListIpAddrs()
  310. {
  311. HandleActivation() ;
  312. }
  313. void
  314. CDhcpIpArrayDlg::OnChangeEditServerName()
  315. {
  316. HandleActivation() ;
  317. }
  318. void
  319. CDhcpIpArrayDlg::OnClickedButnResolve()
  320. {
  321. CString strHost ;
  322. DHCP_IP_ADDRESS dhipa ;
  323. DWORD err = 0 ;
  324. CATCH_MEM_EXCEPTION
  325. {
  326. m_edit_server.GetWindowText( strHost ) ;
  327. }
  328. END_MEM_EXCEPTION( err ) ;
  329. if ( err == 0 )
  330. {
  331. if ( strHost.GetLength() == 0 )
  332. {
  333. err = IDS_ERR_BAD_HOST_NAME ;
  334. }
  335. else
  336. {
  337. err = ::UtilGetHostAddress( strHost, & dhipa ) ;
  338. }
  339. if ( err == 0 )
  340. {
  341. m_ipa_new.SetAddress( dhipa ) ;
  342. }
  343. }
  344. if ( err )
  345. {
  346. ::DhcpMessageBox( err ) ;
  347. }
  348. }