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.

800 lines
22 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: cnumber.cpp
  7. //
  8. // Contents: implementation of CConfigNumber
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "CNumber.h"
  14. #include "util.h"
  15. #include "ANumber.h"
  16. #include "DDWarn.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CConfigNumber dialog
  24. CConfigNumber::CConfigNumber(UINT nTemplateID)
  25. : CAttribute(nTemplateID ? nTemplateID : IDD),
  26. m_cMinutes(0),
  27. m_nLow(0),
  28. m_nHigh(999),
  29. m_nSave(0)
  30. {
  31. //{{AFX_DATA_INIT(CConfigNumber)
  32. m_strUnits = _T("");
  33. m_strValue = _T("");
  34. m_strStatic = _T("");
  35. m_strError = _T("");
  36. //}}AFX_DATA_INIT
  37. m_pHelpIDs = (DWORD_PTR)a181HelpIDs;
  38. m_uTemplateResID = IDD;
  39. }
  40. void CConfigNumber::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CAttribute::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CConfigNumber)
  44. DDX_Control(pDX, IDC_SPIN, m_SpinValue);
  45. DDX_Text(pDX, IDC_UNITS, m_strUnits);
  46. DDX_Text(pDX, IDC_VALUE, m_strValue);
  47. DDX_Text(pDX, IDC_HEADER,m_strStatic);
  48. DDX_Text(pDX, IDC_RANGEERROR,m_strError);
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CConfigNumber, CAttribute)
  52. //{{AFX_MSG_MAP(CConfigNumber)
  53. // ON_EN_KILLFOCUS(IDC_VALUE, OnKillFocus)
  54. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnDeltaposSpin)
  55. ON_EN_UPDATE(IDC_VALUE, OnUpdateValue)
  56. ON_BN_CLICKED(IDC_CONFIGURE,OnConfigure)
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CConfigNumber message handlers
  61. void CConfigNumber::OnDeltaposSpin( NMHDR* pNMHDR, LRESULT* pResult )
  62. {
  63. NM_UPDOWN FAR *pnmud;
  64. pnmud = (NM_UPDOWN FAR *)pNMHDR;
  65. SetModified(TRUE);
  66. if ( pnmud ) {
  67. //
  68. // get current value
  69. //
  70. long lVal = CurrentEditValue();
  71. if (SCE_FOREVER_VALUE == lVal) {
  72. if (pnmud->iDelta > 0) {
  73. if (m_cMinutes & DW_VALUE_OFF) {
  74. lVal = SCE_KERBEROS_OFF_VALUE;
  75. } else {
  76. lVal = m_nHigh;
  77. }
  78. } else {
  79. lVal = m_nLow;
  80. }
  81. } else if (SCE_KERBEROS_OFF_VALUE == lVal) {
  82. if (pnmud->iDelta < 0) {
  83. if (m_cMinutes & DW_VALUE_FOREVER) {
  84. lVal = SCE_FOREVER_VALUE;
  85. } else {
  86. lVal = m_nLow;
  87. }
  88. } else {
  89. lVal = m_nHigh;
  90. }
  91. } else {
  92. lVal -= (LONG)(m_iAccRate*pnmud->iDelta);
  93. if ( lVal > m_nHigh ) {
  94. // if it is overflow, go back to low
  95. if ( m_cMinutes & DW_VALUE_OFF ) {
  96. lVal = SCE_KERBEROS_OFF_VALUE;
  97. } else if (m_cMinutes & DW_VALUE_FOREVER) {
  98. lVal = SCE_FOREVER_VALUE;
  99. } else {
  100. lVal = m_nLow;
  101. }
  102. } else if ( (lVal < m_nLow) &&
  103. ((lVal != SCE_KERBEROS_OFF_VALUE) || !(m_cMinutes & DW_VALUE_OFF)) &&
  104. ((lVal != SCE_FOREVER_VALUE) || !(m_cMinutes & DW_VALUE_FOREVER))) {
  105. // if it is underflow, go back to high
  106. if ( (m_cMinutes & DW_VALUE_FOREVER) && (lVal != SCE_FOREVER_VALUE)) {
  107. lVal = SCE_FOREVER_VALUE;
  108. } else if ((m_cMinutes & DW_VALUE_OFF) && (lVal != SCE_KERBEROS_OFF_VALUE)) {
  109. lVal = SCE_KERBEROS_OFF_VALUE;
  110. } else {
  111. lVal = m_nHigh;
  112. }
  113. }
  114. if ( 0 == lVal && (m_cMinutes & DW_VALUE_NOZERO) ) {
  115. // zero is not allowed
  116. if ( m_nLow > 0 ) {
  117. lVal = m_nLow;
  118. } else {
  119. lVal = 1;
  120. }
  121. }
  122. }
  123. SetValueToEdit(lVal);
  124. }
  125. *pResult = 0;
  126. }
  127. void CConfigNumber::OnKillFocus()
  128. {
  129. LONG lVal = CurrentEditValue();
  130. SetValueToEdit(lVal);
  131. }
  132. void CConfigNumber::SetValueToEdit(LONG lVal)
  133. {
  134. CString strNew;
  135. SetModified(TRUE);
  136. if ( m_iStaticId )
  137. m_strStatic.LoadString(m_iStaticId);
  138. else
  139. m_strStatic = _T("");
  140. if ( 0 == lVal ) {
  141. strNew.Format(TEXT("%d"),lVal);
  142. if ( m_cMinutes & DW_VALUE_NEVER &&
  143. m_iNeverId > 0 ) {
  144. // change to never
  145. m_strStatic.LoadString(m_iNeverId);
  146. }
  147. } else if ( SCE_FOREVER_VALUE == lVal ) {
  148. strNew.LoadString(IDS_FOREVER);
  149. if ( m_iNeverId ) {
  150. m_strStatic.LoadString(m_iNeverId);
  151. }
  152. } else if (SCE_KERBEROS_OFF_VALUE == lVal) {
  153. strNew.LoadString(IDS_OFF);
  154. if ( m_iNeverId ) {
  155. m_strStatic.LoadString(m_iNeverId);
  156. }
  157. } else {
  158. strNew.Format(TEXT("%d"),lVal);
  159. }
  160. m_nSave = lVal;
  161. SetDlgItemText(IDC_VALUE,strNew);
  162. SetDlgItemText(IDC_HEADER,m_strStatic);
  163. }
  164. LONG CConfigNumber::CurrentEditValue()
  165. {
  166. UINT uiVal = 0;
  167. LONG lVal = 0;
  168. BOOL bTrans = FALSE;
  169. int length = m_strValue.GetLength();
  170. while( lVal < length && m_strValue.GetAt(lVal) == L'0' ) //Raid #463904, Yang Gao, 9/6/2001.
  171. {
  172. lVal++;
  173. }
  174. if( lVal > 0 && lVal < length )
  175. {
  176. m_strValue.Delete(0, lVal);
  177. SetDlgItemText(IDC_VALUE, m_strValue);
  178. }
  179. uiVal = GetDlgItemInt(IDC_VALUE,&bTrans,TRUE);
  180. lVal = uiVal;
  181. if ( !bTrans ) {
  182. CString str;
  183. if (m_cMinutes & DW_VALUE_FOREVER) {
  184. str.LoadString(IDS_FOREVER);
  185. if (str == m_strValue) {
  186. return SCE_FOREVER_VALUE;
  187. }
  188. }
  189. lVal = _ttol((LPCTSTR)m_strValue);
  190. if ( lVal == 0 ) {
  191. // nonnumeric
  192. lVal = (LONG) m_nSave;
  193. return lVal;
  194. }
  195. }
  196. if ( m_iAccRate > 1 && lVal > 0 ) {
  197. // for log max size, make it multiples of m_iAccRate
  198. int nCount = lVal % m_iAccRate;
  199. if ( nCount > 0 ) {
  200. lVal = ((LONG)(lVal/m_iAccRate))*m_iAccRate;
  201. }
  202. }
  203. if ( lVal > m_nHigh ) {
  204. // if it is overflow, go back to low
  205. if ( m_cMinutes & DW_VALUE_FOREVER ) {
  206. lVal = SCE_FOREVER_VALUE;
  207. } else if (m_cMinutes & DW_VALUE_OFF) {
  208. lVal = SCE_KERBEROS_OFF_VALUE;
  209. } else {
  210. // Leave alone and let the OnKillActive catch it
  211. }
  212. }
  213. if ( (lVal < m_nLow) &&
  214. (lVal != SCE_KERBEROS_OFF_VALUE) &&
  215. (lVal != SCE_FOREVER_VALUE) ) {
  216. // if it is underflow, go back to high
  217. if (m_cMinutes & DW_VALUE_OFF) {
  218. lVal = SCE_KERBEROS_OFF_VALUE;
  219. } else if ( m_cMinutes & DW_VALUE_FOREVER) {
  220. lVal = SCE_FOREVER_VALUE;
  221. } else {
  222. // Leave alone and let the OnKillActive catch it
  223. }
  224. }
  225. if ( 0 == lVal && (m_cMinutes & DW_VALUE_NOZERO) ) {
  226. // zero is not allowed
  227. if ( m_nLow > 0 ) {
  228. lVal = m_nLow;
  229. } else {
  230. lVal = 1;
  231. }
  232. }
  233. return lVal;
  234. }
  235. void CConfigNumber::OnConfigure()
  236. {
  237. UpdateData(TRUE);
  238. CAttribute::OnConfigure();
  239. CWnd* cwnd = GetDlgItem(IDOK);
  240. if(cwnd)
  241. {
  242. if(!m_bConfigure)
  243. cwnd->EnableWindow(TRUE);
  244. else
  245. OnUpdateValue();
  246. }
  247. }
  248. BOOL CConfigNumber::OnInitDialog()
  249. {
  250. CAttribute::OnInitDialog();
  251. AddUserControl(IDC_VALUE);
  252. AddUserControl(IDC_SPIN);
  253. AddUserControl(IDC_UNITS);
  254. UpdateData(TRUE);
  255. OnConfigure();
  256. return TRUE; // return TRUE unless you set the focus to a control
  257. // EXCEPTION: OCX Property Pages should return FALSE
  258. }
  259. BOOL CConfigNumber::OnApply()
  260. {
  261. if ( !m_bReadOnly )
  262. {
  263. BOOL bSet = FALSE;
  264. LONG_PTR dw = 0;
  265. CString strForever;
  266. CString strOff;
  267. UpdateData(TRUE);
  268. if (!m_bConfigure)
  269. dw = (LONG_PTR)ULongToPtr(SCE_NO_VALUE);
  270. else
  271. dw = CurrentEditValue();
  272. CEditTemplate *petSave = m_pData->GetBaseProfile();
  273. //Raid #715992, yanggao, 10/17/2002.
  274. //for compitability with template that has SCE_FOREVER_VALUE value.
  275. if( SCE_NO_VALUE == dw && SCE_FOREVER_VALUE == m_pData->GetBase()
  276. && IDS_KERBEROS_RENEWAL == m_pData->GetID() )
  277. {
  278. dw = SCE_FOREVER_VALUE;
  279. }
  280. //
  281. // Check dependecies for this item.
  282. //
  283. if( IDS_KERBEROS_RENEWAL != m_pData->GetID() )
  284. {
  285. if(DDWarn.CheckDependencies((DWORD)dw) == ERROR_MORE_DATA )
  286. {
  287. //
  288. // If it fails and the user presses cancel then we will exit and do nothing.
  289. //
  290. CThemeContextActivator activator;
  291. if( DDWarn.DoModal() != IDOK)
  292. return FALSE;
  293. //
  294. // If the user presses autoset then we set the item and update the result panes.
  295. //
  296. for(int i = 0; i < DDWarn.GetFailedCount(); i++)
  297. {
  298. PDEPENDENCYFAILED pItem = DDWarn.GetFailedInfo(i);
  299. if(pItem && pItem->pResult )
  300. {
  301. pItem->pResult->SetBase( pItem->dwSuggested );
  302. SetProfileInfo(
  303. pItem->pResult->GetID(),
  304. pItem->dwSuggested,
  305. pItem->pResult->GetBaseProfile());
  306. pItem->pResult->Update(m_pSnapin, FALSE);
  307. }
  308. }
  309. }
  310. }
  311. //
  312. // Update this items profile.
  313. //
  314. m_pData->SetBase(dw);
  315. SetProfileInfo(m_pData->GetID(),dw,m_pData->GetBaseProfile());
  316. m_pData->Update(m_pSnapin, false);
  317. if( m_bConfigure ) //Raid #460370, Yang Gao, 8/22/2001
  318. {
  319. LPTSTR pszAlloc = NULL; //Raid #402030
  320. m_pData->GetBaseNoUnit(pszAlloc);
  321. if(pszAlloc)
  322. {
  323. SetDlgItemText(IDC_VALUE,pszAlloc);
  324. delete [] pszAlloc;
  325. }
  326. }
  327. }
  328. return CAttribute::OnApply();
  329. }
  330. void CConfigNumber::Initialize(CResult * pResult)
  331. {
  332. LONG_PTR dw=0;
  333. CAttribute::Initialize(pResult);
  334. m_strUnits = pResult->GetUnits();
  335. DDWarn.InitializeDependencies(m_pSnapin,pResult);
  336. m_cMinutes = DW_VALUE_NOZERO;
  337. m_nLow = 0;
  338. m_nHigh = 999;
  339. m_nSave = 0;
  340. m_iNeverId = 0;
  341. m_iAccRate = 1;
  342. m_iStaticId = 0;
  343. m_fZero = FALSE; //Raid 482866, Yanggao, 10/25/2001, make sure zero is a useful value.
  344. BOOL fZerocompatible = FALSE;
  345. CEditTemplate *pTemplate = pResult->GetBaseProfile();
  346. switch (pResult->GetID())
  347. {
  348. // below no zero value
  349. case IDS_LOCK_DURATION:
  350. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO;
  351. m_nHigh = 99999;
  352. m_iStaticId = IDS_DURATION;
  353. m_iNeverId = IDS_LOCKOUT_FOREVER;
  354. break;
  355. case IDS_MIN_PAS_AGE:
  356. m_cMinutes = DW_VALUE_NEVER;
  357. m_iNeverId = IDS_CHANGE_IMMEDIATELY;
  358. m_iStaticId = IDS_PASSWORD_CHANGE;
  359. m_nHigh = 998;
  360. break;
  361. case IDS_MAX_PAS_AGE:
  362. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO;
  363. m_iStaticId = IDS_PASSWORD_EXPIRE;
  364. m_iNeverId = IDS_PASSWORD_FOREVER;
  365. break;
  366. // below zero value means differently
  367. case IDS_LOCK_COUNT:
  368. m_cMinutes = DW_VALUE_NEVER;
  369. m_iNeverId = IDS_NO_LOCKOUT;
  370. m_iStaticId = IDS_LOCKOUT_AFTER;
  371. break;
  372. case IDS_MIN_PAS_LEN:
  373. m_cMinutes = DW_VALUE_NEVER;
  374. m_nHigh = 14;
  375. m_iNeverId = IDS_PERMIT_BLANK;
  376. m_iStaticId = IDS_PASSWORD_LEN;
  377. break;
  378. case IDS_PAS_UNIQUENESS:
  379. m_cMinutes = DW_VALUE_NEVER;
  380. m_nHigh = 24;
  381. m_iNeverId = IDS_NO_HISTORY;
  382. m_iStaticId = IDS_PASSWORD_REMEMBER;
  383. break;
  384. // below there is no zero values
  385. case IDS_LOCK_RESET_COUNT:
  386. m_nLow = 1;
  387. m_nHigh = 99999;
  388. m_iStaticId = IDS_RESET_COUNT; //Raid #489966, yanggao, new static string.
  389. break;
  390. case IDS_SYS_LOG_MAX:
  391. case IDS_SEC_LOG_MAX:
  392. case IDS_APP_LOG_MAX:
  393. m_nLow = 64;
  394. m_nHigh = 4194240;
  395. m_iAccRate = 64;
  396. // no static text
  397. break;
  398. case IDS_SYS_LOG_DAYS:
  399. case IDS_SEC_LOG_DAYS:
  400. case IDS_APP_LOG_DAYS:
  401. m_nHigh = 365;
  402. m_nLow = 1;
  403. m_iStaticId = IDS_OVERWRITE_EVENT;
  404. break;
  405. case IDS_KERBEROS_MAX_AGE:
  406. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO;
  407. m_iStaticId = IDS_TICKET_EXPIRE;
  408. m_iNeverId = IDS_TICKET_FOREVER;
  409. m_nHigh = 99999;
  410. m_fZero = TRUE; //Raid 482866, Yanggao
  411. break;
  412. case IDS_KERBEROS_RENEWAL:
  413. m_cMinutes = DW_VALUE_FOREVER;
  414. m_iStaticId = IDS_TICKET_RENEWAL_EXPIRE;
  415. m_iNeverId = IDS_TICKET_RENEWAL_FOREVER;
  416. m_nHigh = 99999;
  417. m_fZero = TRUE; //Raid 482866, Yanggao
  418. break;
  419. case IDS_KERBEROS_MAX_SERVICE:
  420. m_nLow = 10;
  421. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO;
  422. m_iStaticId = IDS_TICKET_EXPIRE;
  423. m_iNeverId = IDS_TICKET_FOREVER;
  424. m_nHigh = 99999;
  425. m_fZero = TRUE; //Raid 482866, Yanggao
  426. break;
  427. case IDS_KERBEROS_MAX_CLOCK:
  428. m_cMinutes = DW_VALUE_NOZERO;
  429. m_iStaticId = IDS_MAX_TOLERANCE;
  430. m_iNeverId = IDS_NO_MAX_TOLERANCE;
  431. m_nHigh = 99999;
  432. m_nLow = 1; //Raid #678207,yanggao,9/5/2002
  433. fZerocompatible = TRUE;
  434. break;
  435. }
  436. if ((m_cMinutes & DW_VALUE_NOZERO) && (0 == m_nLow)) {
  437. m_nLow = 1;
  438. }
  439. m_strStatic = _T("");
  440. dw = pResult->GetBase();
  441. //Raid #715992, yanggao, 10/17/2002.
  442. //for compitability with template that has SCE_FOREVER_VALUE value.
  443. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) == dw ||
  444. (IDS_KERBEROS_RENEWAL == pResult->GetID() && SCE_FOREVER_VALUE == dw) )
  445. {
  446. m_bConfigure = FALSE;
  447. }
  448. else
  449. {
  450. m_bConfigure = TRUE;
  451. SetInitialValue (dw);
  452. //In order to handle existing template files with IDS_KERBEROS_MAX_CLOCK being set to "0",
  453. //UI will display them as what they are only.
  454. if( fZerocompatible && 0 == (DWORD)dw )
  455. {
  456. m_strValue.Format(TEXT("%d"),dw);
  457. m_nSave = dw;
  458. }
  459. }
  460. }
  461. void CConfigNumber::SetInitialValue(DWORD_PTR dw)
  462. {
  463. //
  464. // Don't overwrite an already set value.
  465. //
  466. if (!m_strValue.IsEmpty())
  467. {
  468. return;
  469. }
  470. //Raid 665368, yanggao, 8/9/2002.
  471. if (SCE_FOREVER_VALUE == (DWORD)dw) {
  472. // forever value
  473. m_strValue.LoadString(IDS_FOREVER);
  474. if ( (m_cMinutes & DW_VALUE_FOREVER) &&
  475. m_iNeverId > 0 ) {
  476. m_strStatic.LoadString(m_iNeverId);
  477. }
  478. m_nSave = SCE_FOREVER_VALUE;
  479. } else if (SCE_KERBEROS_OFF_VALUE == (DWORD)dw) {
  480. // off value
  481. m_strValue.LoadString(IDS_OFF);
  482. if ( (m_cMinutes & DW_VALUE_OFF) &&
  483. m_iNeverId > 0 ) {
  484. m_strStatic.LoadString(m_iNeverId);
  485. }
  486. m_nSave = SCE_KERBEROS_OFF_VALUE;
  487. } else {
  488. if ( 0 == (DWORD)dw && (m_cMinutes & DW_VALUE_NOZERO) ) {
  489. // no zero vallue is allowed
  490. if ( m_nLow > 0 ) {
  491. dw = m_nLow;
  492. } else {
  493. dw = 1;
  494. }
  495. }
  496. //Raid #652193
  497. //If this reg value is a string, it should be converted to number because this is a number dialog.
  498. RESULT_TYPES resultType = m_pData->GetType();
  499. if( ITEM_PROF_REGVALUE == resultType || ITEM_REGVALUE == resultType || ITEM_LOCALPOL_REGVALUE == resultType )
  500. {
  501. PSCE_REGISTRY_VALUE_INFO regThis = (PSCE_REGISTRY_VALUE_INFO)m_pData->GetBase();
  502. if( regThis && (regThis->ValueType == REG_MULTI_SZ || regThis->ValueType == REG_SZ ||
  503. regThis->ValueType == REG_EXPAND_SZ) )
  504. {
  505. dw = (DWORD)StrToLong((LPWSTR)dw);
  506. }
  507. }
  508. m_strValue.Format(TEXT("%d"),dw);
  509. m_nSave = dw;
  510. if ( 0 == (DWORD)dw && (m_cMinutes & DW_VALUE_NEVER) &&
  511. m_iNeverId > 0 )
  512. {
  513. // zero means different values
  514. m_strStatic.LoadString(m_iNeverId);
  515. }
  516. else if ( m_iStaticId > 0 )
  517. {
  518. if( IDS_KERBEROS_RENEWAL == m_pData->GetID() && 0 == dw && m_iNeverId > 0 ) //Raid #730485, 12/18/2002.
  519. {
  520. m_strStatic.LoadString(m_iNeverId);
  521. }
  522. else
  523. {
  524. m_strStatic.LoadString(m_iStaticId);
  525. }
  526. }
  527. }
  528. }
  529. void CConfigNumber::OnUpdateValue()
  530. {
  531. DWORD dwRes = 0;
  532. UpdateData(TRUE);
  533. SetModified(TRUE);
  534. CString sNum;
  535. CEdit *pEdit = (CEdit *)GetDlgItem(IDC_VALUE);
  536. CWnd *pOK = GetDlgItem(IDOK);
  537. DWORD dwValue = _ttoi(m_strValue);
  538. //
  539. // Don't do anything if the string is equal to predefined strings.
  540. //
  541. sNum.LoadString(IDS_FOREVER);
  542. if (m_strValue.IsEmpty()) {
  543. if (pOK) {
  544. pOK->EnableWindow(FALSE);
  545. }
  546. } else if(m_strValue == sNum){
  547. if(pOK && !QueryReadOnly()){
  548. pOK->EnableWindow(TRUE);
  549. }
  550. } else {
  551. if((LONG)dwValue < m_nLow){
  552. //
  553. // Disable the OK button.
  554. //
  555. if( pOK ){
  556. pOK->EnableWindow(FALSE);
  557. }
  558. if(pEdit){
  559. //
  560. // We will only force a select if edit text length >=
  561. // minimum text length
  562. //
  563. sNum.Format(TEXT("%d"), m_nLow);
  564. dwValue = m_nLow;
  565. if(sNum.GetLength() < m_strValue.GetLength()){
  566. pEdit->SetSel(0, -1);
  567. }
  568. }
  569. } else if( (LONG)dwValue > m_nHigh ) {
  570. if(!QueryReadOnly() && pOK){
  571. pOK->EnableWindow(TRUE);
  572. }
  573. if(pEdit){
  574. if(m_cMinutes & DW_VALUE_FOREVER){
  575. sNum.LoadString(IDS_FOREVER);
  576. dwValue = 0;
  577. } else {
  578. sNum.Format(TEXT("%d"), m_nHigh);
  579. dwValue = m_nHigh;
  580. }
  581. m_strValue = sNum;
  582. UpdateData(FALSE);
  583. pEdit->SetSel(0, -1);
  584. }
  585. } else if(!QueryReadOnly() && pOK){
  586. //
  587. // Enable the OK button.
  588. //
  589. if (pOK) {
  590. pOK->EnableWindow(TRUE);
  591. }
  592. }
  593. }
  594. //
  595. // Load the description for this string.
  596. //
  597. if ((dwValue <= 0) && (m_iNeverId != 0)) {
  598. m_strStatic.LoadString(m_iNeverId);
  599. } else {
  600. m_strStatic.LoadString(m_iStaticId);
  601. }
  602. GetDlgItem(IDC_HEADER)->SetWindowText(m_strStatic);
  603. }
  604. BOOL CConfigNumber::OnKillActive()
  605. {
  606. UINT uiVal = 0;
  607. LONG lVal = 0;
  608. BOOL bTrans = FALSE;
  609. CString strRange;
  610. int lMin = m_nLow;
  611. UpdateData(TRUE);
  612. if (!m_bConfigure)
  613. {
  614. return TRUE;
  615. }
  616. if ((m_cMinutes & DW_VALUE_NOZERO) &&
  617. !(m_cMinutes & DW_VALUE_FOREVER) &&
  618. lMin == 0)
  619. {
  620. lMin = 1;
  621. }
  622. CString strFormat;
  623. strFormat.LoadString(IDS_RANGE);
  624. strRange.Format(strFormat,lMin,m_nHigh);
  625. int length = m_strValue.GetLength();
  626. while( lVal < length && m_strValue.GetAt(lVal) == L'0' ) //Raid #463904, Yang Gao, 9/6/2001.
  627. {
  628. lVal++;
  629. }
  630. if( lVal > 0 && lVal < length )
  631. {
  632. m_strValue.Delete(0, lVal);
  633. SetDlgItemText(IDC_VALUE, m_strValue);
  634. }
  635. uiVal = GetDlgItemInt(IDC_VALUE, &bTrans, TRUE);
  636. lVal = uiVal;
  637. if (!bTrans) //invalid numeric string, Raid #529933, yanggao
  638. {
  639. CString str;
  640. if (m_cMinutes & DW_VALUE_FOREVER)
  641. {
  642. str.LoadString(IDS_FOREVER);
  643. if (str == m_strValue)
  644. {
  645. return TRUE;
  646. }
  647. }
  648. // nonnumeric
  649. lVal = (LONG) m_nSave;
  650. if( m_fZero ) //Raid 482866, Yanggao, 10/25/2001
  651. {
  652. strFormat.LoadString(IDS_ADDITIONAL_RANGE);
  653. strRange.Format(strFormat,lMin,m_nHigh);
  654. m_strError = strRange;
  655. }
  656. m_strError = strRange;
  657. UpdateData(FALSE);
  658. return FALSE;
  659. }
  660. if (m_iAccRate > 1 && lVal > 0)
  661. {
  662. // for log max size, make it multiples of m_iAccRate
  663. int nCount = lVal % m_iAccRate;
  664. if ( nCount > 0 )
  665. {
  666. lVal = ((LONG)(lVal/m_iAccRate))*m_iAccRate;
  667. }
  668. }
  669. if (lVal > m_nHigh)
  670. {
  671. m_strError = strRange;
  672. UpdateData(FALSE);
  673. return FALSE;
  674. }
  675. if ((lVal < m_nLow) &&
  676. (lVal != SCE_KERBEROS_OFF_VALUE) &&
  677. (lVal != SCE_FOREVER_VALUE))
  678. {
  679. // if it is underflow, go back to high
  680. if (m_cMinutes & DW_VALUE_OFF)
  681. {
  682. lVal = SCE_KERBEROS_OFF_VALUE;
  683. }
  684. else if (m_cMinutes & DW_VALUE_FOREVER)
  685. {
  686. lVal = SCE_FOREVER_VALUE;
  687. }
  688. else
  689. {
  690. // Leave alone and let the OnKillActive catch it
  691. }
  692. }
  693. if ((lVal < m_nLow) &&
  694. (lVal != SCE_KERBEROS_OFF_VALUE) &&
  695. (lVal != SCE_FOREVER_VALUE))
  696. {
  697. // if it is underflow, go back to high
  698. m_strError = strRange;
  699. UpdateData(FALSE);
  700. return FALSE;
  701. }
  702. if (0 == lVal && (m_cMinutes & DW_VALUE_NOZERO))
  703. {
  704. // zero is not allowed
  705. m_strError = strRange;
  706. UpdateData(FALSE);
  707. return FALSE;
  708. }
  709. return CAttribute::OnKillActive();
  710. }