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.

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