landmarksui/uicontrols/src/CLmkDecimalEditor.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2005 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:    LandmarksUi Content File -
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include <barsread.h>
       
    27 #include <eikenv.h>
       
    28 #include <NumberConversion.h>
       
    29 #include <AknUtils.h>
       
    30 #include <aknsoundsystem.h>
       
    31 #include <AknAppUi.h>
       
    32 #include <AknTextDecorationMetrics.h>
       
    33 #include <eikctl.rsg>
       
    34 #include <e32math.h>
       
    35 
       
    36 #include "CLmkDecimalEditor.h"
       
    37 
       
    38 
       
    39 _LIT(KMinus,"-");
       
    40 
       
    41 namespace EUtils
       
    42 	{
       
    43 	LOCAL_D TBool IsAnyDigit(TChar aCharacter)
       
    44 		{
       
    45 		return ( aCharacter.GetNumericValue() != KErrNotFound);
       
    46 		}
       
    47 	}
       
    48 
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CLmkDecimalEditor::CLmkDecimalEditor
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CLmkDecimalEditor::CLmkDecimalEditor(TInt aMinimumValue, TInt aMaximumValue, TUint32 aFlags)
       
    55 									:iMinimumValue(aMinimumValue),
       
    56 									 iMaximumValue(aMaximumValue),
       
    57 									 iFlags(aFlags),
       
    58 									 iDigitType(EDigitTypeWestern)
       
    59 	{
       
    60 	TBuf<16> minText;
       
    61 	minText.AppendNum(aMinimumValue);
       
    62 	TBuf<16> maxText;
       
    63 	maxText.AppendNum(aMaximumValue);
       
    64 	iMaxDigits=Max(minText.Length(),maxText.Length());
       
    65 
       
    66 	iMaxDigitsMinimumValue=minText.Length();
       
    67 	iMaxDigitsMaximumValue=maxText.Length();
       
    68 	iEnv = CEikonEnv::Static();
       
    69 	}
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CLmkDecimalEditor::~CLmkDecimalEditor
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 CLmkDecimalEditor::~CLmkDecimalEditor()
       
    76 	{
       
    77 	delete iText;
       
    78 	}
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CLmkDecimalEditor::NewL
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CLmkDecimalEditor* CLmkDecimalEditor::NewL(const CFont& aFont, TResourceReader& aResourceReader)
       
    85 	{
       
    86 	TInt minimumValue=aResourceReader.ReadInt32();
       
    87 	TInt maximumValue=aResourceReader.ReadInt32();
       
    88 	TUint32 flags=aResourceReader.ReadUint8();
       
    89 	return NewL(aFont, minimumValue, maximumValue, maximumValue, flags, 0);
       
    90 	}
       
    91 
       
    92 // ---------------------------------------------------------
       
    93 // CLmkDecimalEditor::NewL
       
    94 // ---------------------------------------------------------
       
    95 //
       
    96 CLmkDecimalEditor* CLmkDecimalEditor::NewL(const CFont& aFont, TInt aMinimumValue, TInt aMaximumValue, TInt aInitialValue, TUint32 aFlags, TInt aNumberOfZeros)
       
    97 	{
       
    98 	CLmkDecimalEditor* number=new(ELeave) CLmkDecimalEditor(aMinimumValue, aMaximumValue, aFlags);
       
    99 	CleanupStack::PushL(number);
       
   100 	number->iText=HBufC::NewL(number->MaximumNumberOfDigits()+((aMinimumValue<0)? 1: 0));
       
   101 	number->ConstructL(aNumberOfZeros);
       
   102 	number->SetValue(aInitialValue, aFont);
       
   103 	CleanupStack::Pop();
       
   104 	return number;
       
   105 	}
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // CLmkDecimalEditor::InvalidFieldAlert
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 void CLmkDecimalEditor::InvalidFieldAlert() const
       
   112 	{
       
   113     CAknKeySoundSystem* soundPlayer = (static_cast<CAknAppUi*>(iEnv->AppUi()))->KeySounds();
       
   114     if(soundPlayer)
       
   115         {
       
   116         soundPlayer->PlaySound(EAvkonSIDWarningTone);
       
   117         }
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------
       
   121 // CLmkDecimalEditor::AdditionalWidthForHighlights
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 TInt CLmkDecimalEditor::AdditionalWidthForHighlights(const CFont& aFont) const
       
   125     {
       
   126     TInt addedWidth(0);
       
   127     if ( IsEditable() )
       
   128         {
       
   129         TInt rightHighlight(0);
       
   130         TAknTextDecorationMetrics metrics( &aFont );
       
   131         // Width is increased only by leftHighlight.  This is a compromise in that glyphs already have
       
   132         // spacing within them to achieve character spacing. This spacing is generally (for numbers) on the right.
       
   133         metrics.GetLeftAndRightMargins( addedWidth, rightHighlight ); // rightHighlight is not used
       
   134         }
       
   135     return addedWidth;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CLmkDecimalEditor::WidthInPixels
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 TInt CLmkDecimalEditor::WidthInPixels(const CFont& aFont) const
       
   143 	{
       
   144 	return Max( iMinimumWidthInPixels, aFont.TextWidthInPixels(Text()) + AdditionalWidthForHighlights(aFont) );
       
   145 	}
       
   146 
       
   147 // ---------------------------------------------------------
       
   148 // CLmkDecimalEditor::ConstructL
       
   149 // ---------------------------------------------------------
       
   150 //
       
   151 void CLmkDecimalEditor::ConstructL(TInt aNumberOfZeros)
       
   152 	{
       
   153 	iNudgeCharMinus=iEnv->NudgeCharMinus();
       
   154 	iNudgeCharPlus=iEnv->NudgeCharPlus();
       
   155 	iNumberOfZeros = aNumberOfZeros;
       
   156 	}
       
   157 
       
   158 // ---------------------------------------------------------
       
   159 // CLmkDecimalEditor::SetMinimumAndMaximum
       
   160 // ---------------------------------------------------------
       
   161 //
       
   162 void CLmkDecimalEditor::SetMinimumAndMaximum(TInt aMinimumValue, TInt aMaximumValue, const CFont& aFont)
       
   163 	{
       
   164 	TBuf<16> minText;
       
   165 	minText.AppendNum(aMinimumValue);
       
   166 	TBuf<16> maxText;
       
   167 	maxText.AppendNum(aMaximumValue);
       
   168 	TInt minTextLength=minText.Length();
       
   169 	TInt maxTextLength=maxText.Length();
       
   170 	iMinimumValue=aMinimumValue;
       
   171 	iMaximumValue=aMaximumValue;
       
   172 	TInt value=ValueFromText();
       
   173 	if (value<aMinimumValue||!NumberOfDigits())
       
   174 		SetTextToValue(aMinimumValue, aFont);
       
   175 	else if (value>aMaximumValue)
       
   176 		SetTextToValue(aMaximumValue, aFont);
       
   177 	}
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CLmkDecimalEditor::GetMinimumAndMaximum
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 void CLmkDecimalEditor::GetMinimumAndMaximum(TInt& aMinimumValue, TInt& aMaximumValue) const
       
   184 	{
       
   185 	aMinimumValue=iMinimumValue;
       
   186 	aMaximumValue=iMaximumValue;
       
   187 	}
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CLmkDecimalEditor::SetValue
       
   191 // ---------------------------------------------------------
       
   192 //
       
   193 void CLmkDecimalEditor::SetValue(TInt aValue, const CFont& aFont)
       
   194 	{
       
   195 	SetTextToValue(aValue, aFont);
       
   196 	}
       
   197 
       
   198 // ---------------------------------------------------------
       
   199 // CLmkDecimalEditor::Value
       
   200 // ---------------------------------------------------------
       
   201 //
       
   202 TReal CLmkDecimalEditor::Value() const
       
   203 	{
       
   204 	TInt numberOfDigits = NumberOfDigits();
       
   205 	TReal retVal(0);
       
   206 	TReal temp(0);
       
   207 
       
   208     if (numberOfDigits == 0)
       
   209         {
       
   210         InvalidFieldAlert();
       
   211         }
       
   212 
       
   213     TInt value = ValueFromText();
       
   214     if (value < iMinimumValue)
       
   215         {
       
   216 		InvalidFieldAlert();
       
   217 	    iEnv->LeaveWithInfoMsg(R_EIK_TBUF_NUMBER_BELOW_MIN, iMinimumValue);
       
   218         }
       
   219     if (value > iMaximumValue)
       
   220 		{
       
   221 	    iEnv->LeaveWithInfoMsg(R_EIK_TBUF_NUMBER_ABOVE_MAX, iMaximumValue);
       
   222         }
       
   223     Math::Pow10(temp, numberOfDigits * (-1));
       
   224     retVal = value * temp;
       
   225     return retVal;
       
   226 	}
       
   227 
       
   228 // ---------------------------------------------------------
       
   229 // CLmkDecimalEditor::IsValid
       
   230 // ---------------------------------------------------------
       
   231 //
       
   232 TBool CLmkDecimalEditor::IsValid() const
       
   233 	{
       
   234 	return (NumberOfDigits() != 0);
       
   235 	}
       
   236 
       
   237 // ---------------------------------------------------------
       
   238 // CLmkDecimalEditor::NormalizeDigit
       
   239 // ---------------------------------------------------------
       
   240 //
       
   241 TChar CLmkDecimalEditor::NormalizeDigit(TChar aChar)
       
   242 	{
       
   243 	TBuf<1> buf;
       
   244 	buf.Append(aChar);
       
   245 	NumberConversion::ConvertDigits(buf, iDigitType);
       
   246 	return buf[0];
       
   247 	}
       
   248 
       
   249 // ---------------------------------------------------------
       
   250 // CLmkDecimalEditor::ZeroCharacter
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 TText CLmkDecimalEditor::ZeroCharacter() const
       
   254 		{
       
   255 		return TText(iDigitType);
       
   256 		}
       
   257 
       
   258 // ---------------------------------------------------------
       
   259 // CLmkDecimalEditor::NegativeCharacter
       
   260 // ---------------------------------------------------------
       
   261 //
       
   262 TText CLmkDecimalEditor::NegativeCharacter() const
       
   263 		{
       
   264 		return TText('-');
       
   265 		}
       
   266 
       
   267 // ---------------------------------------------------------
       
   268 // CLmkDecimalEditor::IsTextNull
       
   269 // ---------------------------------------------------------
       
   270 //
       
   271 TBool CLmkDecimalEditor::IsTextNull() const
       
   272 	{
       
   273 	return ( Text().Length() < 1 );
       
   274 	}
       
   275 
       
   276 // ---------------------------------------------------------
       
   277 // CLmkDecimalEditor::MaximumWidthInPixels
       
   278 // ---------------------------------------------------------
       
   279 //
       
   280 TInt CLmkDecimalEditor::MaximumWidthInPixels(const CFont& aFont, TBool aShrinkToMinimumSize)
       
   281 	{
       
   282 	if (aShrinkToMinimumSize)
       
   283 		{
       
   284 		TBuf<16> minText;
       
   285 		minText.AppendNum(iMinimumValue);
       
   286 		TBuf<16> maxText;
       
   287 		maxText.AppendNum(iMaximumValue);
       
   288 
       
   289 		iMaxDigits=Max(2,Max(minText.Length(),maxText.Length()));
       
   290 		}
       
   291 	return (MaximumNumberOfDigits()*TFindWidthOfWidestDigitType(DigitType()).MaximumWidthInPixels(aFont)) + AdditionalWidthForHighlights(aFont) /*+((iMinimumValueCateredForInFieldWidth<0)? aFont.TextWidthInPixels(_L("-")): 0)*/;
       
   292 	}
       
   293 
       
   294 // ---------------------------------------------------------
       
   295 // CLmkDecimalEditor::InputCapabilities
       
   296 // ---------------------------------------------------------
       
   297 //
       
   298 TCoeInputCapabilities CLmkDecimalEditor::InputCapabilities() const
       
   299 	{
       
   300 	TUint inputCapabilities=TCoeInputCapabilities::ENone;
       
   301 	if (iMinimumValue<0)
       
   302 		{
       
   303 		inputCapabilities|=TCoeInputCapabilities::EWesternNumericIntegerNegative;
       
   304 		}
       
   305 	if (iMaximumValue>0)
       
   306 		{
       
   307 		inputCapabilities|=TCoeInputCapabilities::EWesternNumericIntegerPositive;
       
   308 		}
       
   309 	return TCoeInputCapabilities(inputCapabilities);
       
   310 	}
       
   311 
       
   312 // ---------------------------------------------------------
       
   313 // CLmkDecimalEditor::Text
       
   314 // ---------------------------------------------------------
       
   315 //
       
   316 const TDesC& CLmkDecimalEditor::Text() const
       
   317 	{
       
   318 	if (IsUninitialised())
       
   319 		return KNullDesC();
       
   320 	else
       
   321 		return *iText;
       
   322 	}
       
   323 
       
   324 // ---------------------------------------------------------
       
   325 // CLmkDecimalEditor::IsEditable
       
   326 // ---------------------------------------------------------
       
   327 //
       
   328 TBool CLmkDecimalEditor::IsEditable() const
       
   329 	{
       
   330 	return ETrue;
       
   331 	}
       
   332 
       
   333 // ---------------------------------------------------------
       
   334 // CLmkDecimalEditor::HighlightType
       
   335 // ---------------------------------------------------------
       
   336 //
       
   337 CEikMfneField::THighlightType CLmkDecimalEditor::HighlightType() const
       
   338 	{
       
   339 	return (iFlags&EIsBeingEditedWithCursor)? ECursor: EInverseVideo;
       
   340 	}
       
   341 
       
   342 // ---------------------------------------------------------
       
   343 // CLmkDecimalEditor::HandleKey
       
   344 // ---------------------------------------------------------
       
   345 //
       
   346 void CLmkDecimalEditor::HandleKey(const CFont& aFont, const TKeyEvent& aKeyEvent, TBool aInterpretLeftAndRightAsEarEvents, TBool& aDataAltered, TInt& aHighlightIncrement)
       
   347 	{
       
   348 	TChar ch=aKeyEvent.iCode;
       
   349 
       
   350 	TPtr text=iText->Des();
       
   351 	TInt textLength=text.Length();
       
   352 	TBool nudgeTen=EFalse;
       
   353 	switch (ch)
       
   354 		{
       
   355 	case EKeyLeftArrow:
       
   356 	case EKeyRightArrow:
       
   357 		if (!aInterpretLeftAndRightAsEarEvents)
       
   358 			HandleLeftOrRightArrow(ch, aDataAltered, aHighlightIncrement);
       
   359 		else
       
   360 			{
       
   361 		doAdjust:
       
   362 			const TInt nudge=(nudgeTen? 10 : 1);
       
   363 			TInt newValue;
       
   364 
       
   365 
       
   366 			if ((textLength==0) || ! EUtils::IsAnyDigit( TChar(text[textLength-1]) ) )
       
   367 				newValue=0;
       
   368 			else
       
   369 				newValue=ValueFromText()+((ch==EKeyLeftArrow)? -nudge: nudge);
       
   370 			if (newValue>=iMaximumValue)
       
   371 				newValue=iMaximumValue;
       
   372 			else if (newValue<=iMinimumValue)
       
   373 				newValue=iMinimumValue;
       
   374 			SetTextToValue(newValue, aFont);
       
   375 			aHighlightIncrement=0;// Always highlight the field being nudged
       
   376 			aDataAltered=ETrue;
       
   377 			SetUninitialised(EFalse);
       
   378 			iFlags&=~EIsBeingEditedWithCursor;
       
   379 			}
       
   380 		break;
       
   381     case EKeyDownArrow:
       
   382     case EKeyUpArrow:
       
   383         {
       
   384 		if (IsUninitialised())
       
   385 			{
       
   386 			SetUninitialised(EFalse);
       
   387 			}
       
   388 		else
       
   389 			{
       
   390 		        const TInt nudge=(nudgeTen? 10 : 1);
       
   391         		TInt newValue;
       
   392 
       
   393 
       
   394 		        if ((textLength==0) || ! EUtils::IsAnyDigit( TChar(text[textLength-1])) )
       
   395         		    newValue=0;
       
   396         		else
       
   397             			newValue=ValueFromText()+((ch==EKeyDownArrow)? -nudge: nudge);
       
   398 
       
   399 	 		if (newValue>iMaximumValue)
       
   400             			newValue=iMinimumValue;
       
   401         		else if (newValue<iMinimumValue)
       
   402 		            newValue=iMaximumValue;
       
   403        			SetTextToValue(newValue, aFont);
       
   404         		aHighlightIncrement=0;// Always highlight the field being nudged
       
   405         		aDataAltered=ETrue;
       
   406         		iFlags&=~EIsBeingEditedWithCursor;
       
   407 			}
       
   408 		aDataAltered=ETrue;
       
   409         }
       
   410         break;
       
   411     case EKeyBackspace:
       
   412 		if (textLength)
       
   413 			{
       
   414 			iFlags|=EIsBeingEditedWithCursor;
       
   415 			text.SetLength(textLength-1);
       
   416 			if (text==KMinus)
       
   417 				text.SetLength(0);
       
   418 			aDataAltered=ETrue;
       
   419 			SetUninitialised(EFalse);
       
   420 			}
       
   421 		break;
       
   422 	case '+':
       
   423 		break;
       
   424 	case '-':
       
   425         if (iMinimumValue < 0)
       
   426             {
       
   427 			if (~iFlags&EIsBeingEditedWithCursor)
       
   428 				{
       
   429 				iFlags|=EIsBeingEditedWithCursor;
       
   430 				text.SetLength(0);
       
   431 				}
       
   432 			if (text.Length()==0)
       
   433 				{
       
   434 				text.Append('-');
       
   435 				aDataAltered=ETrue;
       
   436 				SetUninitialised(EFalse);
       
   437 				}
       
   438 			}
       
   439 		break;
       
   440 	default:
       
   441 		TBuf<2> nudgeTenChars;
       
   442 		CCoeEnv::Static()->ReadResource(nudgeTenChars,R_EIK_TBUF_NUDGE_TEN_CHARS);
       
   443 
       
   444 		if ( EUtils::IsAnyDigit(ch) )
       
   445 			{
       
   446 			if (~iFlags&EIsBeingEditedWithCursor)
       
   447 				{
       
   448 				iFlags|=EIsBeingEditedWithCursor;
       
   449 				text.SetLength(0);
       
   450 				}
       
   451 			text.Append(NormalizeDigit(ch) );
       
   452 			aDataAltered=ETrue;
       
   453 			SetUninitialised(EFalse);
       
   454 			if (NumberOfDigits()>=MaximumNumberOfDigits())
       
   455 				aHighlightIncrement=1;
       
   456 			}
       
   457 		if (ch==iNudgeCharMinus)
       
   458 			{
       
   459 			ch=EKeyLeftArrow;
       
   460 			goto doAdjust;
       
   461 			}
       
   462 		else if (ch==iNudgeCharPlus)
       
   463 			{
       
   464 			ch=EKeyRightArrow;
       
   465 			goto doAdjust;
       
   466 			}
       
   467 		else if (ch==((TUint)nudgeTenChars[0]))
       
   468 			{
       
   469 			ch=EKeyLeftArrow;
       
   470 			nudgeTen=ETrue;
       
   471 			goto doAdjust;
       
   472 			}
       
   473 		else if (ch==((TUint)nudgeTenChars[1]))
       
   474 			{
       
   475 			ch=EKeyRightArrow;
       
   476 			nudgeTen=ETrue;
       
   477 			goto doAdjust;
       
   478 			}
       
   479 		break;
       
   480 		}
       
   481 	}
       
   482 
       
   483 // ---------------------------------------------------------
       
   484 // CLmkDecimalEditor::HandleDeHighlight
       
   485 // ---------------------------------------------------------
       
   486 //
       
   487 void CLmkDecimalEditor::HandleDeHighlight(const CFont& aFont, CEikonEnv& aEikonEnv, TBool& aDataAltered, TBool& aError)
       
   488 	{
       
   489 	iFlags&=~EIsBeingEditedWithCursor;
       
   490 	if (NumberOfDigits()==0)
       
   491 		{
       
   492 		SetTextToValue(iMaximumValue, aFont);
       
   493 		aDataAltered=ETrue;
       
   494 		aError=ETrue;
       
   495 		aEikonEnv.InfoMsg(R_EIK_TBUF_NO_NUMBER_ENTERED);
       
   496 		return;
       
   497 		}
       
   498 	TInt value=ValueFromText();
       
   499     if ((value<iMinimumValue) || (value>iMaximumValue))
       
   500         {
       
   501         TBool succeeded = ConvertsIntoValidValue(value);
       
   502         if ( !succeeded )
       
   503             {
       
   504             aDataAltered=ETrue;
       
   505             aError=ETrue;
       
   506             if (value<iMinimumValue)
       
   507                 {
       
   508                 SetTextToValue(iMinimumValue, aFont);
       
   509 				InvalidFieldAlert();
       
   510                 aEikonEnv.InfoMsg(R_EIK_TBUF_NUMBER_BELOW_MIN, iMinimumValue);
       
   511                 return;
       
   512                 }
       
   513             if (value>iMaximumValue)
       
   514                 {
       
   515 				InvalidFieldAlert();
       
   516                 SetTextToValue(iMaximumValue, aFont);
       
   517                 aEikonEnv.InfoMsg(R_EIK_TBUF_NUMBER_ABOVE_MAX, iMaximumValue);
       
   518                 return;
       
   519                 }
       
   520             }
       
   521         }
       
   522 	TBuf<128> oldText=*iText;
       
   523 	TBool unInit = IsUninitialised();
       
   524 	//SetTextToValue(value, aFont);
       
   525 	if (oldText!=*iText)
       
   526 		aDataAltered=ETrue;
       
   527 	else
       
   528 		SetUninitialised(unInit);
       
   529 	}
       
   530 
       
   531 // ---------------------------------------------------------
       
   532 // CLmkDecimalEditor::MaximumNumberOfDigits
       
   533 // ---------------------------------------------------------
       
   534 //
       
   535 TInt CLmkDecimalEditor::MaximumNumberOfDigits() const
       
   536 	{
       
   537 	return Max(2,iMaxDigits);
       
   538 	}
       
   539 
       
   540 // ---------------------------------------------------------
       
   541 // CLmkDecimalEditor::NumberOfDigits
       
   542 // ---------------------------------------------------------
       
   543 //
       
   544 TInt CLmkDecimalEditor::NumberOfDigits() const
       
   545 	{
       
   546 	return iText->Length();
       
   547 	}
       
   548 
       
   549 // ---------------------------------------------------------
       
   550 // CLmkDecimalEditor::SetTextToValue
       
   551 // ---------------------------------------------------------
       
   552 //
       
   553 void CLmkDecimalEditor::SetTextToValue(TInt aValue, const CFont& aFont)
       
   554 	{
       
   555 	SetUninitialised(EFalse);
       
   556 	TPtr text=iText->Des();
       
   557 	text.SetLength(0);
       
   558 	if (aValue<0)
       
   559 		{
       
   560 		text.Append('-');
       
   561 		aValue=-aValue;
       
   562 		}
       
   563 	TInt firstUnsetCharacter=text.Length();
       
   564 	text.SetLength(firstUnsetCharacter+MaximumNumberOfDigits());
       
   565 	TInt lastUnsetCharacter=text.Length()-1;
       
   566 	if (aValue==0)
       
   567 		text[lastUnsetCharacter--]=ZeroCharacter();
       
   568 	else
       
   569 		{
       
   570 		for (; aValue; aValue/=10)
       
   571 			text[lastUnsetCharacter--]=(TText)(ZeroCharacter()+(aValue%10));
       
   572 		}
       
   573 	while(iNumberOfZeros--)
       
   574 		{
       
   575 		text[lastUnsetCharacter--]=(TText)(ZeroCharacter());
       
   576 		}
       
   577 	iNumberOfZeros = 0;
       
   578 
       
   579 	if (lastUnsetCharacter>=firstUnsetCharacter)
       
   580 		{
       
   581 		if (iFlags&EFillWithLeadingZeros)
       
   582 			while (lastUnsetCharacter>=firstUnsetCharacter) text[lastUnsetCharacter--]=ZeroCharacter();
       
   583 		else
       
   584 			text.Delete(firstUnsetCharacter, (lastUnsetCharacter+1)-firstUnsetCharacter);
       
   585 		}
       
   586 	if (iFlags&EPreserveOldWidthBeforeEditing)
       
   587 		iMinimumWidthInPixels = WidthInPixels(aFont);
       
   588 	}
       
   589 
       
   590 // ---------------------------------------------------------
       
   591 // CLmkDecimalEditor::ValueFromText
       
   592 // ---------------------------------------------------------
       
   593 //
       
   594 TInt CLmkDecimalEditor::ValueFromText() const
       
   595 	{
       
   596 	if (!NumberOfDigits())
       
   597 		return iMinimumValue;
       
   598 	TInt i=0;
       
   599 	TInt valueFromText=0;
       
   600 	TBool isNegative=EFalse;
       
   601 	switch ((*iText)[i])
       
   602 		{
       
   603 	case '-':
       
   604 		++i;
       
   605 		isNegative=ETrue;
       
   606 		break;
       
   607 		}
       
   608 	TInt textLength=iText->Length();
       
   609 	for (; i<textLength; ++i)
       
   610 		{
       
   611 		TText digit=(*iText)[i];
       
   612 		if (i>=textLength-2)
       
   613 			{
       
   614 			if (!isNegative && valueFromText>(KMaxTInt32/10))
       
   615 				return KMaxTInt32;
       
   616 			else if (isNegative && (-valueFromText)<(KMinTInt32/10))
       
   617 				return KMinTInt32;
       
   618 			}
       
   619 		valueFromText=(valueFromText*10)+(TInt)(digit-ZeroCharacter());
       
   620 		}
       
   621 	if (isNegative==EFalse && valueFromText<0)
       
   622 		return KMaxTInt32;// Deals with overflow
       
   623 	if (isNegative)
       
   624 		valueFromText=-valueFromText;
       
   625 	return valueFromText;
       
   626 	}
       
   627 
       
   628 // ---------------------------------------------------------
       
   629 // CLmkDecimalEditor::ConvertsIntoValidValue
       
   630 // ---------------------------------------------------------
       
   631 //
       
   632 TBool CLmkDecimalEditor::ConvertsIntoValidValue(TInt& aValue) const
       
   633 	{
       
   634 	if ((iFlags&ERepresentsYear) && (aValue>=0) && (aValue<100))
       
   635 		{
       
   636 		TTime homeTime;
       
   637 		homeTime.HomeTime();
       
   638 		TInt currentYear=homeTime.DateTime().Year();
       
   639 		if (currentYear>0)
       
   640 			{
       
   641 			TInt yearsSinceStartOfCurrentCentury=currentYear%100;
       
   642 			TInt newValue=(currentYear-yearsSinceStartOfCurrentCentury)+aValue;
       
   643             // If two digit year is given, 2000 + aValue is expected.
       
   644     		aValue=newValue;
       
   645 			if ((newValue>=iMinimumValue) && (newValue<=iMaximumValue))
       
   646 				{
       
   647 				return ETrue;
       
   648 				}
       
   649 			}
       
   650 		}
       
   651 	return EFalse;
       
   652 	}
       
   653 
       
   654 // ---------------------------------------------------------
       
   655 // CLmkDecimalEditor::SetUninitialised
       
   656 // ---------------------------------------------------------
       
   657 //
       
   658 void CLmkDecimalEditor::SetUninitialised(TBool aUninitialised)
       
   659 	{
       
   660 	if (aUninitialised)
       
   661 		iFlags |= EIsUninitialised;
       
   662 	else
       
   663 		iFlags &= ~EIsUninitialised;
       
   664 	}
       
   665 
       
   666 // ---------------------------------------------------------
       
   667 // CLmkDecimalEditor::IsUninitialised
       
   668 // ---------------------------------------------------------
       
   669 //
       
   670 TBool CLmkDecimalEditor::IsUninitialised() const
       
   671 	{
       
   672 	return iFlags & EIsUninitialised;
       
   673 	}
       
   674 
       
   675 // ---------------------------------------------------------
       
   676 // CLmkDecimalEditor::RefreshDigitType
       
   677 // ---------------------------------------------------------
       
   678 //
       
   679 void CLmkDecimalEditor::RefreshDigitType( const CFont& aFont)
       
   680 	{
       
   681 	SetDigitType( AknTextUtils::NumericEditorDigitType(), aFont);
       
   682 	}
       
   683 
       
   684 // ---------------------------------------------------------
       
   685 // CLmkDecimalEditor::SetDigitType
       
   686 // ---------------------------------------------------------
       
   687 //
       
   688 void CLmkDecimalEditor::SetDigitType(TDigitType aDigitType, const CFont& aFont)
       
   689 	{
       
   690 	TInt value = Value();
       
   691 	iDigitType = aDigitType;
       
   692 	SetTextToValue(value, aFont);
       
   693 	}
       
   694 
       
   695 // ---------------------------------------------------------
       
   696 // CLmkDecimalEditor::DigitType
       
   697 // ---------------------------------------------------------
       
   698 //
       
   699 TDigitType CLmkDecimalEditor::DigitType() const
       
   700 	{
       
   701 	return iDigitType;
       
   702 	}
       
   703