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.

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