uifw/AvKon/src/AknNumEdwin.cpp
changeset 0 2f259fa3e83a
child 8 71dd06cfe933
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Numeric Editor derived from Uikon's CEikEdwin
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 
       
    22 #include <barsread.h>  // Resource reading
       
    23 
       
    24 #include <eikon.hrh>
       
    25 #include <eikctl.rsg>
       
    26 #include <eikenv.h>
       
    27 
       
    28 #include "AknNumEdwin.h"
       
    29 #include "avkon.hrh"
       
    30 #include "AknDef.h"
       
    31 
       
    32 #include <aknenv.h>
       
    33 #include <AknSettingCache.h>
       
    34 #include <numberconversion.h>
       
    35 #include <AknUtils.h>
       
    36 
       
    37 	_LIT(KEmptyText, "" );
       
    38 
       
    39 // INTERNAL CLASS DEFINITIONS
       
    40 
       
    41 
       
    42 // CLASS IMPLEMENTATIONS
       
    43 
       
    44 
       
    45 EXPORT_C CAknIntegerEdwin* CAknIntegerEdwin::NewL( TInt aMin, TInt aMax, TInt aTextLimit )
       
    46     {
       
    47     CAknIntegerEdwin* self = new ( ELeave ) CAknIntegerEdwin;
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( aMin, aMax, aTextLimit);
       
    50     CleanupStack::Pop();
       
    51     return self;
       
    52     }
       
    53 
       
    54 EXPORT_C void CAknIntegerEdwin::ConstructFromResourceL(TResourceReader& aReader)
       
    55 	{
       
    56 	const TInt edwinFlags=0; 
       
    57 
       
    58 	CalculateWidth(20);  // overridden by later layout code
       
    59 
       
    60 	TInt textLimit = aReader.ReadInt16();
       
    61 	TInt minValue = aReader.ReadInt32();
       
    62 	TInt maxValue = aReader.ReadInt32();
       
    63 	iUnsetValue = aReader.ReadInt32();
       
    64 
       
    65 // possible extensions
       
    66 	TInt dummy =  aReader.ReadInt32();
       
    67 	dummy = aReader.ReadInt32();
       
    68 
       
    69 	CommonConstructL(minValue, maxValue, textLimit, edwinFlags, iUnsetValue);
       
    70 	}
       
    71 
       
    72 EXPORT_C void CAknIntegerEdwin::ConstructL(TInt aMin, TInt aMax, TInt aTextLimit)
       
    73 	{
       
    74 	const TInt edwinFlags=0; 
       
    75 
       
    76 	CommonConstructL(aMin, aMax, aTextLimit, edwinFlags, KMaxTInt);
       
    77 	}
       
    78 
       
    79 void CAknIntegerEdwin::CommonConstructL(TInt aMin, TInt aMax, TInt aMaxChars, TInt aFlags, TInt aUnset)
       
    80 	{
       
    81 	iDigitType = EDigitTypeWestern;
       
    82 
       
    83 	const TInt numberOfLines=1;
       
    84 
       
    85 	// Enforce maximum number of digits for numeric Edwin - Otherwise CEikEdwin treats maxlimit of 0 as no limit.
       
    86 	TInt maxLimit(aMaxChars);
       
    87 	if( (maxLimit==0) || (maxLimit>EAknMaxIntegerDigits) )
       
    88 		maxLimit = EAknMaxIntegerDigits;
       
    89 
       
    90 	CEikEdwin::ConstructL(aFlags, aMaxChars, maxLimit, numberOfLines);
       
    91 	SetMinimumIntegerValue(aMin);
       
    92 	SetMaximumIntegerValue(aMax);
       
    93 
       
    94 	SetAknEditorCase(EAknEditorUpperCase);
       
    95 	SetAknEditorAllowedInputModes(EAknEditorNumericInputMode);
       
    96 	SetAknEditorInputMode(EAknEditorNumericInputMode);
       
    97 	SetAknEditorSpecialCharacterTable(0);
       
    98 	SetAknEditorFlags(EAknEditorFlagFixedCase | EAknEditorFlagNoT9);
       
    99 	// Only plain numbers
       
   100 	// The EAknEditorPlainNumberModeKeymap does not support - -sign so
       
   101 	// we have to use the converter mapping
       
   102 	SetAknEditorNumericKeymap(EAknEditorConverterNumberModeKeymap);
       
   103 
       
   104 	iUnsetValue = aUnset;
       
   105 	SetValueL(iUnsetValue);
       
   106 	RefreshFromLocale();
       
   107 	}
       
   108 
       
   109 EXPORT_C void CAknIntegerEdwin::SetValueL( TInt aValue )
       
   110 	{
       
   111 	if ( aValue != iUnsetValue )
       
   112 		{
       
   113 		HBufC* formatBuffer = HBufC::NewMaxLC( EAknMaxIntegerDigits );
       
   114 		TPtr formatPtr = formatBuffer->Des();
       
   115 		formatPtr.Format(KAknIntegerFormat, aValue);
       
   116 		
       
   117         // Latin only editor doesn't need conversion
       
   118         if ( !( AknEdwinFlags() & EAknEditorFlagLatinInputModesOnly ) )
       
   119             {
       
   120             NumberConversion::ConvertDigits(formatPtr, iDigitType);
       
   121             }
       
   122 
       
   123 		SetTextL( &formatPtr );
       
   124 		CleanupStack::Pop(); // formatBuffer
       
   125 		delete formatBuffer;
       
   126 		}
       
   127 	else
       
   128 		{
       
   129 		SetTextL( &KEmptyText );
       
   130 		}
       
   131 	}
       
   132 
       
   133 EXPORT_C TKeyResponse CAknIntegerEdwin::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   134 	{
       
   135 	TKeyEvent modifiedKeyEvent(aKeyEvent);
       
   136 	TEventCode modifiedEventCode(aType);
       
   137     
       
   138     // FEP already should input converted numbers, so there's no need for this.
       
   139 	//MapKeyEvent(modifiedKeyEvent, modifiedEventCode, iDigitType);
       
   140 	return CAknNumericEdwin::OfferKeyEventL(modifiedKeyEvent, modifiedEventCode);
       
   141 	}
       
   142 
       
   143 
       
   144 EXPORT_C CAknIntegerEdwin::TValidationStatus CAknIntegerEdwin::GetTextAsInteger( TInt& aValue )
       
   145 	{
       
   146 
       
   147 	TValidationStatus state = EValueNotParsed;
       
   148 
       
   149 	// Create a normalised western version of the string.
       
   150 	TBuf<EAknMaxIntegerDigits> normalisedText;
       
   151 	GetText(normalisedText);
       
   152 	NumberConversion::ConvertDigits(normalisedText, EDigitTypeWestern);
       
   153 
       
   154 	// Use TextLength() for this test, because stray paragraph marks may lurk in the TPtrC buffer
       
   155 	if ( TextLength() == 0 )
       
   156 		{
       
   157 		state = EEmpty;
       
   158 		aValue = iUnsetValue;
       
   159 		}
       
   160 	else 
       
   161 		{
       
   162 		TLex lex( normalisedText );
       
   163 
       
   164 		if ( lex.Val(aValue) == KErrNone && lex.Remainder().Length() == 0 )
       
   165 			{
       
   166 			state = EValueValid;
       
   167 
       
   168 			// Test the range:
       
   169 			if ( aValue < iMinimumValue )
       
   170 				state = EValueTooSmall;
       
   171 			else if ( aValue > iMaximumValue )
       
   172 				state = EValueTooLarge;
       
   173 			}
       
   174 		else
       
   175 			{
       
   176 			state = EValueNotParsed;
       
   177 			aValue = iUnsetValue;
       
   178 			}
       
   179 
       
   180 		}
       
   181 
       
   182 	return state;
       
   183 
       
   184 	}
       
   185 
       
   186 
       
   187 
       
   188 EXPORT_C void CAknIntegerEdwin::SetMinimumIntegerValue( TInt aMinimum )
       
   189 	{
       
   190 	iMinimumValue = aMinimum;
       
   191 	}
       
   192 
       
   193 EXPORT_C void CAknIntegerEdwin::SetMaximumIntegerValue( TInt aMaximum )
       
   194 	{
       
   195 	iMaximumValue = aMaximum;
       
   196 	}
       
   197 
       
   198 EXPORT_C void CAknIntegerEdwin::SetUnsetValue( TInt aUnsetValue )
       
   199 	{
       
   200 	iUnsetValue = aUnsetValue;
       
   201 	}
       
   202 
       
   203 
       
   204 EXPORT_C void CAknIntegerEdwin::PrepareForFocusLossL()
       
   205 	{
       
   206 	// TInt resId = 0;
       
   207 	TInt value;
       
   208 	TValidationStatus state = GetTextAsInteger( value );
       
   209 
       
   210 	switch (state )
       
   211 		{
       
   212 		case EValueValid:
       
   213 		break;
       
   214 
       
   215 		case EEmpty:
       
   216 		break;
       
   217 
       
   218 		case EValueTooSmall:
       
   219 		// resId=R_EIK_TBUF_FNUMBER_BELOW_MIN;
       
   220 		value = iMinimumValue;
       
   221 		break;
       
   222 
       
   223 		case EValueTooLarge:
       
   224 		// resId=R_EIK_TBUF_FNUMBER_ABOVE_MAX;
       
   225 		value = iMaximumValue;
       
   226 		break;
       
   227 
       
   228 		case EValueNotParsed:
       
   229 
       
   230 		break;
       
   231 
       
   232 		default:
       
   233 		break;
       
   234 		}
       
   235 
       
   236 	}
       
   237 
       
   238 EXPORT_C void CAknIntegerEdwin::HandleResourceChange(TInt aType)
       
   239 	{
       
   240 	if(aType==KEikInputLanguageChange)
       
   241 		{
       
   242 		RefreshFromLocale();
       
   243 		return;
       
   244 		}
       
   245 	CAknNumericEdwin::HandleResourceChange(aType);
       
   246 	}
       
   247 
       
   248 void CAknIntegerEdwin::RefreshFromLocale()
       
   249 	{
       
   250 	iDigitType = AknTextUtils::NumericEditorDigitType();
       
   251 
       
   252 	TInt value;
       
   253 	if( GetTextAsInteger(value) != EValueValid)
       
   254 		return;
       
   255 
       
   256 	TRAP_IGNORE(SetValueL(value) ); // shouldn't leave with OOM because text string is the same size as previous.
       
   257 	}
       
   258 	
       
   259 EXPORT_C void CAknIntegerEdwin::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
       
   260     { 
       
   261     CAknNumericEdwin::HandlePointerEventL(aPointerEvent); 
       
   262     }	
       
   263 
       
   264 EXPORT_C void* CAknIntegerEdwin::ExtensionInterface( TUid /*aInterface*/ ) 
       
   265     { 
       
   266     return NULL;
       
   267     }
       
   268 
       
   269 EXPORT_C void CAknIntegerEdwin::Reserved_3()
       
   270 	{
       
   271 	}
       
   272     
       
   273 EXPORT_C TBool CAknIntegerEdwin::CheckNumber()
       
   274     {
       
   275     
       
   276     TInt value;
       
   277 	TValidationStatus state = GetTextAsInteger( value );
       
   278 
       
   279 	switch (state )
       
   280 		{
       
   281 		case EValueTooSmall:
       
   282 		    {
       
   283 		    TRAP_IGNORE( SetValueL( iMinimumValue ) );
       
   284 		    TRAP_IGNORE( SelectAllL() );
       
   285 		    DrawDeferred();
       
   286 		    return EFalse;
       
   287 		    }
       
   288 		case EValueTooLarge:
       
   289             {
       
   290 		    TRAP_IGNORE( SetValueL( iMaximumValue ) );
       
   291         	TRAP_IGNORE( SelectAllL() );
       
   292 		    DrawDeferred();
       
   293 		    return EFalse;
       
   294             }	
       
   295 		default:
       
   296 		break;
       
   297 		}
       
   298 		
       
   299     return ETrue;
       
   300     }
       
   301     
       
   302 // End of File