home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / prefs / CValidEditField.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.2 KB  |  165 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "CValidEditField.h"
  20.  
  21. //-----------------------------------
  22. CValidEditField::CValidEditField( LStream* s )
  23. //-----------------------------------
  24. :    LGAEditField( s )
  25. ,    mValidationFunc( nil )
  26. {
  27. }
  28.  
  29. //-----------------------------------
  30. Boolean CValidEditField::AllowTargetSwitch( LCommander* /*newTarget*/ )
  31. //-----------------------------------
  32. {
  33.     if ( mValidationFunc )
  34.         return (*mValidationFunc )(this);
  35.     return true;
  36. }
  37.  
  38. //-----------------------------------
  39. void CValidEditField::SetValidationFunction( ValidationFunc validationFunc )
  40. //-----------------------------------
  41. {
  42.     mValidationFunc = validationFunc;
  43. }
  44.  
  45. /********************************************************************************
  46.  * Validation Functions
  47.  ********************************************************************************/
  48. #include "uprefd.h"  // for constants used below.
  49. #include "uerrmgr.h"
  50. #include "resgui.h"
  51.  
  52.  
  53. Boolean ConstrainEditField( LEditField* whichField, long minValue, long maxValue )
  54. {
  55.     long        value;
  56.     Boolean        allowSwitch = TRUE;
  57.     
  58.     value = whichField->GetValue();    
  59.     if ( value > maxValue || value < minValue )
  60.     {
  61.         allowSwitch = FALSE;
  62.         if ( value > maxValue )
  63.             whichField->SetValue( maxValue );
  64.         else
  65.             whichField->SetValue( minValue );
  66.     }
  67.     return allowSwitch;
  68. }
  69.  
  70. Boolean ValidateCacheSize( CValidEditField* bufferSize )
  71. {
  72.     Boolean        allowSwitch = TRUE;
  73.     
  74.     allowSwitch = ConstrainEditField( bufferSize, BUFFER_MIN / BUFFER_SCALE,
  75.          BUFFER_MAX / BUFFER_SCALE );
  76.     if ( !allowSwitch )
  77.     {
  78.         UDesktop::Deactivate();
  79.         ::CautionAlert( 1063, NULL );
  80.         UDesktop::Activate();
  81.     }
  82.  
  83.     return allowSwitch;
  84. }
  85.  
  86. Boolean ValidateNumberNewsArticles( CValidEditField* articles )
  87. {
  88.     Boolean        allowSwitch = TRUE;
  89.     
  90.     allowSwitch = ConstrainEditField( articles, NEWS_ARTICLES_MIN, NEWS_ARTICLES_MAX );
  91.     if ( !allowSwitch )
  92.     {
  93.         UDesktop::Deactivate();
  94.         ::CautionAlert( 1066, NULL );
  95.         UDesktop::Activate();
  96.     }
  97.     return allowSwitch;
  98. }
  99.  
  100. Boolean ValidateDaysTilExpire( CValidEditField* daysTilExpire )
  101. {
  102.     Boolean        allowSwitch = TRUE;
  103.     
  104.     allowSwitch = ConstrainEditField( daysTilExpire, EXPIRE_MIN, EXPIRE_MAX );
  105.     if ( !allowSwitch )
  106.     {
  107.         UDesktop::Deactivate();
  108.         ::CautionAlert( 1064, NULL );
  109.         UDesktop::Activate();
  110.     }        
  111.     
  112.     return allowSwitch;
  113. }
  114.  
  115. Boolean ValidateNumberConnections( CValidEditField* connections )
  116. {
  117.     Boolean        allowSwitch = TRUE;
  118.     
  119.     allowSwitch = ConstrainEditField( connections, CONNECTIONS_MIN, CONNECTIONS_MAX );
  120.     if ( !allowSwitch )
  121.     {
  122.         UDesktop::Deactivate();
  123.         ::CautionAlert( 1062, NULL );
  124.         UDesktop::Activate();
  125.     }        
  126.         
  127.     return allowSwitch;
  128. }
  129.  
  130. Boolean ValidatePopID( CValidEditField* connections )
  131. {
  132.     CStr255 value;
  133.     connections->GetDescriptor(value);
  134.     if (value.Pos("@"))
  135.     // ÑÑÑ FIX ME l10n
  136.     {
  137.         ErrorManager::PlainAlert(POP_USERNAME_ONLY);
  138.         return FALSE;
  139.     }
  140.     else
  141.         return TRUE;
  142. }
  143.  
  144. void TargetOnEditField( LEditField* editField, Boolean doTarget )
  145. {
  146.     if ( doTarget )
  147.     {
  148.         editField->Enable();
  149.         editField->Refresh();
  150.         // pkc -- Call SetLatentSub instead of SwitchTarget
  151.         if( editField->GetSuperCommander() )
  152.             (editField->GetSuperCommander())->SetLatentSub(editField);
  153.         editField->SelectAll();
  154.     }
  155.     else
  156.     {
  157.         editField->Disable();
  158.         editField->Refresh();
  159.         // pkc -- Call SetLatentSub instead of SwitchTarget
  160.         if( editField->GetSuperCommander() )
  161.             (editField->GetSuperCommander())->SetLatentSub(editField);
  162.     }
  163. }
  164.  
  165.