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.

1068 lines
24 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. #include "stdafx.h"
  3. #include <prsht.h>
  4. #include "todlg.h"
  5. #include "resource.h"
  6. TOKTABLE tokday[ 4 ] = {
  7. { NULL , IDS_D },
  8. { NULL , IDS_DAY },
  9. { NULL , IDS_DAYS },
  10. { NULL , ( DWORD )-1 }
  11. };
  12. TOKTABLE tokhour[ 6 ] = {
  13. { NULL , IDS_H },
  14. { NULL , IDS_HR },
  15. { NULL , IDS_HRS },
  16. { NULL , IDS_HOUR },
  17. { NULL , IDS_HOURS },
  18. { NULL , ( DWORD )-1 }
  19. };
  20. TOKTABLE tokmin[ 5 ] = {
  21. { NULL , IDS_M },
  22. { NULL , IDS_MIN },
  23. { NULL , IDS_MINUTE },
  24. { NULL , IDS_MINUTES },
  25. { NULL , ( DWORD )-1 }
  26. };
  27. TCHAR * GetNextToken( TCHAR *pszString , TCHAR *tchToken );
  28. //-------------------------------------------------------------------------------
  29. // CTimeOutDlg::ctor
  30. //-------------------------------------------------------------------------------
  31. CTimeOutDlg::CTimeOutDlg( )
  32. {
  33. ZeroMemory( &m_cbxst , sizeof( CBXSTATE ) * 3 );
  34. }
  35. //-------------------------------------------------------------------------------
  36. BOOL CTimeOutDlg::InitControl( HWND hCtrl )
  37. {
  38. int i = GetCBXSTATEindex( hCtrl );
  39. m_cbxst[ i ].icbxSel = ( int )SendMessage( hCtrl , CB_GETCURSEL , 0 , 0 );
  40. return TRUE;
  41. }
  42. //-------------------------------------------------------------------------------
  43. // release the parent reference
  44. //-------------------------------------------------------------------------------
  45. BOOL CTimeOutDlg::ReleaseAbbreviates( )
  46. {
  47. xxxUnLoadAbbreviate( &tokday[0] );
  48. xxxUnLoadAbbreviate( &tokhour[0] );
  49. xxxUnLoadAbbreviate( &tokmin[0] );
  50. return TRUE;
  51. }
  52. //-------------------------------------------------------------------------------
  53. // OnCommand
  54. //-------------------------------------------------------------------------------
  55. BOOL CTimeOutDlg::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtl , PBOOL pfPersisted )
  56. {
  57. UNREFERENCED_PARAMETER( wID );
  58. switch( wNotifyCode )
  59. {
  60. case CBN_EDITCHANGE:
  61. if( OnCBEditChange( hwndCtl ) )
  62. {
  63. *pfPersisted = FALSE;
  64. }
  65. break;
  66. case CBN_SELCHANGE:
  67. if( OnCBNSELCHANGE( hwndCtl ) )
  68. {
  69. *pfPersisted = FALSE;
  70. }
  71. //case BN_CLICKED:
  72. break;
  73. case CBN_DROPDOWN: // FALLTHROUGH
  74. case CBN_KILLFOCUS:
  75. OnCBDropDown( hwndCtl );
  76. break;
  77. //return FALSE;
  78. /*
  79. case ALN_APPLY:
  80. SendMessage( GetParent( hwndCtl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  81. return FALSE;
  82. */
  83. }
  84. // m_bPersisted = FALSE;
  85. /*
  86. if( bChange )
  87. {
  88. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  89. }
  90. */
  91. return FALSE;
  92. }
  93. //-------------------------------------------------------------------------------
  94. // Update the entry if it has been modified by user
  95. //-------------------------------------------------------------------------------
  96. BOOL CTimeOutDlg::OnCBDropDown( HWND hCombo )
  97. {
  98. TCHAR tchBuffer[ 80 ];
  99. ULONG ulTime;
  100. int i = GetCBXSTATEindex( hCombo );
  101. if( i < 0 )
  102. {
  103. return FALSE;
  104. }
  105. if( m_cbxst[ i ].bEdit )
  106. {
  107. GetWindowText( hCombo , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) );
  108. if( ParseDurationEntry( tchBuffer , &ulTime ) == E_SUCCESS )
  109. {
  110. InsertSortedAndSetCurSel( hCombo , ulTime );
  111. }
  112. return TRUE;
  113. }
  114. return FALSE;
  115. }
  116. //-------------------------------------------------------------------------------
  117. // Use this flag to distinguish between hand entry or listbox selection
  118. // setting it to true implies that the use has edit the cbx via typing
  119. //-------------------------------------------------------------------------------
  120. BOOL CTimeOutDlg::OnCBEditChange( HWND hCombo )
  121. {
  122. int i = GetCBXSTATEindex( hCombo );
  123. if( i > -1 )
  124. {
  125. m_cbxst[ i ].bEdit = TRUE;
  126. return TRUE;
  127. }
  128. return FALSE;
  129. }
  130. //-------------------------------------------------------------------------------
  131. // Determine if user wants to enter a custom time
  132. //-------------------------------------------------------------------------------
  133. BOOL CTimeOutDlg::OnCBNSELCHANGE( HWND hwnd )
  134. {
  135. return SaveChangedSelection( hwnd );
  136. }
  137. //-------------------------------------------------------------------------------
  138. // Saves selected item.
  139. //-------------------------------------------------------------------------------
  140. BOOL CTimeOutDlg::SaveChangedSelection( HWND hCombo )
  141. {
  142. INT_PTR idx = SendMessage( hCombo , CB_GETCURSEL , 0 , 0 );
  143. int i = GetCBXSTATEindex( hCombo );
  144. if( i > -1 )
  145. {
  146. if( m_cbxst[ i ].icbxSel != idx )
  147. {
  148. m_cbxst[ i ].icbxSel = ( int )idx;
  149. m_cbxst[ i ].bEdit = FALSE;
  150. return TRUE;
  151. }
  152. }
  153. return FALSE;
  154. }
  155. //-------------------------------------------------------------------------------
  156. // Restore previous setting
  157. //-------------------------------------------------------------------------------
  158. BOOL CTimeOutDlg::RestorePreviousValue( HWND hwnd )
  159. {
  160. int iSel;
  161. if( ( iSel = GetCBXSTATEindex( hwnd ) ) > -1 )
  162. {
  163. SendMessage( hwnd , CB_SETCURSEL , m_cbxst[ iSel ].icbxSel , 0 );
  164. return TRUE;
  165. }
  166. return FALSE;
  167. }
  168. //-------------------------------------------------------------------------------
  169. // ConvertToMinutes -- helper for CTimeOutDlg::OnNotify
  170. //-------------------------------------------------------------------------------
  171. BOOL CTimeOutDlg::ConvertToMinutes( HWND hwndCtl , PULONG pulMinutes )
  172. {
  173. TCHAR tchBuffer[ 80 ];
  174. TCHAR tchErrTitle[ 80 ];
  175. TCHAR tchErrMsg[ 256 ];
  176. TCHAR tchSetting[ 80 ];
  177. int idx = GetCBXSTATEindex( hwndCtl );
  178. if( idx < 0 )
  179. {
  180. return FALSE;
  181. }
  182. ASSERT( idx <= 2 );
  183. int resID = -1;
  184. if( idx == 0 )
  185. {
  186. resID = IDS_COMBO_CONNECTION;
  187. }
  188. else if( idx == 1 )
  189. {
  190. resID = IDS_COMBO_DISCONNECTION;
  191. }
  192. else if( idx == 2 )
  193. {
  194. resID = IDS_COMBO_IDLECONNECTION;
  195. }
  196. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , resID , tchSetting , SIZE_OF_BUFFER( tchSetting ) ) );
  197. ULONG_PTR dw = ( ULONG_PTR )&tchSetting[ 0 ];
  198. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TITLE , tchErrTitle , SIZE_OF_BUFFER( tchErrTitle ) ) );
  199. if( m_cbxst[ idx ].bEdit )
  200. {
  201. DBGMSG( L"Automatic %s parsing\n" , tchSetting );
  202. if( GetWindowText( hwndCtl , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) ) < 1 )
  203. {
  204. *pulMinutes = 0;
  205. return TRUE;
  206. }
  207. LRESULT lr = ParseDurationEntry( tchBuffer , pulMinutes );
  208. if( lr != E_SUCCESS )
  209. {
  210. if( lr == E_PARSE_VALUEOVERFLOW )
  211. {
  212. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TOOMANYDIGITS , tchErrMsg , SIZE_OF_BUFFER( tchErrMsg ) );
  213. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, tchErrMsg , 0 , 0 , tchErrMsg , SIZE_OF_BUFFER( tchErrMsg ) , ( va_list * )&dw );
  214. MessageBox( hwndCtl , tchErrMsg , tchErrTitle , MB_OK | MB_ICONERROR );
  215. SetFocus( hwndCtl );
  216. }
  217. else if( lr == E_PARSE_MISSING_DIGITS || lr == E_PARSE_INVALID )
  218. {
  219. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_PARSEINVALID , tchErrMsg , SIZE_OF_BUFFER( tchErrMsg ) );
  220. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, tchErrMsg , 0 , 0 , tchErrMsg , SIZE_OF_BUFFER( tchErrMsg ) , ( va_list * )&dw );
  221. MessageBox( hwndCtl , tchErrMsg , tchErrTitle , MB_OK | MB_ICONERROR );
  222. SetFocus( hwndCtl );
  223. }
  224. return FALSE;
  225. }
  226. }
  227. else
  228. {
  229. ODS( L"Getting current selection\n" );
  230. INT_PTR iCurSel = SendMessage( hwndCtl , CB_GETCURSEL , 0 , 0 );
  231. // See if user wants "No Timeout"
  232. if( iCurSel == 0 )
  233. {
  234. *pulMinutes = 0;
  235. return TRUE;
  236. }
  237. if( ( *pulMinutes = ( ULONG )SendMessage( hwndCtl , CB_GETITEMDATA , iCurSel , 0 ) ) == CB_ERR )
  238. {
  239. *pulMinutes = 0;
  240. }
  241. }
  242. if( *pulMinutes > kMaxTimeoutMinute )
  243. {
  244. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_MAXVALEXCEEDED , tchErrMsg , SIZE_OF_BUFFER( tchErrMsg ) );
  245. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, tchErrMsg , 0 , 0 , tchErrMsg , SIZE_OF_BUFFER( tchErrMsg ) , ( va_list * )&dw );
  246. MessageBox( hwndCtl , tchErrMsg , tchErrTitle , MB_OK | MB_ICONERROR );
  247. SetFocus( hwndCtl );
  248. return FALSE;
  249. }
  250. *pulMinutes *= kMilliMinute;
  251. return TRUE;
  252. }
  253. #if 0
  254. //-------------------------------------------------------------------------------
  255. // Lets cut to the chase and find out if this is even worth parsing
  256. //-------------------------------------------------------------------------------
  257. BOOL CTimeOutDlg::DoesContainDigits( LPTSTR pszString )
  258. {
  259. while( *pszString )
  260. {
  261. if( iswdigit( *pszString ) )
  262. {
  263. return TRUE;
  264. }
  265. pszString++;
  266. }
  267. return FALSE;
  268. }
  269. //-------------------------------------------------------------------------------
  270. LRESULT CTimeOutDlg::ParseDurationEntry( LPTSTR pszTime , PULONG pTime )
  271. {
  272. TCHAR tchNoTimeout[ 80 ];
  273. LPTSTR pszTemp = pszTime;
  274. UINT uDec = 0;
  275. float fFrac = 0.0f;
  276. float fT;
  277. UINT uPos = 1;
  278. LoadString( _Module.GetResourceInstance( ) , IDS_NOTIMEOUT , tchNoTimeout , SIZE_OF_BUFFER( tchNoTimeout ) );
  279. if( lstrcmpi( pszTime , tchNoTimeout ) == 0 )
  280. {
  281. *pTime = 0;
  282. return E_SUCCESS;
  283. }
  284. if( !DoesContainDigits( pszTime ) )
  285. {
  286. return E_PARSE_MISSING_DIGITS;
  287. }
  288. while( *pszTemp )
  289. {
  290. if( !iswdigit( *pszTemp ) )
  291. {
  292. break;
  293. }
  294. // check for overflow
  295. if( uDec >= 1000000000 )
  296. {
  297. return E_PARSE_VALUEOVERFLOW ;
  298. }
  299. uDec *= 10;
  300. uDec += ( *pszTemp - '0' );
  301. pszTemp++;
  302. }
  303. TCHAR tchSDecimal[ 5 ];
  304. GetLocaleInfo( LOCALE_USER_DEFAULT , LOCALE_SDECIMAL , tchSDecimal , SIZE_OF_BUFFER( tchSDecimal ) );
  305. if( *pszTemp == *tchSDecimal )
  306. {
  307. pszTemp++;
  308. while( *pszTemp )
  309. {
  310. if( !iswdigit( *pszTemp ) )
  311. {
  312. break;
  313. }
  314. // check for overflow
  315. if( uDec >= 1000000000 )
  316. {
  317. return E_PARSE_VALUEOVERFLOW;
  318. }
  319. uPos *= 10;
  320. fFrac += ( float )( *pszTemp - '0' ) / ( float )uPos;
  321. pszTemp++;
  322. }
  323. }
  324. // remove white space
  325. while( *pszTemp == L' ' )
  326. {
  327. pszTemp++;
  328. }
  329. if( *pszTemp != NULL )
  330. {
  331. if( IsToken( pszTemp , TOKEN_DAY ) )
  332. {
  333. *pTime = uDec * 24 * 60;
  334. fT = ( fFrac * 24.0f * 60.0f + 0.5f );
  335. *pTime += ( ULONG )fT;
  336. return E_SUCCESS;
  337. }
  338. else if( IsToken( pszTemp , TOKEN_HOUR ) )
  339. {
  340. *pTime = uDec * 60;
  341. fT = ( fFrac * 60.0f + 0.5f );
  342. *pTime += ( ULONG )fT;
  343. return E_SUCCESS;
  344. }
  345. else if( IsToken( pszTemp , TOKEN_MINUTE ) )
  346. {
  347. // minutes are rounded up in the 1/10 place
  348. fT = fFrac + 0.5f;
  349. *pTime = uDec;
  350. *pTime += ( ULONG )( fT );
  351. return E_SUCCESS;
  352. }
  353. }
  354. if( *pszTemp == NULL )
  355. {
  356. // if no text is defined considered the entry in hours
  357. *pTime = uDec * 60;
  358. fT = ( fFrac * 60.0f + 0.5f );
  359. *pTime += ( ULONG )fT ;
  360. return E_SUCCESS;
  361. }
  362. return E_PARSE_INVALID;
  363. }
  364. #endif
  365. //-------------------------------------------------------------------------------
  366. // Adds strings to table from resource
  367. //-------------------------------------------------------------------------------
  368. BOOL CTimeOutDlg::LoadAbbreviates( )
  369. {
  370. xxxLoadAbbreviate( &tokday[0] );
  371. xxxLoadAbbreviate( &tokhour[0] );
  372. xxxLoadAbbreviate( &tokmin[0] );
  373. return TRUE;
  374. }
  375. //-------------------------------------------------------------------------------
  376. // Take cares some repetitive work for us
  377. //-------------------------------------------------------------------------------
  378. BOOL CTimeOutDlg::xxxLoadAbbreviate( PTOKTABLE ptoktbl )
  379. {
  380. int idx;
  381. int nSize;
  382. TCHAR tchbuffer[ 80 ];
  383. if( ptoktbl == NULL )
  384. {
  385. return FALSE;
  386. }
  387. for( idx = 0; ptoktbl[ idx ].dwresourceid != ( DWORD )-1 ; ++idx )
  388. {
  389. nSize = LoadString( _Module.GetResourceInstance( ) , ptoktbl[ idx ].dwresourceid , tchbuffer , SIZE_OF_BUFFER( tchbuffer ) );
  390. if( nSize > 0 )
  391. {
  392. ptoktbl[ idx ].pszAbbrv = ( TCHAR *)new TCHAR[ nSize + 1 ];
  393. if( ptoktbl[ idx ].pszAbbrv != NULL )
  394. {
  395. lstrcpy( ptoktbl[ idx ].pszAbbrv , tchbuffer );
  396. }
  397. }
  398. }
  399. return TRUE;
  400. }
  401. //-------------------------------------------------------------------------------
  402. // Frees up allocated resources
  403. //-------------------------------------------------------------------------------
  404. BOOL CTimeOutDlg::xxxUnLoadAbbreviate( PTOKTABLE ptoktbl )
  405. {
  406. if( ptoktbl == NULL )
  407. {
  408. return FALSE;
  409. }
  410. for( int idx = 0; ptoktbl[ idx ].dwresourceid != ( DWORD )-1 ; ++idx )
  411. {
  412. if( ptoktbl[ idx ].pszAbbrv != NULL )
  413. {
  414. delete[] ptoktbl[ idx ].pszAbbrv;
  415. }
  416. }
  417. return TRUE;
  418. }
  419. //-------------------------------------------------------------------------------
  420. // tear-off token tables
  421. //-------------------------------------------------------------------------------
  422. BOOL CTimeOutDlg::IsToken( LPTSTR pszString , TOKEN tok )
  423. {
  424. TOKTABLE *ptoktable;
  425. if( tok == TOKEN_DAY )
  426. {
  427. ptoktable = &tokday[0];
  428. }
  429. else if( tok == TOKEN_HOUR )
  430. {
  431. ptoktable = &tokhour[0];
  432. }
  433. else if( tok == TOKEN_MINUTE )
  434. {
  435. ptoktable = &tokmin[0];
  436. }
  437. else
  438. {
  439. return FALSE;
  440. }
  441. for( int idx = 0 ; ptoktable[ idx ].dwresourceid != -1 ; ++idx )
  442. {
  443. if( lstrcmpi( pszString , ptoktable[ idx ].pszAbbrv ) == 0 )
  444. {
  445. return TRUE;
  446. }
  447. }
  448. return FALSE;
  449. }
  450. #if 0
  451. //-------------------------------------------------------------------------------
  452. // Converts the number minutes into a formated string
  453. //-------------------------------------------------------------------------------
  454. BOOL CTimeOutDlg::ConvertToDuration( ULONG ulTime , LPTSTR pszDuration )
  455. {
  456. ULONG_PTR dw[3];
  457. TCHAR tchTimeUnit[ 40 ];
  458. TCHAR tchTimeFormat[ 40 ];
  459. TCHAR tchOutput[ 80 ];
  460. // ASSERT( ulTime != 0 );
  461. int iHour= ulTime / 60;
  462. int iDays = iHour / 24;
  463. dw[ 2 ] = ( ULONG_PTR )&tchTimeUnit[ 0 ];
  464. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_DOT_DIGIT_TU , tchTimeFormat , SIZE_OF_BUFFER( tchTimeFormat ) );
  465. if( iDays != 0 )
  466. {
  467. int iRemainingHours = iHour % 24;
  468. float fx = ( float )iRemainingHours / 24.0f;
  469. iRemainingHours = ( int )( fx * 10 );
  470. LoadString( _Module.GetResourceInstance( ) , IDS_DAYS , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  471. dw[ 0 ] = iDays;
  472. dw[ 1 ] = iRemainingHours;
  473. if( iRemainingHours == 0 )
  474. {
  475. // formatted string requires two arguments
  476. dw[ 1 ] = ( ULONG_PTR )&tchTimeUnit[ 0 ];
  477. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_TU , tchTimeFormat , SIZE_OF_BUFFER( tchTimeFormat ) );
  478. if( iDays == 1 )
  479. {
  480. LoadString( _Module.GetResourceInstance( ) , IDS_DAY , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  481. }
  482. }
  483. }
  484. else if( iHour != 0 )
  485. {
  486. int iRemainingMinutes = ulTime % 60;
  487. float fx = ( float )iRemainingMinutes / 60.0f;
  488. iRemainingMinutes = ( int ) ( fx * 10 );
  489. dw[ 0 ] = iHour;
  490. dw[ 1 ] = iRemainingMinutes;
  491. LoadString( _Module.GetResourceInstance( ) , IDS_HOURS , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  492. if( iRemainingMinutes == 0 )
  493. {
  494. dw[ 1 ] = ( ULONG_PTR )&tchTimeUnit[ 0 ];
  495. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_TU , tchTimeFormat , SIZE_OF_BUFFER( tchTimeFormat ) );
  496. if( iHour == 1 )
  497. {
  498. LoadString( _Module.GetResourceInstance( ) , IDS_HOUR , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  499. }
  500. }
  501. }
  502. else
  503. {
  504. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTES , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  505. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_TU , tchTimeFormat , SIZE_OF_BUFFER( tchTimeFormat ) );
  506. dw[ 0 ] = ulTime ;
  507. dw[ 1 ] = ( ULONG_PTR )&tchTimeUnit[ 0 ];
  508. if( ulTime > 1 )
  509. {
  510. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTES , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  511. }
  512. else
  513. {
  514. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTE , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  515. }
  516. }
  517. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, tchTimeFormat , 0 , 0 , tchOutput , SIZE_OF_BUFFER( tchOutput ) , ( va_list * )&dw );
  518. lstrcpy( pszDuration , tchOutput );
  519. return TRUE;
  520. }
  521. #endif
  522. //-------------------------------------------------------------------------------
  523. // Place entry in listbox and set as current selection
  524. //-------------------------------------------------------------------------------
  525. BOOL CTimeOutDlg::InsertSortedAndSetCurSel( HWND hCombo , DWORD dwMinutes )
  526. {
  527. // ASSERT( dwMinutes != ( DWORD )-1 );
  528. TCHAR tchBuffer[ 80 ];
  529. INT_PTR iCount = SendMessage( hCombo , CB_GETCOUNT , 0 , 0 );
  530. for( INT_PTR idx = 0 ; idx < iCount ; ++idx )
  531. {
  532. // Don't insert an item that's already in the list
  533. if( dwMinutes == ( DWORD )SendMessage( hCombo , CB_GETITEMDATA , idx , 0 ) )
  534. {
  535. SendMessage( hCombo , CB_SETCURSEL , idx , 0 ) ;
  536. return TRUE;
  537. }
  538. if( dwMinutes < ( DWORD )SendMessage( hCombo , CB_GETITEMDATA , idx , 0 ) )
  539. {
  540. break;
  541. }
  542. }
  543. // hey if the value has exceeded the max timeout don't bother entering it in our list
  544. if( dwMinutes > kMaxTimeoutMinute )
  545. {
  546. return FALSE;
  547. }
  548. if( ConvertToDuration ( dwMinutes , tchBuffer ) )
  549. {
  550. idx = SendMessage( hCombo , CB_INSERTSTRING , idx , ( LPARAM )&tchBuffer[ 0 ] );
  551. if( idx != CB_ERR )
  552. {
  553. SendMessage( hCombo , CB_SETITEMDATA , idx , dwMinutes );
  554. }
  555. SendMessage( hCombo , CB_SETCURSEL , idx , 0 ) ;
  556. }
  557. // must call this here because CB_SETCURSEL does not send CBN_SELCHANGE
  558. SaveChangedSelection( hCombo );
  559. return TRUE;
  560. }
  561. /* Modified settings for a more readable time out settings
  562. * added 1/25/99
  563. * alhen
  564. */
  565. //-------------------------------------------------------------------------------
  566. // Removing decimal entries
  567. //-------------------------------------------------------------------------------
  568. LRESULT CTimeOutDlg::ParseDurationEntry( LPTSTR pszTime , PULONG pTime )
  569. {
  570. TCHAR tchNoTimeout[ 80 ];
  571. LPTSTR pszTemp = pszTime;
  572. UINT uDec = 0;
  573. BOOL bSetDay = FALSE;
  574. BOOL bSetHour = FALSE;
  575. BOOL bSetMin = FALSE;
  576. BOOL bEOL = FALSE;
  577. BOOL bHasDigit= FALSE;
  578. *pTime = 0;
  579. LoadString( _Module.GetResourceInstance( ) , IDS_NOTIMEOUT , tchNoTimeout , SIZE_OF_BUFFER( tchNoTimeout ) );
  580. if( lstrcmpi( pszTime , tchNoTimeout ) == 0 )
  581. {
  582. // *pTime = 0;
  583. return E_SUCCESS;
  584. }
  585. while( !bEOL )
  586. {
  587. // remove leading white spaces
  588. while( *pszTemp == L' ' )
  589. {
  590. pszTemp++;
  591. }
  592. while( *pszTemp )
  593. {
  594. if( !iswdigit( *pszTemp ) )
  595. {
  596. if( !bHasDigit )
  597. {
  598. return E_PARSE_MISSING_DIGITS;
  599. }
  600. break;
  601. }
  602. // check for overflow
  603. if( uDec >= 1000000000 )
  604. {
  605. return E_PARSE_VALUEOVERFLOW ;
  606. }
  607. uDec *= 10;
  608. uDec += ( *pszTemp - '0' );
  609. if( !bHasDigit )
  610. {
  611. bHasDigit = TRUE;
  612. }
  613. pszTemp++;
  614. }
  615. // remove intermediate white spaces
  616. while( *pszTemp == L' ' )
  617. {
  618. pszTemp++;
  619. }
  620. if( *pszTemp != NULL )
  621. {
  622. // Get next token
  623. TCHAR tchToken[ 80 ];
  624. pszTemp = GetNextToken( pszTemp , tchToken );
  625. if( IsToken( tchToken , TOKEN_DAY ) )
  626. {
  627. if( !bSetDay )
  628. {
  629. *pTime += uDec * 1440;
  630. bSetDay = TRUE;
  631. }
  632. }
  633. else if( IsToken( tchToken , TOKEN_HOUR ) )
  634. {
  635. if( !bSetHour )
  636. {
  637. *pTime += uDec * 60;
  638. bSetHour = TRUE;
  639. }
  640. }
  641. else if( IsToken( tchToken , TOKEN_MINUTE ) )
  642. {
  643. if( !bSetMin )
  644. {
  645. *pTime += uDec;
  646. bSetMin = TRUE;
  647. }
  648. }
  649. else
  650. {
  651. return E_PARSE_INVALID;
  652. }
  653. }
  654. else
  655. {
  656. if( !bSetHour )
  657. {
  658. *pTime += uDec * 60;
  659. }
  660. bEOL = TRUE;
  661. }
  662. uDec = 0;
  663. bHasDigit = FALSE;
  664. }
  665. return E_SUCCESS;
  666. }
  667. //-------------------------------------------------------------------------------
  668. // replacing older api
  669. //-------------------------------------------------------------------------------
  670. BOOL CTimeOutDlg::ConvertToDuration( ULONG ulTime , LPTSTR pszDuration )
  671. {
  672. // TCHAR dw[] = L"dhm";
  673. TCHAR tchTimeUnit[ 40 ];
  674. TCHAR tchTimeFormat[ 40 ];
  675. TCHAR tchOutput[ 80 ];
  676. ASSERT( ulTime != 0 );
  677. int iHour = ( ulTime / 60 );
  678. int iDays = iHour / 24;
  679. int iMinute = ulTime % 60;
  680. // Resolve format
  681. tchOutput[0] = 0;
  682. if( iDays > 0 )
  683. {
  684. if( iDays == 1 )
  685. {
  686. LoadString( _Module.GetResourceInstance( ) , IDS_DAY , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  687. }
  688. else
  689. {
  690. LoadString( _Module.GetResourceInstance( ) , IDS_DAYS , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  691. }
  692. iHour = iHour % 24;
  693. wsprintf( tchTimeFormat , L"%d %s", iDays , tchTimeUnit );
  694. lstrcat( tchOutput , tchTimeFormat );
  695. lstrcat( tchOutput , L" " );
  696. }
  697. if( iHour > 0 )
  698. {
  699. if( iHour == 1 )
  700. {
  701. LoadString( _Module.GetResourceInstance( ) , IDS_HOUR , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  702. }
  703. else
  704. {
  705. LoadString( _Module.GetResourceInstance( ) , IDS_HOURS , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  706. }
  707. wsprintf( tchTimeFormat , L"%d %s", iHour , tchTimeUnit );
  708. lstrcat( tchOutput , tchTimeFormat );
  709. lstrcat( tchOutput , L" " );
  710. }
  711. if( iMinute > 0 )
  712. {
  713. if( iMinute == 1 )
  714. {
  715. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTE , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  716. }
  717. else
  718. {
  719. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTES , tchTimeUnit , SIZE_OF_BUFFER( tchTimeUnit ) );
  720. }
  721. wsprintf( tchTimeFormat , L"%d %s", iMinute , tchTimeUnit );
  722. lstrcat( tchOutput , tchTimeFormat );
  723. lstrcat( tchOutput , L" " );
  724. }
  725. lstrcpy( pszDuration , tchOutput );
  726. return TRUE;
  727. }
  728. //-------------------------------------------------------------------------------
  729. BOOL CTimeOutDlg::DoesContainDigits( LPTSTR pszString )
  730. {
  731. while( *pszString )
  732. {
  733. if( *pszString != L' ')
  734. {
  735. if( iswdigit( *pszString ) )
  736. {
  737. return TRUE;
  738. }
  739. else
  740. {
  741. return FALSE;
  742. }
  743. pszString++;
  744. }
  745. }
  746. return FALSE;
  747. }
  748. //-------------------------------------------------------------------------------
  749. TCHAR * GetNextToken( TCHAR *pszString , TCHAR *tchToken )
  750. {
  751. while( *pszString )
  752. {
  753. if( IsCharAlpha( *pszString ) )
  754. {
  755. *tchToken = *pszString;
  756. }
  757. else
  758. {
  759. break;
  760. }
  761. tchToken++;
  762. pszString++;
  763. }
  764. *tchToken = '\0';
  765. return pszString;
  766. }