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.

891 lines
23 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1995 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. dlgdval.cpp
  7. Default value dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "dlgdval.h"
  12. #include "dlgdefop.h"
  13. #include "dlgiparr.h"
  14. #include "dlgbined.h"
  15. #include "strarrdlg.h"
  16. #include "routearrayeditor.h"
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CDhcpDefValDlg dialog
  23. CDhcpDefValDlg::CDhcpDefValDlg
  24. (
  25. ITFSNode * pServerNode,
  26. COptionList * polTypes,
  27. CWnd* pParent /*=NULL*/
  28. )
  29. : CBaseDialog(CDhcpDefValDlg::IDD, pParent),
  30. m_pol_values( polTypes ),
  31. m_p_edit_type( NULL ),
  32. m_b_dirty( FALSE )
  33. {
  34. //{{AFX_DATA_INIT(CDhcpDefValDlg)
  35. //}}AFX_DATA_INIT
  36. m_combo_class_iSel = LB_ERR;
  37. m_combo_name_iSel = LB_ERR;
  38. m_spNode.Set(pServerNode);
  39. ASSERT( m_pol_values != NULL );
  40. }
  41. CDhcpDefValDlg::~CDhcpDefValDlg ()
  42. {
  43. }
  44. void
  45. CDhcpDefValDlg::DoDataExchange
  46. (
  47. CDataExchange* pDX
  48. )
  49. {
  50. CBaseDialog::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CDhcpDefValDlg)
  52. DDX_Control(pDX, IDC_EDIT_COMMENT, m_edit_comment);
  53. DDX_Control(pDX, IDC_BUTN_VALUE, m_butn_edit_value);
  54. DDX_Control(pDX, IDC_STATIC_VALUE_DESC, m_static_value_desc);
  55. DDX_Control(pDX, IDC_EDIT_VALUE_STRING, m_edit_string);
  56. DDX_Control(pDX, IDC_EDIT_VALUE_NUM, m_edit_num);
  57. DDX_Control(pDX, IDC_EDIT_VALUE_ARRAY, m_edit_array);
  58. DDX_Control(pDX, IDC_COMBO_OPTION_NAME, m_combo_name);
  59. DDX_Control(pDX, IDC_COMBO_OPTION_CLASS, m_combo_class);
  60. DDX_Control(pDX, IDC_BUTN_OPTION_PRO, m_butn_prop);
  61. DDX_Control(pDX, IDC_BUTN_NEW_OPTION, m_butn_new);
  62. DDX_Control(pDX, IDC_BUTN_DELETE, m_butn_delete);
  63. //}}AFX_DATA_MAP
  64. DDX_Control(pDX, IDC_IPADDR_VALUE, m_ipa_value);
  65. }
  66. BEGIN_MESSAGE_MAP(CDhcpDefValDlg, CBaseDialog)
  67. //{{AFX_MSG_MAP(CDhcpDefValDlg)
  68. ON_BN_CLICKED(IDC_BUTN_DELETE, OnClickedButnDelete)
  69. ON_BN_CLICKED(IDC_BUTN_NEW_OPTION, OnClickedButnNewOption)
  70. ON_BN_CLICKED(IDC_BUTN_OPTION_PRO, OnClickedButnOptionPro)
  71. ON_CBN_SELCHANGE(IDC_COMBO_OPTION_CLASS, OnSelendokComboOptionClass)
  72. ON_CBN_SETFOCUS(IDC_COMBO_OPTION_CLASS, OnSetfocusComboOptionClass)
  73. ON_CBN_SETFOCUS(IDC_COMBO_OPTION_NAME, OnSetfocusComboOptionName)
  74. ON_CBN_SELCHANGE(IDC_COMBO_OPTION_NAME, OnSelchangeComboOptionName)
  75. ON_BN_CLICKED(IDC_BUTN_VALUE, OnClickedButnValue)
  76. ON_BN_CLICKED(IDC_HELP, OnClickedHelp)
  77. //}}AFX_MSG_MAP
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CDhcpDefValDlg message handlers
  81. void
  82. CDhcpDefValDlg::OnClickedButnDelete()
  83. {
  84. DWORD err = 0 ;
  85. int cSel = m_combo_name.GetCurSel() ;
  86. BOOL fPresentInOldValues;
  87. //
  88. // Make sure there's a new data type.
  89. //
  90. if ( m_p_edit_type == NULL )
  91. {
  92. return ;
  93. }
  94. ASSERT( m_pol_values != NULL ) ;
  95. //
  96. // Remove the focused type.
  97. //
  98. fPresentInOldValues = ( NULL != m_pol_values->Find( m_p_edit_type ));
  99. m_pol_values->Remove( m_p_edit_type ) ;
  100. m_ol_values_new.Remove( m_p_edit_type ) ;
  101. if( fPresentInOldValues )
  102. {
  103. CATCH_MEM_EXCEPTION
  104. {
  105. m_ol_values_defunct.AddTail( m_p_edit_type ) ;
  106. m_b_dirty = TRUE ;
  107. }
  108. END_MEM_EXCEPTION(err);
  109. }
  110. if ( err )
  111. {
  112. ::DhcpMessageBox( err ) ;
  113. }
  114. else
  115. {
  116. if ( m_pol_values->GetCount() == 0 )
  117. {
  118. cSel = -1 ;
  119. }
  120. else
  121. {
  122. cSel = cSel > 0 ? cSel - 1 : 0 ;
  123. }
  124. Fill() ;
  125. m_combo_name.SetCurSel( cSel ) ;
  126. HandleActivation() ;
  127. }
  128. }
  129. void
  130. CDhcpDefValDlg::GetCurrentVendor(CString & strVendor)
  131. {
  132. if (m_combo_class_iSel == 0)
  133. strVendor.Empty();
  134. else
  135. m_combo_class.GetLBText(m_combo_class_iSel, strVendor);
  136. }
  137. void
  138. CDhcpDefValDlg::OnClickedButnNewOption()
  139. {
  140. CString strVendor;
  141. GetCurrentVendor(strVendor);
  142. CDhcpDefOptionDlg dlgDefOpt( m_pol_values, NULL, strVendor, this);
  143. if ( dlgDefOpt.DoModal() == IDOK )
  144. {
  145. CDhcpOption * pNewOption = dlgDefOpt.RetrieveParamType();
  146. LONG err = UpdateList( pNewOption, TRUE ) ;
  147. if ( err )
  148. {
  149. ::DhcpMessageBox( err ) ;
  150. }
  151. else
  152. {
  153. // select the new item
  154. CString strName;
  155. pNewOption->QueryDisplayName(strName);
  156. int nIndex = m_combo_name.FindString(-1, strName);
  157. if (nIndex == CB_ERR)
  158. {
  159. m_combo_name.SetCurSel(0);
  160. }
  161. else
  162. {
  163. m_combo_name.SetCurSel(nIndex);
  164. }
  165. m_combo_name_iSel = m_combo_name.GetCurSel();
  166. HandleActivation() ;
  167. return;
  168. }
  169. }
  170. }
  171. LONG
  172. CDhcpDefValDlg::UpdateList
  173. (
  174. CDhcpOption * pdhcType,
  175. BOOL bNew
  176. )
  177. {
  178. LONG err = 0 ;
  179. POSITION posOpt ;
  180. CString strName;
  181. //
  182. // Remove and discard the old item if there is one.
  183. //
  184. if ( ! bNew )
  185. {
  186. posOpt = m_pol_values->Find( m_p_edit_type ) ;
  187. ASSERT( posOpt != NULL ) ;
  188. m_pol_values->RemoveAt( posOpt ) ;
  189. delete m_p_edit_type ;
  190. }
  191. m_p_edit_type = NULL ;
  192. //
  193. // (Re-)add the item; sort the list, update the dialog,
  194. // set focus to the given item.
  195. //
  196. CATCH_MEM_EXCEPTION
  197. {
  198. m_pol_values->AddTail( pdhcType ) ;
  199. m_ol_values_new.AddTail( pdhcType ) ;
  200. m_b_dirty = TRUE ;
  201. pdhcType->SetDirty() ;
  202. m_pol_values->SetDirty() ;
  203. m_pol_values->SortById() ;
  204. Fill() ;
  205. pdhcType->QueryDisplayName(strName);
  206. if (m_combo_name.SelectString (-1, strName ) == CB_ERR)
  207. {
  208. m_combo_name.SetCurSel ( 0); // this should not happen, but just in case
  209. }
  210. HandleActivation() ;
  211. }
  212. END_MEM_EXCEPTION(err) ;
  213. return err ;
  214. }
  215. void
  216. CDhcpDefValDlg::OnClickedButnOptionPro()
  217. {
  218. CString strVendor;
  219. GetCurrentVendor(strVendor);
  220. CDhcpDefOptionDlg dlgDefOpt( m_pol_values, m_p_edit_type, strVendor, this);
  221. if ( dlgDefOpt.DoModal() == IDOK )
  222. {
  223. LONG err = UpdateList( dlgDefOpt.RetrieveParamType(), FALSE ) ;
  224. if ( err )
  225. {
  226. ::DhcpMessageBox( err ) ;
  227. }
  228. }
  229. }
  230. void
  231. CDhcpDefValDlg::OnSetfocusComboOptionClass()
  232. {
  233. m_combo_class_iSel = (int) ::SendMessage (m_combo_class.m_hWnd, LB_GETCURSEL, 0, 0L);
  234. }
  235. void
  236. CDhcpDefValDlg::OnSetfocusComboOptionName()
  237. {
  238. m_combo_name_iSel = (int) ::SendMessage(m_combo_name.m_hWnd, CB_GETCURSEL, 0, 0L);
  239. }
  240. void
  241. CDhcpDefValDlg::OnSelendokComboOptionClass()
  242. {
  243. ASSERT(m_combo_class_iSel >= 0);
  244. if (!HandleValueEdit())
  245. {
  246. m_combo_class.SetCurSel(m_combo_class_iSel);
  247. return;
  248. }
  249. m_combo_class.GetCount();
  250. m_combo_class_iSel = m_combo_class.GetCurSel();
  251. // fill in the appropriate data for the new option class
  252. Fill();
  253. m_combo_name.SetCurSel(0);
  254. m_combo_name_iSel = m_combo_name.GetCurSel();
  255. // update the controls based on whatever option is now selected
  256. HandleActivation() ;
  257. }
  258. void
  259. CDhcpDefValDlg::OnSelchangeComboOptionName()
  260. {
  261. if (m_combo_name_iSel < 0)
  262. {
  263. m_combo_name.SetCurSel(0);
  264. m_combo_name_iSel = m_combo_name.GetCurSel();
  265. HandleActivation() ;
  266. return;
  267. }
  268. int nCurSel = m_combo_name_iSel;
  269. if (!HandleValueEdit())
  270. {
  271. m_combo_name.SetCurSel(nCurSel);
  272. return;
  273. }
  274. m_combo_name_iSel = (int) ::SendMessage(m_combo_name.m_hWnd, CB_GETCURSEL, 0, 0L);
  275. HandleActivation() ;
  276. }
  277. void
  278. CDhcpDefValDlg::OnCancel()
  279. {
  280. // remove any options that were added to the list
  281. // since we are canceling out and not saving the list
  282. CDhcpOption * pCurOption = NULL;
  283. m_ol_values_new.Reset();
  284. while (pCurOption = m_ol_values_new.Next())
  285. {
  286. m_pol_values->Remove(pCurOption);
  287. }
  288. CBaseDialog::OnCancel();
  289. }
  290. void
  291. CDhcpDefValDlg::OnOK()
  292. {
  293. if (!HandleValueEdit())
  294. return;
  295. if ( m_b_dirty )
  296. {
  297. BEGIN_WAIT_CURSOR;
  298. //
  299. // Update the types; tell the routine to display all errors.
  300. //
  301. CDhcpServer * pServer = GETHANDLER(CDhcpServer, m_spNode);
  302. pServer->UpdateOptionList( m_pol_values,
  303. &m_ol_values_defunct,
  304. this );
  305. m_ol_values_new.RemoveAll();
  306. END_WAIT_CURSOR;
  307. }
  308. CBaseDialog::OnOK();
  309. }
  310. void
  311. CDhcpDefValDlg::OnClickedButnValue()
  312. {
  313. if ( m_p_edit_type == NULL ||
  314. (( m_p_edit_type->IsArray() &&
  315. m_p_edit_type->QueryDataType() == DhcpEncapsulatedDataOption ) ||
  316. ( m_p_edit_type->IsArray() &&
  317. m_p_edit_type->QueryDataType() == DhcpBinaryDataOption ))) {
  318. ASSERT( FALSE ) ;
  319. return ;
  320. }
  321. INT_PTR cDlgResult = IDCANCEL ;
  322. DHCP_OPTION_DATA_TYPE enType = m_p_edit_type->QueryValue().QueryDataType() ;
  323. if ( enType == DhcpIpAddressOption )
  324. {
  325. CDhcpIpArrayDlg dlgIpArray( m_p_edit_type, DhcpDefaultOptions, this ) ;
  326. cDlgResult = dlgIpArray.DoModal() ;
  327. }
  328. else if ( enType == DhcpStringDataOption ) {
  329. CDhcpStringArrayEditor dlgStrArray( m_p_edit_type,
  330. DhcpDefaultOptions, this );
  331. cDlgResult = dlgStrArray.DoModal();
  332. }
  333. // Special case for static routes array option 249
  334. else if (( enType == DhcpBinaryDataOption) &&
  335. ( DHCP_OPTION_ID_CSR == m_p_edit_type->QueryId())) {
  336. CDhcpRouteArrayEditor dlgRouteArray( m_p_edit_type,
  337. DhcpDefaultOptions, this );
  338. cDlgResult = dlgRouteArray.DoModal();
  339. }
  340. else
  341. {
  342. CDlgBinEd dlgBinArray( m_p_edit_type, DhcpDefaultOptions, this ) ;
  343. cDlgResult = dlgBinArray.DoModal() ;
  344. }
  345. if ( cDlgResult == IDOK )
  346. {
  347. m_b_dirty = TRUE ;
  348. m_pol_values->SetDirty() ;
  349. HandleActivation( TRUE ) ;
  350. }
  351. } // CDhcpDefValDlg::OnClickedButnValue()
  352. void
  353. CDhcpDefValDlg::OnClickedHelp()
  354. {
  355. }
  356. CDhcpOption *
  357. CDhcpDefValDlg::GetOptionTypeByIndex
  358. (
  359. int iSel
  360. )
  361. {
  362. CString strVendor;
  363. CDhcpOption * pdhcType;
  364. m_pol_values->Reset();
  365. GetCurrentVendor(strVendor);
  366. for ( int i = -1 ; pdhcType = m_pol_values->Next() ; )
  367. {
  368. //
  369. // If we are looking at Vendor options, make sure the option is a vendor option
  370. // If standard options is the class, make sure that it's not a vendor option
  371. // and we aren't filtering it out (it's an option we want the user to set).
  372. //
  373. // The option list is sorted by ID, so we need to make sure we have the correct vendor
  374. // for the given option
  375. //
  376. if ( (m_combo_class_iSel != 0 && pdhcType->IsVendor() &&
  377. strVendor.CompareNoCase(pdhcType->GetVendor()) == 0 ) ||
  378. (m_combo_class_iSel == 0 && !pdhcType->IsVendor() &&
  379. !::FilterOption(pdhcType->QueryId())) )
  380. {
  381. i++ ;
  382. }
  383. if ( i == iSel )
  384. {
  385. break ;
  386. }
  387. }
  388. return pdhcType ;
  389. }
  390. //
  391. // Check the state of the controls
  392. //
  393. void
  394. CDhcpDefValDlg::HandleActivation
  395. (
  396. BOOL bForce
  397. )
  398. {
  399. int iSel = m_combo_name.GetCurSel() ;
  400. CDhcpOption * pdhcType =
  401. ( iSel >= 0 )
  402. ? GetOptionTypeByIndex( iSel )
  403. : NULL ;
  404. if ( pdhcType == NULL ) {
  405. m_edit_string.ShowWindow( SW_HIDE ) ;
  406. m_edit_num.ShowWindow( SW_HIDE ) ;
  407. m_edit_array.ShowWindow( SW_HIDE ) ;
  408. m_ipa_value.ShowWindow( SW_HIDE ) ;
  409. m_static_value_desc.SetWindowText(_T(""));
  410. m_edit_comment.SetWindowText(_T("")) ;
  411. m_butn_delete.EnableWindow( FALSE ) ;
  412. m_butn_prop.EnableWindow( FALSE ) ;
  413. // in case we just disabled the control with focus, move to the
  414. // next control in the tab order
  415. CWnd * pFocus = GetFocus();
  416. while (!pFocus || !pFocus->IsWindowEnabled()) {
  417. NextDlgCtrl();
  418. pFocus = GetFocus();
  419. }
  420. // if the buttons are enabled, make sure they are the default
  421. if (!m_butn_delete.IsWindowEnabled()) {
  422. m_butn_delete.SetButtonStyle(BS_PUSHBUTTON);
  423. m_butn_prop.SetButtonStyle(BS_PUSHBUTTON);
  424. SetDefID(IDOK);
  425. }
  426. m_p_edit_type = NULL;
  427. return ;
  428. } // if
  429. if ( pdhcType == m_p_edit_type && ! bForce ) {
  430. return ;
  431. }
  432. m_p_edit_type = pdhcType ;
  433. DWORD err = 0 ;
  434. DHCP_OPTION_DATA_TYPE enType = m_p_edit_type->QueryValue().QueryDataType() ;
  435. BOOL bNumber = FALSE;
  436. BOOL bString = FALSE;
  437. BOOL bArray = m_p_edit_type->IsArray();
  438. BOOL bIpAddr = FALSE ;
  439. if (enType == DhcpEncapsulatedDataOption ||
  440. enType == DhcpBinaryDataOption) {
  441. bArray = TRUE;
  442. }
  443. CATCH_MEM_EXCEPTION {
  444. CString strValue, strDataType ;
  445. strDataType.LoadString( IDS_INFO_TYPOPT_BYTE + enType ) ;
  446. m_static_value_desc.SetWindowText( strDataType ) ;
  447. m_edit_comment.SetWindowText( m_p_edit_type->QueryComment() ) ;
  448. m_p_edit_type->QueryValue().QueryDisplayString( strValue, TRUE ) ;
  449. // special case for option 249, classless static routes.
  450. if (( pdhcType->QueryId() == DHCP_OPTION_ID_CSR ) &&
  451. ( pdhcType->QueryValue().QueryDataType() ==
  452. DhcpBinaryDataOption )) {
  453. pdhcType->QueryValue().QueryRouteArrayDisplayString( strValue );
  454. }
  455. //
  456. // If it's an array, set the multi-line edit control, else
  457. // fill the appropriate single control.
  458. //
  459. if ( bArray ) {
  460. m_edit_array.FmtLines( TRUE );
  461. m_edit_array.SetWindowText( strValue ) ;
  462. }
  463. else {
  464. switch ( pdhcType->QueryValue().QueryDataType()) {
  465. case DhcpByteOption:
  466. case DhcpWordOption:
  467. case DhcpDWordOption:
  468. case DhcpDWordDWordOption:
  469. m_edit_num.SetWindowText( strValue ) ;
  470. m_edit_num.SetModify(FALSE);
  471. bNumber = TRUE ;
  472. break;
  473. case DhcpStringDataOption:
  474. m_edit_string.SetWindowText( strValue ) ;
  475. m_edit_string.SetModify(FALSE);
  476. bString = TRUE ;
  477. break ;
  478. case DhcpIpAddressOption:
  479. {
  480. DWORD dwIP = m_p_edit_type->QueryValue().QueryIpAddr();
  481. if (dwIP != 0L) {
  482. m_ipa_value.SetAddress( dwIP ) ;
  483. }
  484. else {
  485. m_ipa_value.ClearAddress();
  486. }
  487. m_ipa_value.SetModify(FALSE);
  488. bIpAddr = TRUE ;
  489. }
  490. break ;
  491. default:
  492. Trace2("Default values: type %d has bad data type = %d\n",
  493. (int) pdhcType->QueryId(),
  494. (int) pdhcType->QueryValue().QueryDataType() );
  495. strValue.LoadString( IDS_INFO_TYPNAM_INVALID ) ;
  496. m_edit_array.SetWindowText( strValue ) ;
  497. bArray = TRUE ;
  498. break ;
  499. } // switch
  500. } // else
  501. m_butn_edit_value.ShowWindow(bArray ? SW_NORMAL : SW_HIDE );
  502. m_edit_num.ShowWindow( bNumber ? SW_NORMAL : SW_HIDE ) ;
  503. m_edit_string.ShowWindow( bString ? SW_NORMAL : SW_HIDE ) ;
  504. m_ipa_value.ShowWindow( bIpAddr ? SW_NORMAL : SW_HIDE ) ;
  505. m_edit_array.ShowWindow( bArray ? SW_NORMAL : SW_HIDE ) ;
  506. //
  507. // See comment at top of file about this manifest.
  508. //
  509. BOOL bEnableDelete = ( m_p_edit_type->IsVendor() ||
  510. ( !m_p_edit_type->IsVendor() &&
  511. (( m_p_edit_type->QueryId() > DHCP_MAX_BUILTIN_OPTION_ID ) &&
  512. ( m_p_edit_type->QueryId() != DHCP_OPTION_ID_CSR ))));
  513. m_butn_delete.EnableWindow( bEnableDelete ) ;
  514. m_butn_prop.EnableWindow( TRUE ) ;
  515. } END_MEM_EXCEPTION( err ) ;
  516. if ( err ) {
  517. ::DhcpMessageBox( err ) ;
  518. EndDialog( -1 ) ;
  519. }
  520. } // CDhcpDefValDlg::HandleActivation()
  521. //
  522. // (Re-)Fill the combo box(es)
  523. //
  524. void
  525. CDhcpDefValDlg::Fill()
  526. {
  527. ASSERT( m_pol_values != NULL ) ;
  528. m_combo_name.ResetContent() ;
  529. CDhcpOption * pdhcType ;
  530. CString strName ;
  531. m_pol_values->Reset();
  532. while ( pdhcType = m_pol_values->Next()) {
  533. //
  534. // Add option, unless it's one of our hidden
  535. // options (subnet mask, T1, T2, etc).
  536. // There are no filtered options for vendor specific.
  537. //
  538. if (m_combo_class_iSel == 0) {
  539. if ((!::FilterOption(pdhcType->QueryId())) &&
  540. (!pdhcType->IsVendor())) {
  541. pdhcType->QueryDisplayName( strName );
  542. m_combo_name.AddString( strName );
  543. }
  544. }
  545. else {
  546. CString strCurVendor;
  547. GetCurrentVendor(strCurVendor);
  548. if (pdhcType->GetVendor() &&
  549. strCurVendor.CompareNoCase(pdhcType->GetVendor()) == 0) {
  550. pdhcType->QueryDisplayName( strName );
  551. m_combo_name.AddString( strName );
  552. }
  553. } // else
  554. } // while
  555. } // CDhcpDefValDlg::Fill()
  556. //
  557. // Handle edited data
  558. //
  559. BOOL
  560. CDhcpDefValDlg::HandleValueEdit()
  561. {
  562. if ( m_p_edit_type == NULL )
  563. {
  564. return TRUE ;
  565. }
  566. CDhcpOptionValue & dhcValue = m_p_edit_type->QueryValue() ;
  567. DHCP_OPTION_DATA_TYPE dhcType = dhcValue.QueryDataType() ;
  568. DHCP_IP_ADDRESS dhipa ;
  569. CString strEdit ;
  570. LONG err = 0 ;
  571. BOOL bModified = FALSE ;
  572. if ( m_p_edit_type->IsArray() )
  573. {
  574. bModified = m_edit_array.GetModify() ;
  575. if ( bModified )
  576. {
  577. err = IDS_ERR_ARRAY_EDIT_NOT_SUPPORTED ;
  578. }
  579. }
  580. else
  581. {
  582. switch ( dhcType )
  583. {
  584. case DhcpByteOption:
  585. case DhcpWordOption:
  586. case DhcpDWordOption:
  587. if ( ! m_edit_num.GetModify() )
  588. {
  589. break ;
  590. }
  591. {
  592. DWORD dwResult;
  593. DWORD dwMask = 0xFFFFFFFF;
  594. if (dhcType == DhcpByteOption)
  595. {
  596. dwMask = 0xFF;
  597. }
  598. else if (dhcType == DhcpWordOption)
  599. {
  600. dwMask = 0xFFFF;
  601. }
  602. if (!FGetCtrlDWordValue(m_edit_num.m_hWnd, &dwResult, 0, dwMask))
  603. return FALSE;
  604. bModified = TRUE ;
  605. (void)dhcValue.SetNumber(dwResult, 0 ) ;
  606. ASSERT(err == FALSE);
  607. }
  608. break ;
  609. case DhcpDWordDWordOption:
  610. if ( !m_edit_num.GetModify() )
  611. {
  612. break;
  613. }
  614. {
  615. DWORD_DWORD dwdwResult;
  616. CString strValue;
  617. m_edit_num.GetWindowText(strValue);
  618. UtilConvertStringToDwordDword(strValue, &dwdwResult);
  619. bModified = TRUE ;
  620. (void)dhcValue.SetDwordDword(dwdwResult, 0 ) ;
  621. ASSERT(err == FALSE);
  622. }
  623. break;
  624. case DhcpStringDataOption:
  625. if ( ! m_edit_string.GetModify() )
  626. {
  627. break ;
  628. }
  629. bModified = TRUE ;
  630. m_edit_string.GetWindowText( strEdit ) ;
  631. err = dhcValue.SetString( strEdit, 0 ) ;
  632. break ;
  633. case DhcpIpAddressOption:
  634. if ( ! m_ipa_value.GetModify() )
  635. {
  636. break ;
  637. }
  638. bModified = TRUE ;
  639. if ( ! m_ipa_value.GetAddress( & dhipa ) )
  640. {
  641. err = ERROR_INVALID_PARAMETER ;
  642. break;
  643. }
  644. err = dhcValue.SetIpAddr( dhipa, 0 ) ;
  645. break ;
  646. case DhcpEncapsulatedDataOption:
  647. case DhcpBinaryDataOption:
  648. if ( ! m_edit_array.GetModify() )
  649. {
  650. break ;
  651. }
  652. err = IDS_ERR_BINARY_DATA_NOT_SUPPORTED ;
  653. break ;
  654. //case DhcpEncapsulatedDataOption:
  655. // Trace0("CDhcpDefValDlg:: encapsulated data type not supported in HandleValueEdit");
  656. //break;
  657. default:
  658. Trace0("CDhcpDefValDlg:: invalid value type in HandleValueEdit");
  659. ASSERT( FALSE ) ;
  660. err = ERROR_INVALID_PARAMETER ;
  661. break;
  662. }
  663. }
  664. if ( err )
  665. {
  666. ::DhcpMessageBox( err ) ;
  667. }
  668. else if ( bModified )
  669. {
  670. m_pol_values->SetDirty() ;
  671. m_b_dirty = TRUE ;
  672. m_p_edit_type->SetDirty() ;
  673. HandleActivation( TRUE ) ;
  674. }
  675. return err == 0 ;
  676. }
  677. BOOL
  678. CDhcpDefValDlg::OnInitDialog()
  679. {
  680. CBaseDialog::OnInitDialog();
  681. DWORD err = 0 ;
  682. CString strTitle ;
  683. m_edit_string.LimitText( EDIT_STRING_MAX ) ;
  684. m_edit_string.ShowWindow( SW_HIDE );
  685. m_edit_num.ShowWindow( SW_HIDE );
  686. m_edit_num.LimitText( 25/*EDIT_ID_MAX*/ ) ;
  687. m_edit_array.LimitText( EDIT_ARRAY_MAX ) ;
  688. m_edit_array.ShowWindow( SW_HIDE );
  689. m_edit_array.SetReadOnly() ;
  690. m_butn_edit_value.ShowWindow( SW_HIDE );
  691. m_ipa_value.ShowWindow( SW_HIDE ) ;
  692. m_static_value_desc.SetWindowText(_T("")) ;
  693. m_edit_comment.SetWindowText(_T("")) ;
  694. CATCH_MEM_EXCEPTION
  695. {
  696. if ( m_pol_values->SetAll( FALSE ) )
  697. {
  698. Trace0("CDhcpDefValDlg::OnInitDialog: newly created list was dirty");
  699. }
  700. //
  701. // Add the two types of options we can define--either
  702. // DHCP default or vendor specific
  703. //
  704. strTitle.LoadString( IDS_INFO_NAME_DHCP_DEFAULT ) ;
  705. m_combo_class.AddString( strTitle ) ;
  706. // now add any vendor classes that are defined
  707. CClassInfoArray ClassInfoArray;
  708. CDhcpServer * pServer = GETHANDLER(CDhcpServer, m_spNode);
  709. pServer->GetClassInfoArray(ClassInfoArray);
  710. for (int i = 0; i < ClassInfoArray.GetSize(); i++)
  711. {
  712. if (ClassInfoArray[i].bIsVendor)
  713. {
  714. m_combo_class.AddString( ClassInfoArray[i].strName ) ;
  715. }
  716. }
  717. m_combo_class.SetCurSel( 0 );
  718. m_combo_class_iSel = 0;
  719. //
  720. // Fill the list box.
  721. //
  722. Fill() ;
  723. //
  724. // Select the first item.
  725. //
  726. m_combo_name.SetCurSel( 0 ) ;
  727. HandleActivation() ;
  728. }
  729. END_MEM_EXCEPTION( err )
  730. if ( err )
  731. {
  732. ::DhcpMessageBox( err ) ;
  733. EndDialog( -1 ) ;
  734. }
  735. return FALSE ;
  736. } // CD