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.

967 lines
23 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. ScopePP.cpp
  7. This file contains all of the implementation for the
  8. scope property page.
  9. FILE HISTORY:
  10. */
  11. #include "stdafx.h"
  12. #include "scopepp.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. #define RADIO_SCOPE_TYPE_BOTH 2
  20. #define RADIO_SCOPE_TYPE_DHCP 0
  21. #define RADIO_SCOPE_TYPE_BOOTP 1
  22. /////////////////////////////////////////////////////////////////////////////
  23. //
  24. // CScopeProperties holder
  25. //
  26. /////////////////////////////////////////////////////////////////////////////
  27. CScopeProperties::CScopeProperties
  28. (
  29. ITFSNode * pNode,
  30. IComponentData * pComponentData,
  31. ITFSComponentData * pTFSCompData,
  32. LPCTSTR pszSheetName
  33. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  34. {
  35. //ASSERT(pFolderNode == GetContainerNode());
  36. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  37. m_liVersion.QuadPart = 0;
  38. m_fSupportsDynBootp = FALSE;
  39. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  40. Assert(pTFSCompData != NULL);
  41. m_spTFSCompData.Set(pTFSCompData);
  42. }
  43. CScopeProperties::~CScopeProperties()
  44. {
  45. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  46. if (m_liVersion.QuadPart >= DHCP_NT5_VERSION)
  47. {
  48. RemovePageFromList((CPropertyPageBase*) &m_pageDns, FALSE);
  49. }
  50. if (m_fSupportsDynBootp)
  51. {
  52. RemovePageFromList((CPropertyPageBase*) &m_pageAdvanced, FALSE);
  53. }
  54. }
  55. void
  56. CScopeProperties::SetVersion
  57. (
  58. LARGE_INTEGER & liVersion
  59. )
  60. {
  61. m_liVersion = liVersion;
  62. if (m_liVersion.QuadPart >= DHCP_NT5_VERSION)
  63. {
  64. AddPageToList((CPropertyPageBase*) &m_pageDns);
  65. }
  66. }
  67. void
  68. CScopeProperties::SetDnsRegistration
  69. (
  70. DWORD dnsRegOption,
  71. DHCP_OPTION_SCOPE_TYPE dhcpOptionType
  72. )
  73. {
  74. m_pageDns.m_dwFlags = dnsRegOption;
  75. m_pageDns.m_dhcpOptionType = dhcpOptionType;
  76. }
  77. void
  78. CScopeProperties::SetSupportsDynBootp(BOOL fSupportsDynBootp)
  79. {
  80. if (fSupportsDynBootp)
  81. {
  82. AddPageToList((CPropertyPageBase*) &m_pageAdvanced);
  83. m_fSupportsDynBootp = TRUE;
  84. }
  85. }
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CScopePropGeneral property page
  88. IMPLEMENT_DYNCREATE(CScopePropGeneral, CPropertyPageBase)
  89. CScopePropGeneral::CScopePropGeneral() : CPropertyPageBase(CScopePropGeneral::IDD)
  90. {
  91. //{{AFX_DATA_INIT(CScopePropGeneral)
  92. m_strComment = _T("");
  93. m_strName = _T("");
  94. //}}AFX_DATA_INIT
  95. m_bInitialized = FALSE;
  96. m_bUpdateName = FALSE;
  97. m_bUpdateComment = FALSE;
  98. m_bUpdateLease = FALSE;
  99. m_bUpdateRange = FALSE;
  100. m_uImage = 0;
  101. }
  102. CScopePropGeneral::~CScopePropGeneral()
  103. {
  104. }
  105. void CScopePropGeneral::DoDataExchange(CDataExchange* pDX)
  106. {
  107. CPropertyPageBase::DoDataExchange(pDX);
  108. //{{AFX_DATA_MAP(CScopePropGeneral)
  109. DDX_Control(pDX, IDC_EDIT_SCOPE_NAME, m_editName);
  110. DDX_Control(pDX, IDC_EDIT_SCOPE_COMMENT, m_editComment);
  111. DDX_Control(pDX, IDC_EDIT_SUBNET_MASK_LENGTH, m_editSubnetMaskLength);
  112. DDX_Control(pDX, IDC_RADIO_LEASE_UNLIMITED, m_radioUnlimited);
  113. DDX_Control(pDX, IDC_RADIO_LEASE_LIMITED, m_radioLimited);
  114. DDX_Control(pDX, IDC_EDIT_LEASE_MINUTES, m_editMinutes);
  115. DDX_Control(pDX, IDC_EDIT_LEASE_HOURS, m_editHours);
  116. DDX_Control(pDX, IDC_EDIT_LEASE_DAYS, m_editDays);
  117. DDX_Control(pDX, IDC_SPIN_SUBNET_MASK_LENGTH, m_spinSubnetMaskLength);
  118. DDX_Control(pDX, IDC_SPIN_LEASE_HOURS, m_spinHours);
  119. DDX_Control(pDX, IDC_SPIN_LEASE_MINUTES, m_spinMinutes);
  120. DDX_Control(pDX, IDC_SPIN_LEASE_DAYS, m_spinDays);
  121. DDX_Text(pDX, IDC_EDIT_SCOPE_COMMENT, m_strComment);
  122. DDX_Text(pDX, IDC_EDIT_SCOPE_NAME, m_strName);
  123. //}}AFX_DATA_MAP
  124. DDX_Control(pDX, IDC_IPADDR_START, m_ipaStart);
  125. DDX_Control(pDX, IDC_IPADDR_END, m_ipaEnd);
  126. DDX_Control(pDX, IDC_IPADDR_MASK, m_ipaSubnetMask);
  127. }
  128. BEGIN_MESSAGE_MAP(CScopePropGeneral, CPropertyPageBase)
  129. //{{AFX_MSG_MAP(CScopePropGeneral)
  130. ON_BN_CLICKED(IDC_RADIO_LEASE_LIMITED, OnRadioLeaseLimited)
  131. ON_BN_CLICKED(IDC_RADIO_LEASE_UNLIMITED, OnRadioLeaseUnlimited)
  132. ON_EN_CHANGE(IDC_EDIT_LEASE_DAYS, OnChangeEditLeaseDays)
  133. ON_EN_CHANGE(IDC_EDIT_LEASE_HOURS, OnChangeEditLeaseHours)
  134. ON_EN_CHANGE(IDC_EDIT_LEASE_MINUTES, OnChangeEditLeaseMinutes)
  135. ON_EN_CHANGE(IDC_EDIT_SUBNET_MASK_LENGTH, OnChangeEditSubnetMaskLength)
  136. ON_EN_KILLFOCUS(IDC_IPADDR_MASK, OnKillfocusSubnetMask)
  137. ON_EN_CHANGE(IDC_EDIT_SCOPE_COMMENT, OnChangeEditScopeComment)
  138. ON_EN_CHANGE(IDC_EDIT_SCOPE_NAME, OnChangeEditScopeName)
  139. //}}AFX_MSG_MAP
  140. ON_EN_CHANGE(IDC_IPADDR_START, OnChangeIpAddrStart)
  141. ON_EN_CHANGE(IDC_IPADDR_END, OnChangeIpAddrStart)
  142. END_MESSAGE_MAP()
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CScopePropGeneral message handlers
  145. BOOL CScopePropGeneral::OnInitDialog()
  146. {
  147. CPropertyPageBase::OnInitDialog();
  148. // Limit the name and comment fields to 255 chars
  149. CEdit *pEditName = reinterpret_cast<CEdit *>(GetDlgItem( IDC_EDIT_SCOPE_NAME ));
  150. if ( 0 != pEditName ) {
  151. pEditName->LimitText( MAX_NAME_LENGTH ); // max characters for superscope name
  152. }
  153. CEdit *pEditComment = reinterpret_cast<CEdit *>(GetDlgItem( IDC_EDIT_SCOPE_COMMENT ));
  154. if ( 0 != pEditComment ) {
  155. pEditComment->LimitText( MAX_NAME_LENGTH ); // max characters for superscope name
  156. }
  157. m_ipaStart.SetAddress(m_dwStartAddress);
  158. m_ipaEnd.SetAddress(m_dwEndAddress);
  159. m_ipaSubnetMask.SetAddress(m_dwSubnetMask);
  160. m_ipaSubnetMask.EnableWindow(FALSE);
  161. m_spinMinutes.SetRange(0, 59);
  162. m_spinHours.SetRange(0, 23);
  163. m_spinDays.SetRange(0, 999);
  164. m_editMinutes.LimitText(2);
  165. m_editHours.LimitText(2);
  166. m_editDays.LimitText(3);
  167. if (m_dwLeaseTime != DHCP_INFINIT_LEASE)
  168. {
  169. int nDays, nHours, nMinutes;
  170. UtilConvertLeaseTime(m_dwLeaseTime, &nDays, &nHours, &nMinutes);
  171. m_spinDays.SetPos(nDays);
  172. m_spinHours.SetPos(nHours);
  173. m_spinMinutes.SetPos(nMinutes);
  174. }
  175. m_radioUnlimited.SetCheck(m_dwLeaseTime == DHCP_INFINIT_LEASE);
  176. m_radioLimited.SetCheck(m_dwLeaseTime != DHCP_INFINIT_LEASE);
  177. ActivateDuration (m_dwLeaseTime != DHCP_INFINIT_LEASE);
  178. m_bInitialized = TRUE;
  179. m_spinSubnetMaskLength.SetRange(8, 32);
  180. UpdateMask(FALSE);
  181. m_spinSubnetMaskLength.EnableWindow(FALSE);
  182. m_editSubnetMaskLength.EnableWindow(FALSE);
  183. m_ipaSubnetMask.SetReadOnly(TRUE);
  184. // load the correct icon
  185. for (int i = 0; i < ICON_IDX_MAX; i++)
  186. {
  187. if (g_uIconMap[i][1] == m_uImage)
  188. {
  189. HICON hIcon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  190. if (hIcon)
  191. ((CStatic *) GetDlgItem(IDC_STATIC_ICON))->SetIcon(hIcon);
  192. break;
  193. }
  194. }
  195. SetDirty(FALSE);
  196. return TRUE; // return TRUE unless you set the focus to a control
  197. // EXCEPTION: OCX Property Pages should return FALSE
  198. }
  199. BOOL CScopePropGeneral::OnSetActive()
  200. {
  201. BOOL fEnable = TRUE;
  202. CScopeProperties * pScopeProp = (CScopeProperties *) GetHolder();
  203. if (pScopeProp->FSupportsDynBootp())
  204. {
  205. if (pScopeProp->m_pageAdvanced.m_RangeType == DhcpIpRangesBootpOnly)
  206. {
  207. fEnable = FALSE;
  208. }
  209. }
  210. // enable/disable DHCP clients lease time
  211. GetDlgItem(IDC_RADIO_LEASE_UNLIMITED)->EnableWindow(fEnable);
  212. GetDlgItem(IDC_RADIO_LEASE_LIMITED)->EnableWindow(fEnable);
  213. GetDlgItem(IDC_STATIC_DHCP_DURATION)->EnableWindow(fEnable);
  214. if (fEnable && IsDlgButtonChecked(IDC_RADIO_LEASE_LIMITED))
  215. {
  216. fEnable = TRUE;
  217. }
  218. else
  219. {
  220. fEnable = FALSE;
  221. }
  222. ActivateDuration(fEnable);
  223. return CPropertyPageBase::OnSetActive();
  224. }
  225. void CScopePropGeneral::OnRadioLeaseLimited()
  226. {
  227. if (((CButton *) GetDlgItem(IDC_RADIO_LEASE_LIMITED))->GetCheck())
  228. {
  229. ActivateDuration(TRUE);
  230. SetDirty(TRUE);
  231. }
  232. }
  233. void CScopePropGeneral::OnRadioLeaseUnlimited()
  234. {
  235. if (((CButton *) GetDlgItem(IDC_RADIO_LEASE_UNLIMITED))->GetCheck())
  236. {
  237. ActivateDuration(FALSE);
  238. SetDirty(TRUE);
  239. }
  240. }
  241. BOOL CScopePropGeneral::OnApply()
  242. {
  243. UpdateData();
  244. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  245. DWORD dwLeaseTime;
  246. if (m_radioUnlimited.GetCheck())
  247. {
  248. dwLeaseTime = DHCP_INFINIT_LEASE;
  249. }
  250. else
  251. {
  252. dwLeaseTime = UtilConvertLeaseTime(m_spinDays.GetPos(),
  253. m_spinHours.GetPos(),
  254. m_spinMinutes.GetPos());
  255. }
  256. if (dwLeaseTime == 0)
  257. {
  258. DhcpMessageBox(IDS_ERR_NO_DURATION_SPECIFIED);
  259. m_editDays.SetFocus();
  260. return FALSE;
  261. }
  262. if (dwLeaseTime != m_dwLeaseTime)
  263. {
  264. m_bUpdateLease = TRUE;
  265. m_dwLeaseTime = dwLeaseTime;
  266. }
  267. m_bUpdateName = m_editName.GetModify();
  268. m_editName.SetModify(FALSE);
  269. m_bUpdateComment = m_editComment.GetModify();
  270. m_editComment.SetModify(FALSE);
  271. if (m_ipaStart.GetModify() ||
  272. m_ipaEnd.GetModify() )
  273. {
  274. DWORD dwStartAddr, dwEndAddr;
  275. m_ipaStart.GetAddress(&dwStartAddr);
  276. m_ipaEnd.GetAddress(&dwEndAddr);
  277. // make sure that the starting address != subnet address
  278. if ( ((dwStartAddr & ~m_dwSubnetMask) == (DWORD) 0) ||
  279. (dwStartAddr > dwEndAddr) )
  280. {
  281. Trace0("CScopePropGeneral::OnApply() - starting range is 0 for subnet\n");
  282. DhcpMessageBox(IDS_ERR_IP_RANGE_INV_START);
  283. m_ipaStart.SetFocus();
  284. return FALSE;
  285. }
  286. // make sure that the subnet broadcast address is not the ending address
  287. if ((dwEndAddr & ~m_dwSubnetMask) == ~m_dwSubnetMask)
  288. {
  289. Trace0("CScopePropGeneral::OnApply() - ending range is subnet broadcast addr\n");
  290. DhcpMessageBox(IDS_ERR_IP_RANGE_INV_END);
  291. m_ipaEnd.SetFocus();
  292. return FALSE;
  293. }
  294. m_bUpdateRange = TRUE;
  295. m_dwStartAddress = dwStartAddr;
  296. m_dwEndAddress = dwEndAddr;
  297. }
  298. BOOL bRet = CPropertyPageBase::OnApply();
  299. if (bRet == FALSE)
  300. {
  301. // Something bad happened... grab the error code
  302. // AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  303. ::DhcpMessageBox(GetHolder()->GetError());
  304. }
  305. return bRet;
  306. }
  307. BOOL CScopePropGeneral::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  308. {
  309. CDhcpScope * pScope;
  310. SPITFSNode spNode;
  311. DWORD dwError = 0;
  312. spNode = GetHolder()->GetNode();
  313. pScope = GETHANDLER(CDhcpScope, spNode);
  314. BEGIN_WAIT_CURSOR;
  315. //
  316. // Check to see if we need to update the least time
  317. //
  318. if (m_bUpdateLease)
  319. {
  320. // Lease time changed, update on server
  321. dwError = pScope->SetLeaseTime(m_dwLeaseTime);
  322. if (dwError != ERROR_SUCCESS)
  323. {
  324. GetHolder()->SetError(dwError);
  325. }
  326. m_bUpdateLease = FALSE;
  327. }
  328. //
  329. // Now check the allocation range
  330. //
  331. if (m_bUpdateRange)
  332. {
  333. // need to update the address pool allocation range
  334. CDhcpIpRange dhcpIpRange;
  335. dhcpIpRange.SetAddr(m_dwStartAddress, TRUE);
  336. dhcpIpRange.SetAddr(m_dwEndAddress, FALSE);
  337. dhcpIpRange.SetRangeType(((CScopeProperties *) GetHolder())->m_pageAdvanced.m_RangeType);
  338. dwError = pScope->SetIpRange(dhcpIpRange, TRUE);
  339. if (dwError != ERROR_SUCCESS)
  340. {
  341. GetHolder()->SetError(dwError);
  342. }
  343. }
  344. //
  345. // Update the name and comment if necessary
  346. //
  347. if (m_bUpdateName)
  348. {
  349. pScope->SetName(m_strName);
  350. *ChangeMask = SCOPE_PANE_CHANGE_ITEM_DATA;
  351. }
  352. if (m_bUpdateComment)
  353. {
  354. pScope->SetComment(m_strComment);
  355. }
  356. if (m_bUpdateName || m_bUpdateComment)
  357. {
  358. dwError = pScope->SetInfo();
  359. if (dwError != ERROR_SUCCESS)
  360. {
  361. GetHolder()->SetError(dwError);
  362. }
  363. m_bUpdateName = m_bUpdateComment = FALSE;
  364. }
  365. END_WAIT_CURSOR;
  366. return FALSE;
  367. }
  368. void CScopePropGeneral::OnChangeEditLeaseDays()
  369. {
  370. ValidateLeaseTime();
  371. SetDirty(TRUE);
  372. }
  373. void CScopePropGeneral::OnChangeEditLeaseHours()
  374. {
  375. ValidateLeaseTime();
  376. SetDirty(TRUE);
  377. }
  378. void CScopePropGeneral::OnChangeEditLeaseMinutes()
  379. {
  380. ValidateLeaseTime();
  381. SetDirty(TRUE);
  382. }
  383. void CScopePropGeneral::OnChangeEditSubnetMaskLength()
  384. {
  385. UpdateMask(TRUE);
  386. SetDirty(TRUE);
  387. }
  388. void CScopePropGeneral::OnKillfocusSubnetMask()
  389. {
  390. UpdateMask(FALSE);
  391. SetDirty(TRUE);
  392. }
  393. void CScopePropGeneral::OnChangeEditScopeComment()
  394. {
  395. SetDirty(TRUE);
  396. }
  397. void CScopePropGeneral::OnChangeEditScopeName()
  398. {
  399. SetDirty(TRUE);
  400. }
  401. void CScopePropGeneral::OnChangeIpAddrStart()
  402. {
  403. SetDirty(TRUE);
  404. }
  405. void CScopePropGeneral::OnChangeIpAddrEnd()
  406. {
  407. SetDirty(TRUE);
  408. }
  409. //
  410. // Helpers
  411. //
  412. void
  413. CScopePropGeneral::ActivateDuration
  414. (
  415. BOOL fActive
  416. )
  417. {
  418. m_spinMinutes.EnableWindow(fActive);
  419. m_spinHours.EnableWindow(fActive);
  420. m_spinDays.EnableWindow(fActive);
  421. m_editMinutes.EnableWindow(fActive);
  422. m_editHours.EnableWindow(fActive);
  423. m_editDays.EnableWindow(fActive);
  424. GetDlgItem(IDC_STATIC_DAYS)->EnableWindow(fActive);
  425. GetDlgItem(IDC_STATIC_HOURS)->EnableWindow(fActive);
  426. GetDlgItem(IDC_STATIC_MINUTES)->EnableWindow(fActive);
  427. }
  428. //
  429. // Update the subnet mask field using either the length identifier or
  430. // the acutal address as the base
  431. //
  432. void
  433. CScopePropGeneral::UpdateMask(BOOL bUseLength)
  434. {
  435. if (m_bInitialized)
  436. {
  437. if (bUseLength)
  438. {
  439. DWORD dwAddress = 0xFFFFFFFF;
  440. dwAddress = dwAddress << (32 - (DWORD) m_spinSubnetMaskLength.GetPos());
  441. m_ipaSubnetMask.SetAddress(dwAddress);
  442. }
  443. else
  444. {
  445. DWORD dwAddress, dwTestMask = 0x80000000;
  446. int nLength = 0;
  447. m_ipaSubnetMask.GetAddress(&dwAddress);
  448. while (TRUE)
  449. {
  450. if (dwAddress & dwTestMask)
  451. {
  452. nLength++;
  453. dwTestMask = dwTestMask >> 1;
  454. }
  455. else
  456. {
  457. break;
  458. }
  459. }
  460. m_spinSubnetMaskLength.SetPos(nLength);
  461. }
  462. }
  463. }
  464. void
  465. CScopePropGeneral::ValidateLeaseTime()
  466. {
  467. CString strText;
  468. if (IsWindow(m_editHours.GetSafeHwnd()))
  469. {
  470. m_editHours.GetWindowText(strText);
  471. // check to see if the value is greater than the max
  472. if (_ttoi(strText) > HOURS_MAX)
  473. {
  474. LPTSTR pBuf = strText.GetBuffer(5);
  475. _itot(HOURS_MAX, pBuf, 10);
  476. strText.ReleaseBuffer();
  477. m_editHours.SetWindowText(strText);
  478. m_spinHours.SetPos(HOURS_MAX);
  479. MessageBeep(MB_ICONEXCLAMATION);
  480. }
  481. }
  482. if (IsWindow(m_editMinutes.GetSafeHwnd()))
  483. {
  484. m_editMinutes.GetWindowText(strText);
  485. // check to see if the value is greater than the max
  486. if (_ttoi(strText) > MINUTES_MAX)
  487. {
  488. LPTSTR pBuf = strText.GetBuffer(5);
  489. _itot(MINUTES_MAX, pBuf, 10);
  490. strText.ReleaseBuffer();
  491. m_editMinutes.SetWindowText(strText);
  492. m_spinMinutes.SetPos(MINUTES_MAX);
  493. MessageBeep(MB_ICONEXCLAMATION);
  494. }
  495. }
  496. }
  497. /////////////////////////////////////////////////////////////////////////////
  498. // CScopePropAdvanced property page
  499. IMPLEMENT_DYNCREATE(CScopePropAdvanced, CPropertyPageBase)
  500. CScopePropAdvanced::CScopePropAdvanced() : CPropertyPageBase(CScopePropAdvanced::IDD)
  501. {
  502. //{{AFX_DATA_INIT(CScopePropAdvanced)
  503. m_nRangeType = -1;
  504. //}}AFX_DATA_INIT
  505. }
  506. CScopePropAdvanced::~CScopePropAdvanced()
  507. {
  508. }
  509. void CScopePropAdvanced::DoDataExchange(CDataExchange* pDX)
  510. {
  511. CPropertyPageBase::DoDataExchange(pDX);
  512. //{{AFX_DATA_MAP(CScopePropAdvanced)
  513. DDX_Control(pDX, IDC_STATIC_BOOTP_DURATION, m_staticDuration);
  514. DDX_Control(pDX, IDC_SPIN_LEASE_MINUTES, m_spinMinutes);
  515. DDX_Control(pDX, IDC_SPIN_LEASE_HOURS, m_spinHours);
  516. DDX_Control(pDX, IDC_SPIN_LEASE_DAYS, m_spinDays);
  517. DDX_Control(pDX, IDC_EDIT_LEASE_MINUTES, m_editMinutes);
  518. DDX_Control(pDX, IDC_EDIT_LEASE_HOURS, m_editHours);
  519. DDX_Control(pDX, IDC_EDIT_LEASE_DAYS, m_editDays);
  520. DDX_Radio(pDX, IDC_RADIO_DHCP_ONLY, m_nRangeType);
  521. //}}AFX_DATA_MAP
  522. }
  523. BEGIN_MESSAGE_MAP(CScopePropAdvanced, CPropertyPageBase)
  524. //{{AFX_MSG_MAP(CScopePropAdvanced)
  525. ON_BN_CLICKED(IDC_RADIO_LEASE_LIMITED, OnRadioLeaseLimited)
  526. ON_BN_CLICKED(IDC_RADIO_LEASE_UNLIMITED, OnRadioLeaseUnlimited)
  527. ON_EN_CHANGE(IDC_EDIT_LEASE_DAYS, OnChangeEditLeaseDays)
  528. ON_EN_CHANGE(IDC_EDIT_LEASE_HOURS, OnChangeEditLeaseHours)
  529. ON_EN_CHANGE(IDC_EDIT_LEASE_MINUTES, OnChangeEditLeaseMinutes)
  530. ON_BN_CLICKED(IDC_RADIO_BOOTP_ONLY, OnRadioBootpOnly)
  531. ON_BN_CLICKED(IDC_RADIO_DHCP_BOOTP, OnRadioDhcpBootp)
  532. ON_BN_CLICKED(IDC_RADIO_DHCP_ONLY, OnRadioDhcpOnly)
  533. //}}AFX_MSG_MAP
  534. END_MESSAGE_MAP()
  535. /////////////////////////////////////////////////////////////////////////////
  536. // CScopePropAdvanced message handlers
  537. BOOL CScopePropAdvanced::OnInitDialog()
  538. {
  539. CPropertyPageBase::OnInitDialog();
  540. BOOL fActivateLeaseSelection = TRUE;
  541. switch (m_RangeType)
  542. {
  543. case DhcpIpRangesDhcpBootp:
  544. ((CButton *) GetDlgItem(IDC_RADIO_DHCP_BOOTP))->SetCheck(TRUE);
  545. break;
  546. case DhcpIpRangesBootpOnly:
  547. ((CButton *) GetDlgItem(IDC_RADIO_BOOTP_ONLY))->SetCheck(TRUE);
  548. break;
  549. case DhcpIpRangesDhcpOnly:
  550. default:
  551. ((CButton *) GetDlgItem(IDC_RADIO_DHCP_ONLY))->SetCheck(TRUE);
  552. fActivateLeaseSelection = FALSE;
  553. break;
  554. }
  555. BOOL fUnlimited = TRUE;
  556. if (m_dwLeaseTime != DHCP_INFINIT_LEASE)
  557. {
  558. int nDays, nHours, nMinutes;
  559. UtilConvertLeaseTime(m_dwLeaseTime, &nDays, &nHours, &nMinutes);
  560. m_spinDays.SetPos(nDays);
  561. m_spinHours.SetPos(nHours);
  562. m_spinMinutes.SetPos(nMinutes);
  563. fUnlimited = FALSE;
  564. }
  565. //UINT uControl = fUnlimited ? IDC_RADIO_LEASE_UNLIMITED : IDC_RADIO_LEASE_LIMITED;
  566. //((CButton *) GetDlgItem(uControl))->SetCheck(TRUE);
  567. //ActivateDuration(m_dwLeaseTime != DHCP_INFINIT_LEASE);
  568. if (fUnlimited)
  569. {
  570. ((CButton *) GetDlgItem(IDC_RADIO_LEASE_UNLIMITED))->SetCheck(TRUE);
  571. ((CButton *) GetDlgItem(IDC_RADIO_LEASE_LIMITED))->SetCheck(FALSE);
  572. }
  573. else
  574. {
  575. ((CButton *) GetDlgItem(IDC_RADIO_LEASE_UNLIMITED))->SetCheck(FALSE);
  576. ((CButton *) GetDlgItem(IDC_RADIO_LEASE_LIMITED))->SetCheck(TRUE);
  577. }
  578. m_spinMinutes.SetRange(0, 59);
  579. m_spinHours.SetRange(0, 23);
  580. m_spinDays.SetRange(0, 999);
  581. m_editMinutes.LimitText(2);
  582. m_editHours.LimitText(2);
  583. m_editDays.LimitText(3);
  584. ActivateLeaseSelection(fActivateLeaseSelection);
  585. SetDirty(FALSE);
  586. return TRUE; // return TRUE unless you set the focus to a control
  587. // EXCEPTION: OCX Property Pages should return FALSE
  588. }
  589. BOOL CScopePropAdvanced::OnApply()
  590. {
  591. UpdateData();
  592. DWORD dwLeaseTime;
  593. if (((CButton *)GetDlgItem(IDC_RADIO_LEASE_UNLIMITED))->GetCheck())
  594. {
  595. m_dwLeaseTime = DHCP_INFINIT_LEASE;
  596. }
  597. else
  598. {
  599. m_dwLeaseTime = UtilConvertLeaseTime(m_spinDays.GetPos(),
  600. m_spinHours.GetPos(),
  601. m_spinMinutes.GetPos());
  602. }
  603. if (m_dwLeaseTime == 0)
  604. {
  605. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  606. DhcpMessageBox(IDS_ERR_NO_DURATION_SPECIFIED);
  607. m_editDays.SetFocus();
  608. return FALSE;
  609. }
  610. m_RangeType = GetRangeType();
  611. BOOL bRet = CPropertyPageBase::OnApply();
  612. if (bRet == FALSE)
  613. {
  614. // Something bad happened... grab the error code
  615. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  616. ::DhcpMessageBox(GetHolder()->GetError());
  617. }
  618. return bRet;
  619. }
  620. BOOL CScopePropAdvanced::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  621. {
  622. CDhcpScope * pScope;
  623. SPITFSNode spNode;
  624. DWORD dwError = 0;
  625. spNode = GetHolder()->GetNode();
  626. pScope = GETHANDLER(CDhcpScope, spNode);
  627. BEGIN_WAIT_CURSOR;
  628. dwError = pScope->SetDynamicBootpInfo(m_RangeType, m_dwLeaseTime);
  629. if (dwError != ERROR_SUCCESS)
  630. {
  631. GetHolder()->SetError(dwError);
  632. }
  633. END_WAIT_CURSOR;
  634. return FALSE;
  635. }
  636. UINT CScopePropAdvanced::GetRangeType()
  637. {
  638. UINT uType = DhcpIpRangesDhcpOnly; // default
  639. switch (m_nRangeType)
  640. {
  641. case RADIO_SCOPE_TYPE_DHCP:
  642. uType = DhcpIpRangesDhcpOnly;
  643. break;
  644. case RADIO_SCOPE_TYPE_BOTH:
  645. uType = DhcpIpRangesDhcpBootp;
  646. break;
  647. case RADIO_SCOPE_TYPE_BOOTP:
  648. uType = DhcpIpRangesBootpOnly;
  649. break;
  650. }
  651. return uType;
  652. }
  653. void CScopePropAdvanced::OnRadioLeaseLimited()
  654. {
  655. if (((CButton *) GetDlgItem(IDC_RADIO_LEASE_LIMITED))->GetCheck())
  656. {
  657. ActivateDuration(TRUE);
  658. SetDirty(TRUE);
  659. }
  660. }
  661. void CScopePropAdvanced::OnRadioLeaseUnlimited()
  662. {
  663. if (((CButton *) GetDlgItem(IDC_RADIO_LEASE_UNLIMITED))->GetCheck())
  664. {
  665. ActivateDuration(FALSE);
  666. SetDirty(TRUE);
  667. }
  668. }
  669. void CScopePropAdvanced::OnChangeEditLeaseDays()
  670. {
  671. ValidateLeaseTime();
  672. SetDirty(TRUE);
  673. }
  674. void CScopePropAdvanced::OnChangeEditLeaseHours()
  675. {
  676. ValidateLeaseTime();
  677. SetDirty(TRUE);
  678. }
  679. void CScopePropAdvanced::OnChangeEditLeaseMinutes()
  680. {
  681. ValidateLeaseTime();
  682. SetDirty(TRUE);
  683. }
  684. void CScopePropAdvanced::OnRadioBootpOnly()
  685. {
  686. UpdateData();
  687. m_RangeType = GetRangeType();
  688. ActivateLeaseSelection(TRUE);
  689. SetDirty(TRUE);
  690. }
  691. void CScopePropAdvanced::OnRadioDhcpBootp()
  692. {
  693. UpdateData();
  694. m_RangeType = GetRangeType();
  695. ActivateLeaseSelection(TRUE);
  696. SetDirty(TRUE);
  697. }
  698. void CScopePropAdvanced::OnRadioDhcpOnly()
  699. {
  700. UpdateData();
  701. m_RangeType = GetRangeType();
  702. ActivateLeaseSelection(FALSE);
  703. SetDirty(TRUE);
  704. }
  705. void
  706. CScopePropAdvanced::ValidateLeaseTime()
  707. {
  708. CString strText;
  709. if (IsWindow(m_editHours.GetSafeHwnd()))
  710. {
  711. m_editHours.GetWindowText(strText);
  712. // check to see if the value is greater than the max
  713. if (_ttoi(strText) > HOURS_MAX)
  714. {
  715. LPTSTR pBuf = strText.GetBuffer(5);
  716. _itot(HOURS_MAX, pBuf, 10);
  717. strText.ReleaseBuffer();
  718. m_editHours.SetWindowText(strText);
  719. m_spinHours.SetPos(HOURS_MAX);
  720. MessageBeep(MB_ICONEXCLAMATION);
  721. }
  722. }
  723. if (IsWindow(m_editMinutes.GetSafeHwnd()))
  724. {
  725. m_editMinutes.GetWindowText(strText);
  726. // check to see if the value is greater than the max
  727. if (_ttoi(strText) > MINUTES_MAX)
  728. {
  729. LPTSTR pBuf = strText.GetBuffer(5);
  730. _itot(MINUTES_MAX, pBuf, 10);
  731. strText.ReleaseBuffer();
  732. m_editMinutes.SetWindowText(strText);
  733. m_spinMinutes.SetPos(MINUTES_MAX);
  734. MessageBeep(MB_ICONEXCLAMATION);
  735. }
  736. }
  737. }
  738. void
  739. CScopePropAdvanced::ActivateDuration
  740. (
  741. BOOL fActive
  742. )
  743. {
  744. m_spinMinutes.EnableWindow(fActive);
  745. m_spinHours.EnableWindow(fActive);
  746. m_spinDays.EnableWindow(fActive);
  747. m_editMinutes.EnableWindow(fActive);
  748. m_editHours.EnableWindow(fActive);
  749. m_editDays.EnableWindow(fActive);
  750. GetDlgItem(IDC_STATIC_DAYS)->EnableWindow(fActive);
  751. GetDlgItem(IDC_STATIC_HOURS)->EnableWindow(fActive);
  752. GetDlgItem(IDC_STATIC_MINUTES)->EnableWindow(fActive);
  753. }
  754. void
  755. CScopePropAdvanced::ActivateLeaseSelection
  756. (
  757. BOOL fActive
  758. )
  759. {
  760. BOOL fActivateDuration = FALSE;
  761. if (((CButton *) GetDlgItem(IDC_RADIO_LEASE_LIMITED))->GetCheck() &&
  762. !((CButton *) GetDlgItem(IDC_RADIO_DHCP_ONLY))->GetCheck())
  763. {
  764. fActivateDuration = TRUE;
  765. }
  766. m_staticDuration.EnableWindow(fActive);
  767. GetDlgItem(IDC_RADIO_LEASE_UNLIMITED)->EnableWindow(fActive);
  768. GetDlgItem(IDC_RADIO_LEASE_LIMITED)->EnableWindow(fActive);
  769. ActivateDuration(fActivateDuration);
  770. }