fep/frontendprocessor/test/feps/TFEP1.CPP
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <e32base.h>
       
    23 #include <e32keys.h>
       
    24 #include <s32strm.h>
       
    25 #include <gdi.h>
       
    26 #include <txtfrmat.h>
       
    27 #include <fbs.h>
       
    28 #include <bitstd.h>
       
    29 #include <bitdev.h>
       
    30 #include <w32std.h>
       
    31 #include <frmtlay.h>
       
    32 #include <coemain.h>
       
    33 #include <coeaui.h>
       
    34 #include <coecntrl.h>
       
    35 #include <coefepff.h>
       
    36 #include <fepbase.h>
       
    37 #include <fepitfr.h>
       
    38 #include <techview/eikon.hrh>
       
    39 #include <techview/eikdialg.h>
       
    40 #include <techview/eikchkbx.h>
       
    41 #include <techview/eikbutb.h>
       
    42 #include <techview/eikchlst.h>
       
    43 
       
    44 #include "tfep1.hrh"
       
    45 #include "TFEP1.H"
       
    46 #include "TFEP1COM.H"
       
    47 
       
    48 // constants
       
    49 
       
    50 enum TPanic
       
    51 	{
       
    52 	EPanicBackupAlreadyExists=1,
       
    53 	EPanicBadIndex1,
       
    54 	EPanicBadIndex2,
       
    55 	EPanicNotExpectedToBeSimulatingKeyEvent1,
       
    56 	EPanicNotExpectedToBeSimulatingKeyEvent2,
       
    57 	EPanicBadAttributeUid1,
       
    58 	EPanicBadAttributeUid2,
       
    59 	EPanicBadAttributeUid3,
       
    60 	EPanicBadAttributeUid4,
       
    61 	EPanicBadInputMethod1,
       
    62 	EPanicBadInputMethod2,
       
    63 	EPanicBadInputMethod3,
       
    64 	EPanicBadInputMethod4,
       
    65 	EPanicBadInputMethod5,
       
    66 	EPanicBadTextLength1,
       
    67 	EPanicBadTextLength2,
       
    68 	EPanicBadKeyCode1,
       
    69 	EPanicBadKeyCode2,
       
    70 	EPanicBadKeyCode3,
       
    71 	EPanicBadKeyCode4,
       
    72 	EPanicBadCharacterInBuffer,
       
    73 	EPanicInconsistentState,
       
    74 	EPanicNegativeIndex,
       
    75 	EPanicArithmeticConfusion,
       
    76 	EPanicBadLengthOfTextBeforeSelection,
       
    77 	EPanicSelectionExtendsPastEndOfDocument,
       
    78 	EPanicBadLengthOfTextAfterSelection,
       
    79 	EPanicBadLengthOfSelection,
       
    80 	EPanicBadHeight,
       
    81 	EPanicIsAlreadyActive,
       
    82 	EPanicNoFepAwareTextEditorAlthoughCurrentlyInlineEditing,
       
    83 	EPanicBadKeyResponse,
       
    84 	EPanicUnexpectedButtonId,
       
    85 	EPanicBadCheckBoxState,
       
    86 	EPanicBadNumberOfAttributes
       
    87 	};
       
    88 
       
    89 _LIT(KLitTFEP1, "TFEP1");
       
    90 #if defined(_UNICODE)
       
    91 const TUint KEllipsisCharacter=0x2026;
       
    92 _LIT(KLitCompositionFontTypefaceName, "publicDomainUnicode");
       
    93 #else
       
    94 const TUint KEllipsisCharacter=0x85;
       
    95 _LIT(KLitCompositionFontTypefaceName, "courier");
       
    96 #endif
       
    97 _LIT(KLitStatusFontTypefaceName, "arial");
       
    98 _LIT(KLitNoFocusedFepAwareTextEditor, "No focused FEP-aware text-editor");
       
    99 _LIT(KLitNoFocusedFepAwareTextEditorSupportingState, "No focused FEP-aware text-editor supporting state");
       
   100 _LIT(KLitNotAvailable, "[not available]");
       
   101 //_LIT(KLitTooLong, "[too long]");
       
   102 _LIT(KLitQuotationMark, "\"");
       
   103 _LIT(KLitTextBeforeSelectionColonSpace, "Text before selection: ");
       
   104 _LIT(KLitTextAfterSelectionColonSpace, "Text after selection: ");
       
   105 _LIT(KLitSelectionColonSpace, "Selection: ");
       
   106 _LIT(KLitInputMethodColonSpace, "Input method: ");
       
   107 _LIT(KLitPlain, "plain");
       
   108 _LIT(KLitHexadecimalCharacterCode, "hexadecimal character-code");
       
   109 _LIT(KLitInlineEditingColonSpace, "Inline editing: ");
       
   110 _LIT(KLitEnabled, "enabled");
       
   111 _LIT(KLitDisabled, "disabled");
       
   112 _LIT(KLitOpeningSquareBracket, "[");
       
   113 _LIT(KLitCaptionColonSpace, "Caption: ");
       
   114 _LIT(KLitStateColonSpace, "State: ");
       
   115 _LIT(KLitInputCapabilitiesColonSpace, "Input-capabilities: ");
       
   116 _LIT(KLitNone, "none");
       
   117 _LIT(KLitWesternNumericIntegerPositive, "Western numeric integer positive");
       
   118 _LIT(KLitWesternNumericIntegerNegative, "Western numeric integer negative");
       
   119 _LIT(KLitWesternNumericReal, "Western numeric real");
       
   120 _LIT(KLitWesternAlphabetic, "Western alphabetic");
       
   121 _LIT(KLitJapaneseHiragana, "Japanese hiragana");
       
   122 _LIT(KLitJapaneseKatakanaHalfWidth, "Japanese katakana half-width");
       
   123 _LIT(KLitJapaneseKatakanaFullWidth, "Japanese katakana full-width");
       
   124 _LIT(KLitDialableCharacters, "dialable characters");
       
   125 _LIT(KLitSecretText, "secret text");
       
   126 _LIT(KLitAllText, "all text");
       
   127 _LIT(KLitNavigation, "navigation");
       
   128 _LIT(KLitExtensionsColonSpace, "extensions: ");
       
   129 _LIT(KLitPhoneticAlphabet, "phonetic alphabet");
       
   130 _LIT(KLitCommaSpace, ", ");
       
   131 _LIT(KLitClosingSquareBracket, "]");
       
   132 
       
   133 LOCAL_D const TText* const KPhoneticAlphabet[]=
       
   134 	{
       
   135 	_S("Alpha"),
       
   136 	_S("Bravo"),
       
   137 	_S("Charlie"),
       
   138 	_S("Delta"),
       
   139 	_S("Echo"),
       
   140 	_S("Foxtrot"),
       
   141 	_S("Golf"),
       
   142 	_S("Hotel"),
       
   143 	_S("India"),
       
   144 	_S("Juliette"),
       
   145 	_S("Kilo"),
       
   146 	_S("Lima"),
       
   147 	_S("Mike"),
       
   148 	_S("November"),
       
   149 	_S("Oscar"),
       
   150 	_S("Papa"),
       
   151 	_S("Quebec"),
       
   152 	_S("Romeo"),
       
   153 	_S("Sierra"),
       
   154 	_S("Tango"),
       
   155 	_S("Uniform"),
       
   156 	_S("Victor"),
       
   157 	_S("Whiskey"),
       
   158 	_S("X-Ray"),
       
   159 	_S("Yankee"),
       
   160 	_S("Zulu")
       
   161 	};
       
   162 
       
   163 // local and global functions
       
   164 
       
   165 LOCAL_C void Panic(TPanic aPanic)
       
   166 	{
       
   167 	User::Panic(KLitTFEP1, aPanic);
       
   168 	}
       
   169 
       
   170 GLDEF_C TInt E32Dll(
       
   171 					)
       
   172 	{
       
   173 	return KErrNone;
       
   174 	}
       
   175 
       
   176 // TTstTextBackup
       
   177 
       
   178 #pragma warning(disable: 4355) // "'this' : used in base member initializer list"
       
   179 
       
   180 TTstTextBackup::TTstTextBackup(TDes& aText)
       
   181 	:iCleanupItem(Cleanup, this),
       
   182 	 iOriginal(aText),
       
   183 	 iBackup(NULL)
       
   184 	{
       
   185 	}
       
   186 
       
   187 #pragma warning(default: 4355)
       
   188 
       
   189 void TTstTextBackup::PushOntoCleanupStackL()
       
   190 	{
       
   191 	__ASSERT_DEBUG(iBackup==NULL, Panic(EPanicBackupAlreadyExists));
       
   192 	iBackup=iOriginal.AllocL();
       
   193 	CleanupStack::PushL(iCleanupItem);
       
   194 	}
       
   195 
       
   196 void TTstTextBackup::PopOffCleanupStack()
       
   197 	{
       
   198 	delete iBackup;
       
   199 	CleanupStack::Pop();
       
   200 	}
       
   201 
       
   202 void TTstTextBackup::Cleanup(TAny* aTextBackup)
       
   203 	{
       
   204 	TTstTextBackup* const textBackup=STATIC_CAST(TTstTextBackup*, aTextBackup);
       
   205 	textBackup->iOriginal=*textBackup->iBackup;
       
   206 	delete textBackup->iBackup;
       
   207 	}
       
   208 
       
   209 // CTstInsertionPoint
       
   210 
       
   211 CTstInsertionPoint* CTstInsertionPoint::NewL(RWindowBase& aWindow, CCoeEnv& aConeEnvironment)
       
   212 	{
       
   213 	CTstInsertionPoint* const insertionPoint=new(ELeave) CTstInsertionPoint(aConeEnvironment.WsSession());
       
   214 	CleanupStack::PushL(insertionPoint);
       
   215 	insertionPoint->ConstructL(aWindow, aConeEnvironment.ScreenDevice()->DisplayMode());
       
   216 	CleanupStack::Pop(); // insertionPoint
       
   217 	return insertionPoint;
       
   218 	}
       
   219 
       
   220 CTstInsertionPoint::~CTstInsertionPoint()
       
   221 	{
       
   222 	iSprite.Close();
       
   223 	delete iSpriteMember.iBitmap; // must be deleted after iSprite is closed as iSprite has a reference to it
       
   224 	// iSpriteMember.iMaskBitmap is not deleted as it is the same as iSpriteMember.iBitmap
       
   225 	}
       
   226 
       
   227 void CTstInsertionPoint::SetPosition(const TPoint& aPosition)
       
   228 	{
       
   229 	iPosition=aPosition;
       
   230 	if (iFlags&EFlagOn)
       
   231 		{
       
   232 		iSprite.SetPosition(iPosition);
       
   233 		}
       
   234 	}
       
   235 
       
   236 void CTstInsertionPoint::SetOn(TBool aOn)
       
   237 	{
       
   238 	if (!aOn!=!(iFlags&EFlagOn)) // fold non-zero values on both sides before comparing for inequality
       
   239 		{
       
   240 		DoSetOn(aOn);
       
   241 		}
       
   242 	}
       
   243 
       
   244 CTstInsertionPoint::CTstInsertionPoint(RWsSession& aWindowServerSession)
       
   245 	:iSprite(aWindowServerSession),
       
   246 	 iPosition(0, 0),
       
   247 	 iFlags(0)
       
   248 	{
       
   249 	iSpriteMember.iBitmap=NULL;
       
   250 	iSpriteMember.iMaskBitmap=NULL;
       
   251 	}
       
   252 
       
   253 void CTstInsertionPoint::ConstructL(RWindowBase& aWindow, TDisplayMode aDisplayMode)
       
   254 	{
       
   255 	iSpriteMember.iBitmap=CreateBitmapL(aDisplayMode);
       
   256 	iSpriteMember.iMaskBitmap=iSpriteMember.iBitmap;
       
   257 	iSpriteMember.iInvertMask=ETrue;
       
   258 	iSpriteMember.iDrawMode=CGraphicsContext::EDrawModePEN;
       
   259 	iSpriteMember.iOffset.iX=-(CTstInsertionPoint::EWidth/2);
       
   260 	iSpriteMember.iOffset.iY=0;
       
   261 	iSpriteMember.iInterval=0;
       
   262 	User::LeaveIfError(iSprite.Construct(aWindow, iPosition, 0));
       
   263 	User::LeaveIfError(iSprite.AppendMember(iSpriteMember));
       
   264 	DoSetOn(EFalse);
       
   265 	User::LeaveIfError(iSprite.Activate());
       
   266 	}
       
   267 
       
   268 CFbsBitmap* CTstInsertionPoint::CreateBitmapL(TDisplayMode aDisplayMode)
       
   269 	{
       
   270 	CFbsBitmap* const bitmap=new(ELeave) CFbsBitmap;
       
   271 	CleanupStack::PushL(bitmap);
       
   272 	User::LeaveIfError(bitmap->Create(TSize(CTstInsertionPoint::EWidth, CTstInsertionPoint::EHeight), aDisplayMode));
       
   273 	CFbsBitmapDevice* const bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
       
   274 	CleanupStack::PushL(bitmapDevice);
       
   275 	CFbsBitGc* const graphicsContext=CFbsBitGc::NewL();
       
   276 	CleanupStack::PushL(graphicsContext);
       
   277 	graphicsContext->Activate(bitmapDevice);
       
   278 	graphicsContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   279 	graphicsContext->SetBrushColor(KRgbWhite);
       
   280 	graphicsContext->SetPenStyle(CGraphicsContext::ESolidPen);
       
   281 	graphicsContext->SetPenColor(KRgbBlack);
       
   282 	graphicsContext->Clear();
       
   283 	const TPoint bottomLeft(0, CTstInsertionPoint::EHeight-1);
       
   284 	const TPoint bottomRight(CTstInsertionPoint::EWidth-1, CTstInsertionPoint::EHeight-1);
       
   285 	const TPoint top(CTstInsertionPoint::EWidth/2, 0);
       
   286 	graphicsContext->DrawLine(bottomLeft, bottomRight);
       
   287 	graphicsContext->DrawLine(bottomRight, top);
       
   288 	graphicsContext->DrawLine(top, bottomLeft);
       
   289 	CleanupStack::PopAndDestroy(2); // graphicsContext and bitmapDevice
       
   290 	CleanupStack::Pop(); // bitmap
       
   291 	return bitmap;
       
   292 	}
       
   293 
       
   294 void CTstInsertionPoint::DoSetOn(TBool aOn)
       
   295 	{
       
   296 	iSprite.SetPosition(aOn? iPosition: TPoint(-(EWidth*4), -(EHeight*4)));
       
   297 	if (aOn)
       
   298 		{
       
   299 		iFlags|=EFlagOn;
       
   300 		}
       
   301 	else
       
   302 		{
       
   303 		iFlags&=~EFlagOn;
       
   304 		}
       
   305 	}
       
   306 
       
   307 // TTstArrayOfOneCtrlCharacter
       
   308 
       
   309 TTstArrayOfOneCtrlCharacter::TTstArrayOfOneCtrlCharacter(TUint aCharacter)
       
   310 	:iCharacter(aCharacter)
       
   311 	{
       
   312 	}
       
   313 
       
   314 TArray<CCoeFep::MModifiedCharacter> TTstArrayOfOneCtrlCharacter::ArrayOfModifiedCharacters()
       
   315 	{
       
   316 	return TArray<CCoeFep::MModifiedCharacter>(NumberOfModifiedCharacters, ModifiedCharacter, (const CBase*)this);
       
   317 	}
       
   318 
       
   319 TInt TTstArrayOfOneCtrlCharacter::NumberOfModifiedCharacters(const CBase*)
       
   320 	{
       
   321 	return 1;
       
   322 	}
       
   323 
       
   324 const TAny* TTstArrayOfOneCtrlCharacter::ModifiedCharacter(const CBase* aThis, TInt aIndex)
       
   325 	{
       
   326 	__ASSERT_ALWAYS(aIndex==0, Panic(EPanicBadIndex1));
       
   327 	return aThis;
       
   328 	}
       
   329 
       
   330 TUint TTstArrayOfOneCtrlCharacter::CharacterCode() const
       
   331 	{
       
   332 	return iCharacter;
       
   333 	}
       
   334 
       
   335 TUint TTstArrayOfOneCtrlCharacter::ModifierMask() const
       
   336 	{
       
   337 	return EModifierCtrl|EModifierShift|EModifierLeftShift|EModifierRightShift;
       
   338 	}
       
   339 
       
   340 TUint TTstArrayOfOneCtrlCharacter::ModifierValues() const
       
   341 	{
       
   342 	return EModifierCtrl;
       
   343 	}
       
   344 
       
   345 // CTstControl
       
   346 
       
   347 CTstControl* CTstControl::NewL(CTstFep& aFep)
       
   348 	{
       
   349 	CTstControl* const control=new(ELeave) CTstControl(aFep);
       
   350 	CleanupStack::PushL(control);
       
   351 	control->ConstructL();
       
   352 	CleanupStack::Pop(); // control
       
   353 	return control;
       
   354 	}
       
   355 
       
   356 CTstControl::~CTstControl()
       
   357 	{
       
   358 	if (iFlags&EFlagInsideInlineEditingTransaction)
       
   359 		{
       
   360 		CancelInlineEdit(*iInputCapabilities.FepAwareTextEditor());
       
   361 		}
       
   362 	iCoeEnv->ReleaseScreenFont(iCompositionFont);
       
   363 	iCoeEnv->ReleaseScreenFont(iStatusFont);
       
   364 	STATIC_CAST(CCoeAppUi*, iCoeEnv->AppUi())->RemoveFromStack(this);
       
   365 	delete iInsertionPoint;
       
   366 	}
       
   367 
       
   368 void CTstControl::CancelTransaction()
       
   369 	{
       
   370 	__ASSERT_DEBUG(!iFep.IsSimulatingKeyEvent() || ((~iFlags&EFlagInsideInlineEditingTransaction) && (iBuffer.Length()==0)), Panic(EPanicNotExpectedToBeSimulatingKeyEvent1));
       
   371 	TBool needToDraw=EFalse;
       
   372 	if (iFlags&EFlagInsideInlineEditingTransaction)
       
   373 		{
       
   374 		CancelInlineEdit(*iInputCapabilities.FepAwareTextEditor());
       
   375 		needToDraw=ETrue;
       
   376 		}
       
   377 	if (iBuffer.Length()>0)
       
   378 		{
       
   379 		ResetBuffer();
       
   380 		needToDraw=ETrue;
       
   381 		}
       
   382 	if (needToDraw)
       
   383 		{
       
   384 		DrawNow();
       
   385 		}
       
   386 	}
       
   387 
       
   388 void CTstControl::IsOnHasChangedState()
       
   389 	{
       
   390 	ChangeSetupAndResetBufferAndDrawNow(NULL);
       
   391 	}
       
   392 
       
   393 void CTstControl::OfferPointerEventL(CCoeFep::TEventResponse& aEventResponse, const TPointerEvent& aPointerEvent, const CCoeControl* aWindowOwningControl)
       
   394 	{
       
   395 	// this function must correctly set aEventResponse *before* calling anything that can leave
       
   396 	if (aWindowOwningControl==this)
       
   397 		{
       
   398 		aEventResponse=CCoeFep::EEventWasConsumed;
       
   399 		HandlePointerEventL(aPointerEvent);
       
   400 		}
       
   401 	else
       
   402 		{
       
   403 		aEventResponse=CCoeFep::EEventWasNotConsumed;
       
   404 		}
       
   405 	}
       
   406 
       
   407 TInt CTstControl::NumberOfAttributes()
       
   408 	{
       
   409 	return 2;
       
   410 	}
       
   411 
       
   412 TUid CTstControl::AttributeAtIndex(TInt aIndex)
       
   413 	{
       
   414 	switch (aIndex)
       
   415 		{
       
   416 	case 0:
       
   417 		return TUid::Uid(ETstInlineEditingEnabledUid);
       
   418 	case 1:
       
   419 		return TUid::Uid(ETstInputMethodUid);
       
   420 #if defined(_DEBUG)
       
   421 	default:
       
   422 		Panic(EPanicBadIndex2);
       
   423 		break;
       
   424 #endif
       
   425 		}
       
   426 	return KNullUid;
       
   427 	}
       
   428 
       
   429 void CTstControl::WriteAttributeDataToStreamL(TUid aAttributeUid, RWriteStream& aStream) const
       
   430 	{
       
   431 	switch (aAttributeUid.iUid)
       
   432 		{
       
   433 	case ETstInlineEditingEnabledUid:
       
   434 		aStream.WriteUint8L((iFlags&EFlagInlineEditingEnabled)!=0);
       
   435 		break;
       
   436 	case ETstInputMethodUid:
       
   437 		aStream.WriteUint8L(iInputMethod);
       
   438 		break;
       
   439 #if defined(_DEBUG)
       
   440 	default:
       
   441 		Panic(EPanicBadAttributeUid1);
       
   442 		break;
       
   443 #endif
       
   444 		}
       
   445 	}
       
   446 
       
   447 void CTstControl::ReadAttributeDataFromStreamL(TUid aAttributeUid, RReadStream& aStream)
       
   448 	{
       
   449 	switch (aAttributeUid.iUid)
       
   450 		{
       
   451 	case ETstInlineEditingEnabledUid:
       
   452 		ChangeSetupAndResetBufferAndDrawNow(SetFlagInlineEditingEnabled, aStream.ReadUint8L());
       
   453 		break;
       
   454 	case ETstInputMethodUid:
       
   455 		{
       
   456 		TInt inputMethod=aStream.ReadUint8L();
       
   457 		if ((inputMethod!=EInputMethodPlain) && (inputMethod!=EInputMethodHexadecimalCharacterCode))
       
   458 			{
       
   459 			User::Leave(KErrCorrupt);
       
   460 			}
       
   461 		ChangeSetupAndResetBufferAndDrawNow(SetInputMethod, inputMethod);
       
   462 		}
       
   463 		break;
       
   464 #if defined(_DEBUG)
       
   465 	default:
       
   466 		Panic(EPanicBadAttributeUid2);
       
   467 		break;
       
   468 #endif
       
   469 		}
       
   470 	}
       
   471 
       
   472 void CTstControl::WriteAttributeDataToStreamL(TUid aAttributeUid, RWriteStream& aStream, TBool aInlineEditingEnabled, TInt aInputMethod)
       
   473 	{
       
   474 	switch (aAttributeUid.iUid)
       
   475 		{
       
   476 	case ETstInlineEditingEnabledUid:
       
   477 		aStream.WriteUint8L(aInlineEditingEnabled!=EFalse);
       
   478 		break;
       
   479 	case ETstInputMethodUid:
       
   480 		aStream.WriteUint8L(aInputMethod);
       
   481 		break;
       
   482 #if defined(_DEBUG)
       
   483 	default:
       
   484 		Panic(EPanicBadAttributeUid3);
       
   485 		break;
       
   486 #endif
       
   487 		}
       
   488 	}
       
   489 
       
   490 void CTstControl::ReadAttributeDataFromStreamL(TUid aAttributeUid, RReadStream& aStream, TBool& aInlineEditingEnabled, TInt& aInputMethod)
       
   491 	{
       
   492 	switch (aAttributeUid.iUid)
       
   493 		{
       
   494 	case ETstInlineEditingEnabledUid:
       
   495 		aInlineEditingEnabled=aStream.ReadUint8L();
       
   496 		break;
       
   497 	case ETstInputMethodUid:
       
   498 		aInputMethod=aStream.ReadUint8L();
       
   499 		break;
       
   500 #if defined(_DEBUG)
       
   501 	default:
       
   502 		Panic(EPanicBadAttributeUid4);
       
   503 		break;
       
   504 #endif
       
   505 		}
       
   506 	}
       
   507 
       
   508 void CTstControl::HandleGainingForeground()
       
   509 	{
       
   510 	DrawableWindow()->MoveToGroup(iCoeEnv->WsSession().GetFocusWindowGroup()); // ignore the error returned
       
   511 	ChangeSetupAndResetBufferAndDrawNow(SetForeground, ETrue);
       
   512 	}
       
   513 
       
   514 void CTstControl::HandleLosingForeground()
       
   515 	{
       
   516 	ChangeSetupAndResetBufferAndDrawNow(SetForeground, EFalse);
       
   517 	}
       
   518 
       
   519 void CTstControl::HandleChangeInFocus()
       
   520 	{
       
   521 	ChangeSetupAndResetBufferAndDrawNow(SetInputCapabilities, NULL);
       
   522 	}
       
   523 
       
   524 void CTstControl::HandleDestructionOfFocusedItem()
       
   525 	{
       
   526 	if (!IsBeingDestroyed())
       
   527 		{
       
   528 		const TCoeInputCapabilities inputCapabilities(STATIC_CAST(const CCoeAppUi*, iCoeEnv->AppUi())->InputCapabilities());
       
   529 		if (inputCapabilities.FepAwareTextEditor()==NULL)
       
   530 			{
       
   531 			iFlags&=~EFlagInsideInlineEditingTransaction; // turn this off now so that ChangeSetupAndResetBufferAndDrawNow does not try to call CancelInlineEdit on an object that has probably been destroyed by now
       
   532 			}
       
   533 		ChangeSetupAndResetBufferAndDrawNow(SetInputCapabilities, REINTERPRET_CAST(TInt, &inputCapabilities));
       
   534 		}
       
   535 	}
       
   536 
       
   537 CTstControl::CTstControl(CTstFep& aFep)
       
   538 	:iFep(aFep),
       
   539 	 iInputMethod(EInputMethodPlain),
       
   540 	 iFlags(0),
       
   541 	 iBuffer(KNullDesC),
       
   542 	 iSelectedCompositionText(0, 0),
       
   543 	 iInputCapabilities(TCoeInputCapabilities::ENone),
       
   544 	 iCompositionFont(NULL),
       
   545 	 iStatusFont(NULL),
       
   546 	 iInsertionPoint(NULL),
       
   547 	 iPositionOnWindowBeingDragged(0, 0)
       
   548 	{
       
   549 	}
       
   550 
       
   551 void CTstControl::ConstructL()
       
   552 	{
       
   553 	CreateWindowL();
       
   554 	EnableDragEvents();
       
   555 	ClaimPointerGrab();
       
   556 	SetNonFocusing();
       
   557 	RDrawableWindow& window=*DrawableWindow();
       
   558 	window.SetOrdinalPosition(0, ECoeWinPriorityFep);
       
   559 	window.SetShadowHeight(3);
       
   560 	TFontSpec compositionFontSpec(KLitCompositionFontTypefaceName, 200);
       
   561 	compositionFontSpec.iTypeface.SetIsProportional(EFalse);
       
   562 	iCompositionFont=iCoeEnv->CreateScreenFontL(compositionFontSpec);
       
   563 	iStatusFont=iCoeEnv->CreateScreenFontL(TFontSpec(KLitStatusFontTypefaceName, 120));
       
   564 	iInsertionPoint=CTstInsertionPoint::NewL(window, *iCoeEnv);
       
   565 	SetPositionOfInsertionPointInBuffer(0);
       
   566 	const TInt statusFontHeightInPixels=iStatusFont->HeightInPixels();
       
   567 	const TSize size(320, 1+EGapAboveCompositionLine+iCompositionFont->HeightInPixels()+EGapBelowCompositionLine+EGapAboveTopStatusLine+(4*(statusFontHeightInPixels+EGapBetweenEachStatusLine))+statusFontHeightInPixels+EGapBelowBottomStatusLine+1);
       
   568 	const TSize screenSize(iCoeEnv->ScreenDevice()->SizeInPixels());
       
   569 	SetExtent(TPoint(screenSize.iWidth-(size.iWidth+10), screenSize.iHeight-(size.iHeight+10)), size);
       
   570 	STATIC_CAST(CCoeAppUi*, iCoeEnv->AppUi())->AddToStackL(this, ECoeStackPriorityFep, ECoeStackFlagRefusesFocus|ECoeStackFlagSharable);
       
   571 	ChangeSetupAndResetBufferAndDrawNow(SetForeground, iCoeEnv->RootWin().Identifier()==iCoeEnv->WsSession().GetFocusWindowGroup());
       
   572 	ChangeSetupAndResetBufferAndDrawNow(SetFocus, EFalse);
       
   573 	ChangeSetupAndResetBufferAndDrawNow(SetFlagInlineEditingEnabled, ETrue);
       
   574 	ChangeSetupAndResetBufferAndDrawNow(SetInputMethod, EInputMethodPlain);
       
   575 	ChangeSetupAndResetBufferAndDrawNow(SetInputCapabilities, NULL);
       
   576 	}
       
   577 
       
   578 void CTstControl::SetForeground(CTstControl& aControl, TBool& aChangeWasMade, TInt aParameter)
       
   579 	{
       
   580 	SetFlag(aControl, aChangeWasMade, aParameter, EFlagForeground);
       
   581 	}
       
   582 
       
   583 void CTstControl::SetFocus(CTstControl& aControl, TBool& aChangeWasMade, TInt aParameter)
       
   584 	{
       
   585 	aChangeWasMade=EFalse;
       
   586 	if (!aParameter!=!aControl.IsFocused()) // fold non-zero values on both sides before comparing for inequality
       
   587 		{
       
   588 		CCoeAppUi& appUi=*STATIC_CAST(CCoeAppUi*, aControl.iCoeEnv->AppUi());
       
   589 		appUi.UpdateStackedControlFlags(&aControl, (aParameter? 0: ECoeStackFlagRefusesFocus), ECoeStackFlagRefusesFocus);
       
   590 		appUi.HandleStackChanged();
       
   591 		aChangeWasMade=ETrue;
       
   592 		TBool notUsed;
       
   593 		SetInputCapabilities(aControl, notUsed, NULL);
       
   594 		}
       
   595 	}
       
   596 
       
   597 void CTstControl::SetFlagInlineEditingEnabled(CTstControl& aControl, TBool& aChangeWasMade, TInt aParameter)
       
   598 	{
       
   599 	SetFlag(aControl, aChangeWasMade, aParameter, EFlagInlineEditingEnabled);
       
   600 	}
       
   601 
       
   602 void CTstControl::SetInputMethod(CTstControl& aControl, TBool& aChangeWasMade, TInt aParameter)
       
   603 	{
       
   604 	__ASSERT_DEBUG((aParameter==EInputMethodPlain) || (aParameter==EInputMethodHexadecimalCharacterCode), Panic(EPanicBadInputMethod1));
       
   605 	aChangeWasMade=EFalse;
       
   606 	if (aControl.iInputMethod!=aParameter)
       
   607 		{
       
   608 		aControl.iInputMethod=aParameter;
       
   609 		aChangeWasMade=ETrue;
       
   610 		}
       
   611 	}
       
   612 
       
   613 void CTstControl::SetInputCapabilities(CTstControl& aControl, TBool& aChangeWasMade, TInt aParameter)
       
   614 	{
       
   615 	aChangeWasMade=EFalse;
       
   616 	TCoeInputCapabilities inputCapabilities(TCoeInputCapabilities::ENone);
       
   617 	if (!aControl.IsFocused())
       
   618 		{
       
   619 		inputCapabilities=(aParameter!=NULL)? *REINTERPRET_CAST(const TCoeInputCapabilities*, aParameter): STATIC_CAST(const CCoeAppUi*, aControl.iCoeEnv->AppUi())->InputCapabilities();
       
   620 		}
       
   621 	if (aControl.iInputCapabilities!=inputCapabilities)
       
   622 		{
       
   623 		aControl.iInputCapabilities=inputCapabilities;
       
   624 		aChangeWasMade=ETrue;
       
   625 		}
       
   626 	}
       
   627 
       
   628 void CTstControl::SetFlag(CTstControl& aControl, TBool& aChangeWasMade, TInt aParameter, TUint aFlag)
       
   629 	{
       
   630 	aChangeWasMade=EFalse;
       
   631 	if (!aParameter!=!(aControl.iFlags&aFlag)) // fold non-zero values on both sides before comparing for inequality
       
   632 		{
       
   633 		aControl.iFlags^=aFlag;
       
   634 		aChangeWasMade=ETrue;
       
   635 		}
       
   636 	}
       
   637 
       
   638 void CTstControl::ChangeSetupAndResetBufferAndDrawNow(FChangeFunction aChangeFunction, TInt aParameter)
       
   639 	{
       
   640 	__ASSERT_DEBUG(!iFep.IsSimulatingKeyEvent() || ((~iFlags&EFlagInsideInlineEditingTransaction) && (iBuffer.Length()==0)), Panic(EPanicNotExpectedToBeSimulatingKeyEvent2));
       
   641 	TBool needToDraw=EFalse;
       
   642 	if (iFlags&EFlagInsideInlineEditingTransaction)
       
   643 		{
       
   644 		CancelInlineEdit(*iInputCapabilities.FepAwareTextEditor());
       
   645 		needToDraw=ETrue;
       
   646 		}
       
   647 	if (aChangeFunction!=NULL)
       
   648 		{
       
   649 		TBool changeWasMade;
       
   650 		(*aChangeFunction)(*this, changeWasMade, aParameter);
       
   651 		if (changeWasMade)
       
   652 			{
       
   653 			needToDraw=ETrue;
       
   654 			}
       
   655 		}
       
   656 	if (iBuffer.Length()>0)
       
   657 		{
       
   658 		ResetBuffer();
       
   659 		needToDraw=ETrue;
       
   660 		}
       
   661 	const TBool potentiallyInlineEditing=((iInputCapabilities.FepAwareTextEditor()!=NULL) && (iFlags&EFlagInlineEditingEnabled)); // iInputCapabilities.FepAwareTextEditor may return a different value here to the call at the start of the function, hence the need to call it again
       
   662 	iInsertionPoint->SetOn(!IsFocused() && !potentiallyInlineEditing);
       
   663 	if (!potentiallyInlineEditing!=!(iFlags&EFlagHasNoCompositionWindow)) // fold non-zero values on both sides before comparing for inequality
       
   664 		{
       
   665 		const TInt heightOfCompositionWindow=EGapAboveCompositionLine+iCompositionFont->HeightInPixels()+EGapBelowCompositionLine;
       
   666 		TInt windowAdjustmentY;
       
   667 		if (potentiallyInlineEditing)
       
   668 			{
       
   669 			windowAdjustmentY=heightOfCompositionWindow;
       
   670 			iFlags|=EFlagHasNoCompositionWindow;
       
   671 			}
       
   672 		else
       
   673 			{
       
   674 			windowAdjustmentY=-heightOfCompositionWindow;
       
   675 			iFlags&=~EFlagHasNoCompositionWindow;
       
   676 			}
       
   677 		TRect rectangle(Position(), Size()); // creating rectangle from Rect() will give the wrong result as this control owns a window (its top left position would come out as TPoint(0, 0) rather than what Position() returns)
       
   678 		rectangle.iTl.iY+=windowAdjustmentY;
       
   679 		SetRect(rectangle);
       
   680 		needToDraw=ETrue;
       
   681 		}
       
   682 	const TBool shouldBeVisible=(iFep.IsOn() && (iFlags&EFlagForeground));
       
   683 	if (!IsVisible()!=!shouldBeVisible) // fold non-zero values on both sides before comparing for inequality
       
   684 		{
       
   685 		MakeVisible(shouldBeVisible);
       
   686 		needToDraw=EFalse;
       
   687 		}
       
   688 	if (needToDraw)
       
   689 		{
       
   690 		DrawNow();
       
   691 		}
       
   692 	}
       
   693 
       
   694 void CTstControl::InsertCompositionCharacterAndDrawNowL(TUint aCharacterCode)
       
   695 	{
       
   696 	const TInt positionOfNewText=iSelectedCompositionText.LowerPos();
       
   697 	if (positionOfNewText<EMaximumLengthOfBuffer)
       
   698 		{
       
   699 		TTstTextBackup textBackup=iBuffer;
       
   700 		textBackup.PushOntoCleanupStackL();
       
   701 		const TCoeInputCapabilities::MCoeFepSpecificExtensions* fepSpecificInputCapabilityExtensions=iInputCapabilities.FepSpecificExtensions(TUid::Uid(KTfep1Uid));
       
   702 		const TUint upperCaseCharacterCode=User::UpperCase(aCharacterCode);
       
   703 		TPtrC textToInsert;
       
   704 		TBuf<1> buffer;
       
   705 		TInt newPositionOfInsertionPointInBuffer=positionOfNewText;
       
   706 		if ((iInputMethod==EInputMethodPlain) && (fepSpecificInputCapabilityExtensions!=NULL) && fepSpecificInputCapabilityExtensions->SupportsPhoneticAlphabet() && (upperCaseCharacterCode>='A') && (upperCaseCharacterCode<='Z'))
       
   707 			{
       
   708 			textToInsert.Set(TPtrC(KPhoneticAlphabet[upperCaseCharacterCode-'A']));
       
   709 			const TInt lengthOfRoomForTextToInsert=EMaximumLengthOfBuffer-positionOfNewText;
       
   710 			if (textToInsert.Length()>lengthOfRoomForTextToInsert)
       
   711 				{
       
   712 				textToInsert.Set(textToInsert.Left(lengthOfRoomForTextToInsert));
       
   713 				}
       
   714 			newPositionOfInsertionPointInBuffer+=textToInsert.Length();
       
   715 			}
       
   716 		else
       
   717 			{
       
   718 			buffer.Append(aCharacterCode);
       
   719 			textToInsert.Set(buffer);
       
   720 			++newPositionOfInsertionPointInBuffer;
       
   721 			}
       
   722 		iBuffer.Delete(positionOfNewText, iSelectedCompositionText.Length());
       
   723 		const TInt lengthToDeleteToMakeRoom=textToInsert.Length()-(EMaximumLengthOfBuffer-iBuffer.Length());
       
   724 		if (lengthToDeleteToMakeRoom>0)
       
   725 			{
       
   726 			iBuffer.Delete(iBuffer.Length()-lengthToDeleteToMakeRoom, lengthToDeleteToMakeRoom);
       
   727 			}
       
   728 		iBuffer.Insert(positionOfNewText, textToInsert);
       
   729 		__ASSERT_DEBUG((iInputMethod==EInputMethodPlain) || (iInputMethod==EInputMethodHexadecimalCharacterCode), Panic(EPanicBadInputMethod4));
       
   730 		if (iInputMethod==EInputMethodHexadecimalCharacterCode)
       
   731 			{
       
   732 			if (newPositionOfInsertionPointInBuffer>=ENumberOfHexadecimalDigitsPerCharacterCode)
       
   733 				{
       
   734 				TUint characterCode=0;
       
   735 				for (TInt i=ENumberOfHexadecimalDigitsPerCharacterCode; ; --i)
       
   736 					{
       
   737 					if (i<=0)
       
   738 						{
       
   739 						const TInt positionToInsertCharacterCode=newPositionOfInsertionPointInBuffer-ENumberOfHexadecimalDigitsPerCharacterCode;
       
   740 						iBuffer.Delete(positionToInsertCharacterCode, ENumberOfHexadecimalDigitsPerCharacterCode-1);
       
   741 						iBuffer[positionToInsertCharacterCode]=(TText)characterCode;
       
   742 						newPositionOfInsertionPointInBuffer-=ENumberOfHexadecimalDigitsPerCharacterCode-1;
       
   743 						break;
       
   744 						}
       
   745 					const TCharUC hexadecimalDigit=iBuffer[newPositionOfInsertionPointInBuffer-i];
       
   746 					characterCode*=16;
       
   747 					if ((hexadecimalDigit>='0') && (hexadecimalDigit<='9'))
       
   748 						{
       
   749 						characterCode+=hexadecimalDigit-'0';
       
   750 						}
       
   751 					else if ((hexadecimalDigit>='A') && (hexadecimalDigit<='F'))
       
   752 						{
       
   753 						characterCode+=(hexadecimalDigit-'A')+10;
       
   754 						}
       
   755 					else
       
   756 						{
       
   757 						break;
       
   758 						}
       
   759 					}
       
   760 				}
       
   761 			}
       
   762 		SetPositionOfInsertionPointInBuffer(newPositionOfInsertionPointInBuffer);
       
   763 		MCoeFepAwareTextEditor* const fepAwareTextEditor=iInputCapabilities.FepAwareTextEditor();
       
   764 		if ((fepAwareTextEditor==NULL) || !(iFlags&EFlagInlineEditingEnabled))
       
   765 			{
       
   766 			DrawNow();
       
   767 			}
       
   768 		else
       
   769 			{
       
   770 			SetInlineTextL(*fepAwareTextEditor);
       
   771 			}
       
   772 		textBackup.PopOffCleanupStack();
       
   773 		}
       
   774 	} // positionOfNewText newPositionOfInsertionPointInBuffer iCursorPos
       
   775 
       
   776 void CTstControl::SetInlineTextL(MCoeFepAwareTextEditor& aFepAwareTextEditor)
       
   777 	{
       
   778 	if (iFlags&EFlagInsideInlineEditingTransaction)
       
   779 		{
       
   780 		aFepAwareTextEditor.UpdateFepInlineTextL(iBuffer, iSelectedCompositionText.iCursorPos);
       
   781 		}
       
   782 	else
       
   783 		{
       
   784 		aFepAwareTextEditor.StartFepInlineEditL(iBuffer, iSelectedCompositionText.iCursorPos, ETrue, this, *this, *this);
       
   785 		iFlags|=EFlagInsideInlineEditingTransaction;
       
   786 		}
       
   787 	}
       
   788 
       
   789 void CTstControl::CancelInlineEdit(MCoeFepAwareTextEditor& aFepAwareTextEditor)
       
   790 	{
       
   791 	aFepAwareTextEditor.CancelFepInlineEdit();
       
   792 	iFlags&=~EFlagInsideInlineEditingTransaction;
       
   793 	}
       
   794 
       
   795 void CTstControl::CommitInlineEditL(MCoeFepAwareTextEditor& aFepAwareTextEditor)
       
   796 	{
       
   797 	aFepAwareTextEditor.CommitFepInlineEditL(*iCoeEnv);
       
   798 	iFlags&=~EFlagInsideInlineEditingTransaction;
       
   799 	}
       
   800 
       
   801 void CTstControl::ResetBuffer()
       
   802 	{
       
   803 	SetPositionOfInsertionPointInBuffer(0);
       
   804 	iBuffer.SetLength(0);
       
   805 	}
       
   806 
       
   807 void CTstControl::SetPositionOfInsertionPointInBuffer(TInt aPositionOfInsertionPointInBuffer)
       
   808 	{
       
   809 	SetPositionOfInsertionPointInBuffer(aPositionOfInsertionPointInBuffer, aPositionOfInsertionPointInBuffer);
       
   810 	}
       
   811 
       
   812 void CTstControl::SetPositionOfInsertionPointInBuffer(TInt aPositionOfInsertionPointInBuffer, TInt aPositionOfAnchorInBuffer)
       
   813 	{
       
   814 	iSelectedCompositionText.iCursorPos=aPositionOfInsertionPointInBuffer;
       
   815 	iSelectedCompositionText.iAnchorPos=aPositionOfAnchorInBuffer;
       
   816 	iInsertionPoint->SetPosition(PositionOfInsertionPointOnWindow());
       
   817 	}
       
   818 
       
   819 TPoint CTstControl::PositionOfInsertionPointOnWindow() const
       
   820 	{
       
   821 	return TPoint(1+EGapLeftOfEachLine+iCompositionFont->TextWidthInPixels(iBuffer.Left(iSelectedCompositionText.iCursorPos)), 1+EGapAboveCompositionLine+iCompositionFont->HeightInPixels());
       
   822 	}
       
   823 
       
   824 TInt CTstControl::PositionInBuffer(TInt aX) const
       
   825 	{
       
   826 	const TInt lengthOfBuffer=iBuffer.Length();
       
   827 	TInt previousX=0; // dummy initialization to prevent compiler warning "local variable 'previousX' may be used without having been initialized"
       
   828 	for (TInt i=0; ; ++i)
       
   829 		{
       
   830 		if (i>lengthOfBuffer)
       
   831 			{
       
   832 			return lengthOfBuffer;
       
   833 			}
       
   834 		const TInt x=1+EGapLeftOfEachLine+iCompositionFont->TextWidthInPixels(iBuffer.Left(i));
       
   835 		if (x>aX)
       
   836 			{
       
   837 			__ASSERT_DEBUG(i>=0, Panic(EPanicNegativeIndex));
       
   838 			if (i<=0)
       
   839 				{
       
   840 				return 0;
       
   841 				}
       
   842 			if (aX-previousX<x-aX)
       
   843 				{
       
   844 				return i-1;
       
   845 				}
       
   846 			return i;
       
   847 			}
       
   848 		previousX=x;
       
   849 		}
       
   850 	}
       
   851 
       
   852 TBool CTstControl::IsLegalNonDigitForRealNumber(const TCharUC& aKeyCodeInUpperCase) const
       
   853 	{
       
   854 	const TInt startOfSelectedText=iSelectedCompositionText.LowerPos();
       
   855 	const TInt endOfSelectedText=iSelectedCompositionText.HigherPos();
       
   856 	TInt positionOfExistingDecimalPoint=iBuffer.Locate('.');
       
   857 	if ((positionOfExistingDecimalPoint>=startOfSelectedText) && (positionOfExistingDecimalPoint<endOfSelectedText))
       
   858 		{
       
   859 		positionOfExistingDecimalPoint=KErrNotFound;
       
   860 		}
       
   861 	TInt positionOfExistingE=iBuffer.Locate('E');
       
   862 	if ((positionOfExistingE>=startOfSelectedText) && (positionOfExistingE<endOfSelectedText))
       
   863 		{
       
   864 		positionOfExistingE=KErrNotFound;
       
   865 		}
       
   866 	if (aKeyCodeInUpperCase=='.')
       
   867 		{
       
   868 		return (positionOfExistingDecimalPoint==KErrNotFound) && ((positionOfExistingE==KErrNotFound) || (positionOfExistingE>=endOfSelectedText));
       
   869 		}
       
   870 	if (aKeyCodeInUpperCase=='E')
       
   871 		{
       
   872 		return (positionOfExistingE==KErrNotFound) && ((positionOfExistingDecimalPoint==KErrNotFound) || (positionOfExistingDecimalPoint<startOfSelectedText));
       
   873 		}
       
   874 	return EFalse;
       
   875 	}
       
   876 
       
   877 void CTstControl::GetFormatAtDocumentPosition(TCharFormat& aFormat, TInt aDocumentPosition, const MCoeFepAwareTextEditor& aFepAwareTextEditor)
       
   878 	{
       
   879 	if (aDocumentPosition<0)
       
   880 		{
       
   881 		aDocumentPosition=0;
       
   882 		}
       
   883 	const TInt documentLength=aFepAwareTextEditor.DocumentLengthForFep();
       
   884 	if (aDocumentPosition>documentLength)
       
   885 		{
       
   886 		aDocumentPosition=documentLength;
       
   887 		}
       
   888 	aFepAwareTextEditor.GetFormatForFep(aFormat, aDocumentPosition);
       
   889 	}
       
   890 
       
   891 TInt CTstControl::NumberOfCharactersInBuffer(const CBase* aControl)
       
   892 	{
       
   893 	return STATIC_CAST(const CTstControl*, aControl)->iBuffer.Length();
       
   894 	}
       
   895 
       
   896 const TAny* CTstControl::CharacterInBuffer(const CBase* aControl, TInt aIndex)
       
   897 	{
       
   898 	CTstControl* control=STATIC_CAST(CTstControl*, CONST_CAST(CBase*, aControl));
       
   899 	control->iCharacterCode=control->iBuffer[aIndex];
       
   900 	return &control->iCharacterCode;
       
   901 	}
       
   902 
       
   903 TKeyResponse CTstControl::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aEventCode)
       
   904 	{
       
   905 	// CTstFep::OfferKeyEventL assumes that this will not leave if it returns EKeyWasNotConsumed
       
   906 	FEP_START_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, aEventCode);
       
   907 	const TBool isFocused=IsFocused();
       
   908 	const TCharUC keyCodeInUpperCase=aKeyEvent.iCode;
       
   909 	TInt bufferLength=iBuffer.Length();
       
   910 	if ((aKeyEvent.iModifiers&EModifierRightShift) && !isFocused)
       
   911 		{
       
   912 		if (keyCodeInUpperCase=='W')
       
   913 			{
       
   914  			if (iFlags&EFlagInsideInlineEditingTransaction)
       
   915 				{
       
   916 				TBool didIt=EFalse;
       
   917 				MCoeFepAwareTextEditor* const fepAwareTextEditor=iInputCapabilities.FepAwareTextEditor();
       
   918 				if (fepAwareTextEditor!=NULL)
       
   919 					{
       
   920 					MCoeFepAwareTextEditor_Extension1* const extension=fepAwareTextEditor->Extension1();
       
   921 					if (extension!=NULL)
       
   922 						{
       
   923 						TTextCursor textCursor;
       
   924 						textCursor.iType=TTextCursor::ETypeHollowRectangle;
       
   925 						textCursor.iHeight=0; // ignored by CEikEdwin as it checks for iWidth.
       
   926 						textCursor.iAscent=0; // ignored by CEikEdwin
       
   927 						textCursor.iWidth=5;
       
   928 						textCursor.iFlags=TTextCursor::EFlagNoFlash;
       
   929 						textCursor.iColor=TRgb(255,0,0);
       
   930 						extension->SetCursorType(didIt,textCursor);
       
   931 						}
       
   932 					}
       
   933 				if (!didIt)
       
   934 					{
       
   935 					User::InfoPrint(_L("Couldn't set the cursor-type"));
       
   936 					}
       
   937 				}
       
   938 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
   939 			}
       
   940 		else if (bufferLength==0)
       
   941 			{
       
   942 			switch (keyCodeInUpperCase)
       
   943 				{
       
   944 			case 'M':
       
   945   				ChangeSetupAndResetBufferAndDrawNow(SetInputMethod, (iInputMethod+1<EInputMethodOnePastTheLast)? iInputMethod+1: 0);
       
   946   				iFep.WriteAttributeDataAndBroadcastL(TUid::Uid(ETstInputMethodUid));
       
   947   				FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
   948 
       
   949 			case 'F':
       
   950 				ChangeSetupAndResetBufferAndDrawNow(SetFocus, ETrue);
       
   951 				FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
   952 			case 'I':
       
   953 				ChangeSetupAndResetBufferAndDrawNow(SetFlagInlineEditingEnabled, !(iFlags&EFlagInlineEditingEnabled));
       
   954 				iFep.WriteAttributeDataAndBroadcastL(TUid::Uid(ETstInlineEditingEnabledUid));
       
   955 				FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
   956 			case 'X':
       
   957 			case 'C':
       
   958 			case 'V':
       
   959 				{
       
   960 				TTstArrayOfOneCtrlCharacter arrayOfOneCtrlCharacter(keyCodeInUpperCase-('A'-1)); // the TTstArrayOfOneCtrlCharacter object cannot be an anonymous (temporary) object as its lifetime must be guaranteed to last until iFep.SimulateKeyEventsL returns
       
   961 				iFep.SimulateKeyEventsL(arrayOfOneCtrlCharacter.ArrayOfModifiedCharacters());
       
   962 				}
       
   963 				FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
   964 			case 'T':
       
   965 				{
       
   966 				MCoeFepAwareTextEditor* const fepAwareTextEditor=iInputCapabilities.FepAwareTextEditor();
       
   967 				if (fepAwareTextEditor==NULL)
       
   968 					{
       
   969 					User::InfoPrint(KLitNoFocusedFepAwareTextEditor);
       
   970 					}
       
   971 				else
       
   972 					{
       
   973 					MCoeFepAwareTextEditor_Extension1* const extension1=fepAwareTextEditor->Extension1();
       
   974 					if (extension1==NULL)
       
   975 						{
       
   976 						User::InfoPrint(KLitNoFocusedFepAwareTextEditorSupportingState);
       
   977 						}
       
   978 					else
       
   979 						{
       
   980 						MCoeFepAwareTextEditor_Extension1::CState* const state=extension1->State(TUid::Uid(KTfep1Uid));
       
   981 						if (state!=NULL)
       
   982 							{
       
   983 							STATIC_CAST(CStateInformation*, state)->IncrementMeaninglessNumber(); // this cast is safe as KTfep1Uid is used to retrieve state
       
   984 							}
       
   985 						else
       
   986 							{
       
   987 							CStateInformation* stateInformation=CStateInformation::NewLC(1);
       
   988 							extension1->SetStateTransferingOwnershipL(stateInformation, TUid::Uid(KTfep1Uid));
       
   989 							CleanupStack::Pop(stateInformation);
       
   990 							}
       
   991 						DrawNow();
       
   992 						}
       
   993 					}
       
   994 				}
       
   995 				FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
   996 			case 'N':
       
   997 				{
       
   998 				const MCoeFepAwareTextEditor* const fepAwareTextEditor=iInputCapabilities.FepAwareTextEditor();
       
   999 				if (fepAwareTextEditor==NULL)
       
  1000 					{
       
  1001 					User::InfoPrint(KLitNotAvailable);
       
  1002 					}
       
  1003 				else
       
  1004 					{
       
  1005 					TCursorSelection cursorSelection;
       
  1006 					fepAwareTextEditor->GetCursorSelectionForFep(cursorSelection);
       
  1007 					TPoint position;
       
  1008 					TInt height;
       
  1009 					TInt ascent;
       
  1010 					fepAwareTextEditor->GetScreenCoordinatesForFepL(position,height,ascent,cursorSelection.LowerPos());
       
  1011 					position.iY+=height-ascent;
       
  1012 					const TSize screenSize(iCoeEnv->ScreenDevice()->SizeInPixels());
       
  1013 					const TInt xMaximum=screenSize.iWidth-iSize.iWidth;
       
  1014 					if ((position.iX<0) || (xMaximum<0))
       
  1015 						{
       
  1016 						position.iX=0;
       
  1017 						}
       
  1018 					else if (position.iX>xMaximum)
       
  1019 						{
       
  1020 						position.iX=xMaximum;
       
  1021 						}
       
  1022 					const TInt yMaximum=screenSize.iHeight-iSize.iHeight;
       
  1023 					if ((position.iY<0) || (yMaximum<0))
       
  1024 						{
       
  1025 						position.iY=0;
       
  1026 						}
       
  1027 					else
       
  1028 						{
       
  1029 						const TInt yOverlapIfFepIsBelow=position.iY-yMaximum;
       
  1030 						if (yOverlapIfFepIsBelow>0)
       
  1031 							{
       
  1032 							const TInt yPositionIfFepIsAbove=Max(0, position.iY-(height+iSize.iHeight));
       
  1033 							const TInt yOverlapIfFepIsAbove=(yPositionIfFepIsAbove+iSize.iHeight)-(position.iY-height);
       
  1034 							if (yOverlapIfFepIsAbove<yOverlapIfFepIsBelow)
       
  1035 								{
       
  1036 								position.iY=yPositionIfFepIsAbove;
       
  1037 								}
       
  1038 							}
       
  1039 						}
       
  1040 					SetPosition(position);
       
  1041 					}
       
  1042 				}
       
  1043 				FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1044 			case 'B':
       
  1045 			case 'A':
       
  1046 			case 'S':
       
  1047 				{
       
  1048 				const MCoeFepAwareTextEditor* const fepAwareTextEditor=iInputCapabilities.FepAwareTextEditor();
       
  1049 				TBuf<40+EMaximumLengthOfDisplayOfContextInformation> textToDisplay;
       
  1050 				if (fepAwareTextEditor==NULL)
       
  1051 					{
       
  1052 					textToDisplay=KLitNotAvailable;
       
  1053 					}
       
  1054 				else
       
  1055 					{
       
  1056 					TCursorSelection cursorSelection;
       
  1057 					fepAwareTextEditor->GetCursorSelectionForFep(cursorSelection);
       
  1058 					switch (keyCodeInUpperCase)
       
  1059 						{
       
  1060 					case 'B':
       
  1061 						{
       
  1062 						TInt lengthToRetrieve=EMaximumLengthOfDisplayOfContextInformation+1;
       
  1063 						TInt documentPositionBeforeSelection=cursorSelection.LowerPos()-lengthToRetrieve;
       
  1064 						if (documentPositionBeforeSelection<0)
       
  1065 							{
       
  1066 							lengthToRetrieve+=documentPositionBeforeSelection; // same as doing "lengthToRetrieve=cursorSelection.LowerPos()", hence the assert below
       
  1067 							__ASSERT_DEBUG(lengthToRetrieve==cursorSelection.LowerPos(), Panic(EPanicArithmeticConfusion));
       
  1068 							documentPositionBeforeSelection=0;
       
  1069 							}
       
  1070 						fepAwareTextEditor->GetEditorContentForFep(textToDisplay, documentPositionBeforeSelection, lengthToRetrieve);
       
  1071 						const TInt lengthOfTextBeforeSelection=textToDisplay.Length();
       
  1072 						if (lengthOfTextBeforeSelection>EMaximumLengthOfDisplayOfContextInformation)
       
  1073 							{
       
  1074 							textToDisplay.Delete(0, (lengthOfTextBeforeSelection-EMaximumLengthOfDisplayOfContextInformation)-1);
       
  1075 							__ASSERT_DEBUG(textToDisplay.Length()==EMaximumLengthOfDisplayOfContextInformation+1, Panic(EPanicBadLengthOfTextBeforeSelection));
       
  1076 							textToDisplay[0]=KEllipsisCharacter;
       
  1077 							}
       
  1078 						}
       
  1079 						textToDisplay.Insert(0, KLitQuotationMark);
       
  1080 						textToDisplay.Append(KLitQuotationMark);
       
  1081 						textToDisplay.Insert(0, KLitTextBeforeSelectionColonSpace);
       
  1082 						break;
       
  1083 					case 'A':
       
  1084 						{
       
  1085 						const TInt documentLength=fepAwareTextEditor->DocumentLengthForFep();
       
  1086 						const TInt documentPositionAfterSelection=cursorSelection.HigherPos();
       
  1087 						if (documentPositionAfterSelection>documentLength)
       
  1088 							{
       
  1089 							__ASSERT_DEBUG(documentPositionAfterSelection==documentLength+1, Panic(EPanicSelectionExtendsPastEndOfDocument));
       
  1090 							}
       
  1091 						else
       
  1092 							{
       
  1093 							fepAwareTextEditor->GetEditorContentForFep(textToDisplay, documentPositionAfterSelection, EMaximumLengthOfDisplayOfContextInformation+1);
       
  1094 							const TInt lengthOfTextAfterSelection=textToDisplay.Length();
       
  1095 							if (lengthOfTextAfterSelection>EMaximumLengthOfDisplayOfContextInformation)
       
  1096 								{
       
  1097 								textToDisplay.Delete(EMaximumLengthOfDisplayOfContextInformation, (lengthOfTextAfterSelection-EMaximumLengthOfDisplayOfContextInformation)-1);
       
  1098 								__ASSERT_DEBUG(textToDisplay.Length()==EMaximumLengthOfDisplayOfContextInformation+1, Panic(EPanicBadLengthOfTextAfterSelection));
       
  1099 								textToDisplay[EMaximumLengthOfDisplayOfContextInformation]=KEllipsisCharacter;
       
  1100 								}
       
  1101 							}
       
  1102 						}
       
  1103 						textToDisplay.Insert(0, KLitQuotationMark);
       
  1104 						textToDisplay.Append(KLitQuotationMark);
       
  1105 						textToDisplay.Insert(0, KLitTextAfterSelectionColonSpace);
       
  1106 						break;
       
  1107 					case 'S':
       
  1108 						fepAwareTextEditor->GetEditorContentForFep(textToDisplay, cursorSelection.LowerPos(), cursorSelection.Length());
       
  1109 						{
       
  1110 						const TInt lengthOfSelection=textToDisplay.Length();
       
  1111 						if (lengthOfSelection>EMaximumLengthOfDisplayOfContextInformation)
       
  1112 							{
       
  1113 							textToDisplay.Delete(EMaximumLengthOfDisplayOfContextInformation, (lengthOfSelection-EMaximumLengthOfDisplayOfContextInformation)-1);
       
  1114 							__ASSERT_DEBUG(textToDisplay.Length()==EMaximumLengthOfDisplayOfContextInformation+1, Panic(EPanicBadLengthOfSelection));
       
  1115 							textToDisplay[EMaximumLengthOfDisplayOfContextInformation]=KEllipsisCharacter;
       
  1116 							}
       
  1117 						}
       
  1118 						textToDisplay.Insert(0, KLitQuotationMark);
       
  1119 						textToDisplay.Append(KLitQuotationMark);
       
  1120 						textToDisplay.Insert(0, KLitSelectionColonSpace);
       
  1121 						break;
       
  1122 #if defined(_DEBUG)
       
  1123 					default:
       
  1124 						Panic(EPanicBadKeyCode1);
       
  1125 						break;
       
  1126 #endif
       
  1127 						}
       
  1128 					}
       
  1129 				User::InfoPrint(textToDisplay);
       
  1130 				}
       
  1131 				FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1132 				}
       
  1133 			}
       
  1134 		}
       
  1135 	if (iInputCapabilities.IsNone() && !isFocused)
       
  1136 		{
       
  1137 		FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasNotConsumed); // returns from this function
       
  1138 		}
       
  1139 	switch (keyCodeInUpperCase)
       
  1140 		{
       
  1141 	case EKeyEnter:
       
  1142 	case EKeyEscape:
       
  1143 		if (isFocused)
       
  1144 			{
       
  1145 			ChangeSetupAndResetBufferAndDrawNow(SetFocus, EFalse);
       
  1146 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1147 			}
       
  1148 		if (bufferLength>0)
       
  1149 			{
       
  1150 			TBool needToDraw=ETrue;
       
  1151 			switch (keyCodeInUpperCase)
       
  1152 				{
       
  1153 			case EKeyEnter:
       
  1154 				if (~iFlags&EFlagInsideInlineEditingTransaction)
       
  1155 					{
       
  1156 					iFep.SimulateKeyEventsL(TArray<TUint>(NumberOfCharactersInBuffer, CharacterInBuffer, this));
       
  1157 					}
       
  1158 				else
       
  1159 					{
       
  1160 					CommitInlineEditL(*iInputCapabilities.FepAwareTextEditor());
       
  1161 					needToDraw=EFalse;
       
  1162 					}
       
  1163 				break;
       
  1164 			case EKeyEscape:
       
  1165 				if (iFlags&EFlagInsideInlineEditingTransaction)
       
  1166 					{
       
  1167 					CancelInlineEdit(*iInputCapabilities.FepAwareTextEditor());	
       
  1168 					needToDraw=EFalse;
       
  1169 					}
       
  1170 				break;
       
  1171 #if defined(_DEBUG)
       
  1172 			default:
       
  1173 				Panic(EPanicBadKeyCode2);
       
  1174 				break;
       
  1175 #endif
       
  1176 				}
       
  1177 			ResetBuffer();
       
  1178 			if (needToDraw)
       
  1179 				{
       
  1180 				DrawNow();
       
  1181 				}
       
  1182 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1183 			}
       
  1184 		break;
       
  1185 	case EKeyDelete:
       
  1186 	case EKeyBackspace:
       
  1187 		if (!isFocused && (bufferLength>0))
       
  1188 			{
       
  1189 			TCursorSelection portionToDelete(iSelectedCompositionText.iCursorPos, iSelectedCompositionText.iAnchorPos);
       
  1190 			const TBool deleteLeft=((keyCodeInUpperCase==EKeyBackspace) && !(aKeyEvent.iModifiers&EModifierShift));
       
  1191 			if (portionToDelete.Length()==0)
       
  1192 				{
       
  1193 				if (deleteLeft)
       
  1194 					{
       
  1195 					if (portionToDelete.iCursorPos>0)
       
  1196 						{
       
  1197 						--portionToDelete.iCursorPos;
       
  1198 						}
       
  1199 					}
       
  1200 				else
       
  1201 					{
       
  1202 					if (portionToDelete.iCursorPos<bufferLength)
       
  1203 						{
       
  1204 						++portionToDelete.iCursorPos;
       
  1205 						}
       
  1206 					}
       
  1207 				}
       
  1208 			if (portionToDelete.Length()>0)
       
  1209 				{
       
  1210 				TTstTextBackup textBackup=iBuffer;
       
  1211 				textBackup.PushOntoCleanupStackL();
       
  1212 				SetPositionOfInsertionPointInBuffer(portionToDelete.LowerPos());
       
  1213 				iBuffer.Delete(portionToDelete.LowerPos(), portionToDelete.Length());
       
  1214 				if (~iFlags&EFlagInsideInlineEditingTransaction)
       
  1215 					{
       
  1216 					DrawNow();
       
  1217 					}
       
  1218 				else
       
  1219 					{
       
  1220 					if (bufferLength-1>0)
       
  1221 						{
       
  1222 						SetInlineTextL(*iInputCapabilities.FepAwareTextEditor());
       
  1223 						}
       
  1224 					else
       
  1225 						{
       
  1226 						CancelInlineEdit(*iInputCapabilities.FepAwareTextEditor());
       
  1227 						}
       
  1228 					}
       
  1229 				textBackup.PopOffCleanupStack();
       
  1230 				}
       
  1231 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1232 			}
       
  1233 		break;
       
  1234 	case EKeySpace:
       
  1235 		if (!isFocused && (bufferLength>0))
       
  1236 			{
       
  1237 			__ASSERT_DEBUG((iInputMethod==EInputMethodPlain) || (iInputMethod==EInputMethodHexadecimalCharacterCode), Panic(EPanicBadInputMethod2));
       
  1238 			if ((iInputMethod==EInputMethodPlain) && (iSelectedCompositionText.iCursorPos<bufferLength))
       
  1239 				{
       
  1240 				const TInt increment=(aKeyEvent.iModifiers&EModifierShift)? -1: 1;
       
  1241 				const TCharUC limit=(aKeyEvent.iModifiers&EModifierShift)? 'A': 'Z';
       
  1242 				const TCharUC characterToAdjust=iBuffer[iSelectedCompositionText.iCursorPos];
       
  1243 				__ASSERT_DEBUG((characterToAdjust>='A') && (characterToAdjust<='Z'), Panic(EPanicBadCharacterInBuffer));
       
  1244 				if (characterToAdjust!=limit)
       
  1245 					{
       
  1246 					TTstTextBackup textBackup=iBuffer;
       
  1247 					textBackup.PushOntoCleanupStackL();
       
  1248 					iBuffer[iSelectedCompositionText.iCursorPos]=(TText)(iBuffer[iSelectedCompositionText.iCursorPos]+increment);
       
  1249 					if (iFlags&EFlagInsideInlineEditingTransaction)
       
  1250 						{
       
  1251 						SetInlineTextL(*iInputCapabilities.FepAwareTextEditor());
       
  1252 						}
       
  1253 					else
       
  1254 						{
       
  1255 						DrawNow();
       
  1256 						}
       
  1257 					textBackup.PopOffCleanupStack();
       
  1258 					}
       
  1259 				}
       
  1260 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1261 			}
       
  1262 		break;
       
  1263 	case EKeyHome:
       
  1264 	case EKeyEnd:
       
  1265 	case EKeyPageUp:
       
  1266 	case EKeyPageDown:
       
  1267 	case EKeyLeftArrow:
       
  1268 	case EKeyRightArrow:
       
  1269 	case EKeyUpArrow:
       
  1270 	case EKeyDownArrow:
       
  1271 		if (isFocused)
       
  1272 			{
       
  1273 			TPoint offset(0, 0);
       
  1274 			TInt magnification=10;
       
  1275 			switch (keyCodeInUpperCase)
       
  1276 				{
       
  1277 			case EKeyLeftArrow:
       
  1278 				offset.iX=-1;
       
  1279 				break;
       
  1280 			case EKeyRightArrow:
       
  1281 				offset.iX=1;
       
  1282 				break;
       
  1283 			case EKeyUpArrow:
       
  1284 				offset.iY=-1;
       
  1285 				break;
       
  1286 			case EKeyDownArrow:
       
  1287 				offset.iY=1;
       
  1288 				break;
       
  1289 			case EKeyHome:
       
  1290 				offset.iX=-iPosition.iX;
       
  1291 				offset.iY=-iPosition.iY;
       
  1292 				magnification=1;
       
  1293 				break;
       
  1294 			case EKeyEnd:
       
  1295 				{
       
  1296 				const TSize screenWidth(iCoeEnv->ScreenDevice()->SizeInPixels());
       
  1297 				offset.iX=(screenWidth.iWidth-iSize.iWidth)-iPosition.iX;
       
  1298 				offset.iY=(screenWidth.iHeight-iSize.iHeight)-iPosition.iY;
       
  1299 				}
       
  1300 				magnification=1;
       
  1301 				break;
       
  1302 			case EKeyPageUp:
       
  1303 				offset.iY=-iSize.iHeight;
       
  1304 				magnification=1;
       
  1305 				break;
       
  1306 			case EKeyPageDown:
       
  1307 				offset.iY=iSize.iHeight;
       
  1308 				magnification=1;
       
  1309 				break;
       
  1310 #if defined(_DEBUG)
       
  1311 			default:
       
  1312 				Panic(EPanicBadKeyCode3);
       
  1313 				break;
       
  1314 #endif
       
  1315 				}
       
  1316 			if (aKeyEvent.iModifiers&EModifierCtrl)
       
  1317 				{
       
  1318 				offset.iX*=magnification;
       
  1319 				offset.iY*=magnification;
       
  1320 				}
       
  1321 			SetPosition(TPoint(iPosition.iX+offset.iX, iPosition.iY+offset.iY));
       
  1322 			if (iFlags&EFlagWindowIsBeingDragged)
       
  1323 				{
       
  1324 				iPositionOnWindowBeingDragged.iX-=offset.iX;
       
  1325 				iPositionOnWindowBeingDragged.iY-=offset.iY;
       
  1326 				}
       
  1327 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1328 			}
       
  1329 		if (bufferLength>0)
       
  1330 			{
       
  1331 			TInt newPositionOfInsertionPointInBuffer=iSelectedCompositionText.iCursorPos;
       
  1332 			switch (keyCodeInUpperCase)
       
  1333 				{
       
  1334 			case EKeyLeftArrow:
       
  1335 				if (newPositionOfInsertionPointInBuffer>0)
       
  1336 					{
       
  1337 					--newPositionOfInsertionPointInBuffer;
       
  1338 					}
       
  1339 				break;
       
  1340 			case EKeyRightArrow:
       
  1341 				if (newPositionOfInsertionPointInBuffer<bufferLength)
       
  1342 					{
       
  1343 					++newPositionOfInsertionPointInBuffer;
       
  1344 					}
       
  1345 				break;
       
  1346 			case EKeyHome:
       
  1347 			case EKeyPageUp:
       
  1348 			case EKeyUpArrow:
       
  1349 				newPositionOfInsertionPointInBuffer=0;
       
  1350 				break;
       
  1351 			case EKeyEnd:
       
  1352 			case EKeyPageDown:
       
  1353 			case EKeyDownArrow:
       
  1354 				newPositionOfInsertionPointInBuffer=bufferLength;
       
  1355 				break;
       
  1356 #if defined(_DEBUG)
       
  1357 			default:
       
  1358 				Panic(EPanicBadKeyCode4);
       
  1359 				break;
       
  1360 #endif
       
  1361 				}
       
  1362 			if (iSelectedCompositionText.iCursorPos!=newPositionOfInsertionPointInBuffer)
       
  1363 				{
       
  1364 				if ((iSelectedCompositionText.Length()>0) && !(aKeyEvent.iModifiers&EModifierShift))
       
  1365 					{
       
  1366 					if (newPositionOfInsertionPointInBuffer<iSelectedCompositionText.iCursorPos)
       
  1367 						{
       
  1368 						newPositionOfInsertionPointInBuffer=iSelectedCompositionText.LowerPos();
       
  1369 						}
       
  1370 					else
       
  1371 						{
       
  1372 						newPositionOfInsertionPointInBuffer=iSelectedCompositionText.HigherPos();
       
  1373 						}
       
  1374 					}
       
  1375 				}
       
  1376 			const TInt newPositionOfAnchorInBuffer=(aKeyEvent.iModifiers&EModifierShift)? iSelectedCompositionText.iAnchorPos: newPositionOfInsertionPointInBuffer;
       
  1377 			if ((iSelectedCompositionText.iCursorPos!=newPositionOfInsertionPointInBuffer) || (iSelectedCompositionText.iAnchorPos!=newPositionOfAnchorInBuffer))
       
  1378 				{
       
  1379 				const TBool needToDraw=((iSelectedCompositionText.Length()>0) || (aKeyEvent.iModifiers&EModifierShift)); // don't need to draw if there is no selected text as a result of this event, or if there previously was no selected text before this event
       
  1380 				SetPositionOfInsertionPointInBuffer(newPositionOfInsertionPointInBuffer, newPositionOfAnchorInBuffer);
       
  1381 				if (iFlags&EFlagInsideInlineEditingTransaction)
       
  1382 					{
       
  1383 					SetInlineTextL(*iInputCapabilities.FepAwareTextEditor());
       
  1384 					}
       
  1385 				else if (needToDraw)
       
  1386 					{
       
  1387 					DrawNow();
       
  1388 					}
       
  1389 				}
       
  1390 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1391 			}
       
  1392 		break;
       
  1393 	default:
       
  1394 		if (isFocused)
       
  1395 			{
       
  1396 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1397 			}
       
  1398 		TBool isLegalCompositionCharacter=EFalse;
       
  1399 		switch (iInputMethod)
       
  1400 			{
       
  1401 		case EInputMethodPlain:
       
  1402 			if (iInputCapabilities.SupportsAllText())
       
  1403 				{
       
  1404 				isLegalCompositionCharacter=keyCodeInUpperCase.IsPrint();
       
  1405 				}
       
  1406 			else
       
  1407 				{
       
  1408 				const TBool isDigit=((keyCodeInUpperCase>='0') && (keyCodeInUpperCase<='9'));
       
  1409 				isLegalCompositionCharacter=(iInputCapabilities.SupportsWesternNumericIntegerPositive() && isDigit);
       
  1410 				if (isLegalCompositionCharacter)
       
  1411 					{
       
  1412 					break;
       
  1413 					}
       
  1414 				isLegalCompositionCharacter=(iInputCapabilities.SupportsWesternNumericIntegerNegative() && (isDigit || ((iSelectedCompositionText.LowerPos()==0) && (keyCodeInUpperCase=='-'))));
       
  1415 				if (isLegalCompositionCharacter)
       
  1416 					{
       
  1417 					break;
       
  1418 					}
       
  1419 				isLegalCompositionCharacter=(iInputCapabilities.SupportsWesternNumericReal() && (isDigit || IsLegalNonDigitForRealNumber(keyCodeInUpperCase)));
       
  1420 				if (isLegalCompositionCharacter)
       
  1421 					{
       
  1422 					break;
       
  1423 					}
       
  1424 				const TUint foldFlags=(TChar::EFoldCase|TChar::EFoldAccents);
       
  1425 				const TUint foldedKeyCode=User::Fold(keyCodeInUpperCase, foldFlags);
       
  1426 				isLegalCompositionCharacter=(iInputCapabilities.SupportsWesternAlphabetic() && (foldedKeyCode>=User::Fold('A', foldFlags)) && (foldedKeyCode<=User::Fold('Z', foldFlags)));
       
  1427 				if (isLegalCompositionCharacter)
       
  1428 					{
       
  1429 					break;
       
  1430 					}
       
  1431 				}
       
  1432 			break;
       
  1433 		case EInputMethodHexadecimalCharacterCode:
       
  1434 			isLegalCompositionCharacter=keyCodeInUpperCase.IsHexDigit();
       
  1435 			break;
       
  1436 		case EInputMethodOnePastTheLast:
       
  1437 #if defined(_DEBUG)
       
  1438 		default:
       
  1439 			Panic(EPanicBadInputMethod3);
       
  1440 #endif
       
  1441 			break;
       
  1442 			}
       
  1443 		if (isLegalCompositionCharacter)
       
  1444 			{
       
  1445 			iCharacterCode=aKeyEvent.iCode; // set iCharacterCode to aKeyEvent.iCode rather than keyCodeInUpperCase so that the original case is preserved
       
  1446 			iFep.MakeDeferredFunctionCall(*this); // deferred call to InsertCompositionCharacterAndDrawNowL
       
  1447 			if (bufferLength==0)
       
  1448 				{
       
  1449 				iCoeEnv->ForEachFepObserverCall(FepObserverHandleStartOfTransactionL); // must be called before inserting the composition character as an application's HandleStartOfTransactionL function may move focus to a control supporting inline-editing
       
  1450 				}
       
  1451 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1452 			}
       
  1453 		if (bufferLength>0)
       
  1454 			{
       
  1455 			FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasConsumed); // returns from this function
       
  1456 			}
       
  1457 		break;
       
  1458 		}
       
  1459 	FEP_END_KEY_EVENT_HANDLER_L(iFep, aKeyEvent, EKeyWasNotConsumed); // returns from this function
       
  1460 	}
       
  1461 
       
  1462 void CTstControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
  1463 	{
       
  1464 	switch (aPointerEvent.iType)
       
  1465 		{
       
  1466 	case TPointerEvent::EButton1Down:
       
  1467 		if (IsFocused() ||
       
  1468 			(iFlags&EFlagHasNoCompositionWindow) ||
       
  1469 			(aPointerEvent.iPosition.iX<1) || (aPointerEvent.iPosition.iX>=iSize.iWidth-1) ||
       
  1470 			(aPointerEvent.iPosition.iY<1) || (aPointerEvent.iPosition.iY>=1+EGapAboveCompositionLine+iCompositionFont->HeightInPixels()+EGapBelowCompositionLine))
       
  1471 			{
       
  1472 			iFlags|=EFlagWindowIsBeingDragged;
       
  1473 			iPositionOnWindowBeingDragged=aPointerEvent.iPosition;
       
  1474 			}
       
  1475 		else
       
  1476 			{
       
  1477 			if (~iFlags&EFlagInsideInlineEditingTransaction)
       
  1478 				{
       
  1479 				const TInt newPositionOfInsertionPointInBuffer=PositionInBuffer(aPointerEvent.iPosition.iX);
       
  1480 				const TInt newPositionOfAnchorInBuffer=(aPointerEvent.iModifiers&EModifierShift)? iSelectedCompositionText.iAnchorPos: newPositionOfInsertionPointInBuffer;
       
  1481 				if ((iSelectedCompositionText.iCursorPos!=newPositionOfInsertionPointInBuffer) || (iSelectedCompositionText.iAnchorPos!=newPositionOfAnchorInBuffer))
       
  1482 					{
       
  1483 					const TBool needToDraw=((iSelectedCompositionText.Length()>0) || (aPointerEvent.iModifiers&EModifierShift)); // don't need to draw if there is no selected text as a result of this event, or if there previously was no selected text before this event
       
  1484 					SetPositionOfInsertionPointInBuffer(newPositionOfInsertionPointInBuffer, newPositionOfAnchorInBuffer);
       
  1485 					if (needToDraw)
       
  1486 						{
       
  1487 						DrawNow();
       
  1488 						}
       
  1489 					}
       
  1490 				}
       
  1491 			}
       
  1492 		break;
       
  1493 	case TPointerEvent::EDrag:
       
  1494 		if (iFlags&EFlagWindowIsBeingDragged)
       
  1495 			{
       
  1496 			SetPosition(aPointerEvent.iParentPosition-iPositionOnWindowBeingDragged);
       
  1497 			}
       
  1498 		else
       
  1499 			{
       
  1500 			if (~iFlags&EFlagInsideInlineEditingTransaction)
       
  1501 				{
       
  1502 				const TInt newPositionOfInsertionPointInBuffer=PositionInBuffer(aPointerEvent.iPosition.iX);
       
  1503 				if (iSelectedCompositionText.iCursorPos!=newPositionOfInsertionPointInBuffer)
       
  1504 					{
       
  1505 					SetPositionOfInsertionPointInBuffer(newPositionOfInsertionPointInBuffer, iSelectedCompositionText.iAnchorPos);
       
  1506 					DrawNow();
       
  1507 					}
       
  1508 				}
       
  1509 			}
       
  1510 		break;
       
  1511 	case TPointerEvent::EButton1Up:
       
  1512 		iFlags&=~EFlagWindowIsBeingDragged;
       
  1513 		break;
       
  1514 #if defined(__GCC32__)
       
  1515 	default:
       
  1516 		break;
       
  1517 #endif
       
  1518 		}
       
  1519 	}
       
  1520 
       
  1521 void CTstControl::Draw(const TRect&) const
       
  1522 	{
       
  1523 	CWindowGc& graphicsContext=SystemGc();
       
  1524 	graphicsContext.SetPenStyle(CGraphicsContext::ESolidPen);
       
  1525 	graphicsContext.SetPenColor(KRgbBlack);
       
  1526 	graphicsContext.SetBrushStyle(CGraphicsContext::ENullBrush);
       
  1527 	TRect rectangle(Rect());
       
  1528 	graphicsContext.DrawRect(rectangle);
       
  1529 	rectangle.Shrink(1, 1);
       
  1530 	graphicsContext.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  1531 	if (IsFocused())
       
  1532 		{
       
  1533 		__ASSERT_DEBUG(iBuffer.Length()==0, Panic(EPanicInconsistentState));
       
  1534 		// the pen color is still black here
       
  1535 		graphicsContext.SetBrushColor(KRgbBlack);
       
  1536 		graphicsContext.DrawRect(rectangle);
       
  1537 		const TPoint center=rectangle.Center();
       
  1538 		graphicsContext.SetPenColor(KRgbWhite);
       
  1539 		const TPoint leftArrowHead((rectangle.iTl.iX+center.iX)/2, center.iY);
       
  1540 		const TPoint rightArrowHead((center.iX+rectangle.iBr.iX)/2, center.iY);
       
  1541 		const TPoint topArrowHead(center.iX, (rectangle.iTl.iY+center.iY)/2);
       
  1542 		const TPoint bottomArrowHead(center.iX, (center.iY+rectangle.iBr.iY)/2);
       
  1543 		graphicsContext.DrawLine(leftArrowHead, rightArrowHead);
       
  1544 		graphicsContext.Plot(rightArrowHead);
       
  1545 		graphicsContext.DrawLine(topArrowHead, bottomArrowHead);
       
  1546 		graphicsContext.Plot(bottomArrowHead);
       
  1547 		graphicsContext.DrawLine(TPoint(leftArrowHead.iX+EArrowHeadSize, leftArrowHead.iY+EArrowHeadSize), leftArrowHead);
       
  1548 		graphicsContext.DrawLine(TPoint(leftArrowHead.iX+EArrowHeadSize, leftArrowHead.iY-EArrowHeadSize), leftArrowHead);
       
  1549 		graphicsContext.DrawLine(TPoint(rightArrowHead.iX-EArrowHeadSize, rightArrowHead.iY-EArrowHeadSize), rightArrowHead);
       
  1550 		graphicsContext.DrawLine(TPoint(rightArrowHead.iX-EArrowHeadSize, rightArrowHead.iY+EArrowHeadSize), rightArrowHead);
       
  1551 		graphicsContext.DrawLine(TPoint(topArrowHead.iX-EArrowHeadSize, topArrowHead.iY+EArrowHeadSize), topArrowHead);
       
  1552 		graphicsContext.DrawLine(TPoint(topArrowHead.iX+EArrowHeadSize, topArrowHead.iY+EArrowHeadSize), topArrowHead);
       
  1553 		graphicsContext.DrawLine(TPoint(bottomArrowHead.iX+EArrowHeadSize, bottomArrowHead.iY-EArrowHeadSize), bottomArrowHead);
       
  1554 		graphicsContext.DrawLine(TPoint(bottomArrowHead.iX-EArrowHeadSize, bottomArrowHead.iY-EArrowHeadSize), bottomArrowHead);
       
  1555 		}
       
  1556 	else
       
  1557 		{
       
  1558 		TRect temp(rectangle);
       
  1559 		temp.iBr.iY=temp.iTl.iY;
       
  1560 		graphicsContext.SetBrushColor(KRgbWhite);
       
  1561 		if (~iFlags&EFlagHasNoCompositionWindow)
       
  1562 			{
       
  1563 			graphicsContext.UseFont(iCompositionFont);
       
  1564 			temp.iBr.iY+=EGapAboveCompositionLine+iCompositionFont->HeightInPixels()+EGapBelowCompositionLine;
       
  1565 			TRect temp2=temp;
       
  1566 			const TInt startOfSelectedCompositionText=iSelectedCompositionText.LowerPos();
       
  1567 			const TPtrC textBeforeSelectedText(iBuffer.Left(startOfSelectedCompositionText));
       
  1568 			temp2.iBr.iX=temp2.iTl.iX;
       
  1569 			temp2.iBr.iX+=iCompositionFont->TextWidthInPixels(textBeforeSelectedText);
       
  1570 			graphicsContext.SetPenColor(KRgbRed);
       
  1571 			graphicsContext.DrawText(textBeforeSelectedText, temp2, EGapAboveCompositionLine+iCompositionFont->AscentInPixels(), CGraphicsContext::ELeft, EGapLeftOfEachLine);
       
  1572 			const TPtrC selectedText(iBuffer.Mid(startOfSelectedCompositionText, iSelectedCompositionText.Length()));
       
  1573 			temp2.iTl.iX=temp2.iBr.iX;
       
  1574 			temp2.iBr.iX+=iCompositionFont->TextWidthInPixels(selectedText);
       
  1575 			graphicsContext.SetPenColor(KRgbGreen);
       
  1576 			graphicsContext.DrawText(selectedText, temp2, EGapAboveCompositionLine+iCompositionFont->AscentInPixels(), CGraphicsContext::ELeft, EGapLeftOfEachLine);
       
  1577 			const TPtrC textAfterSelectedText(iBuffer.Mid(iSelectedCompositionText.HigherPos()));
       
  1578 			temp2.iTl.iX=temp2.iBr.iX;
       
  1579 			temp2.iBr.iX=temp.iBr.iX;
       
  1580 			graphicsContext.SetPenColor(KRgbRed);
       
  1581 			graphicsContext.DrawText(textAfterSelectedText, temp2, EGapAboveCompositionLine+iCompositionFont->AscentInPixels(), CGraphicsContext::ELeft, EGapLeftOfEachLine);
       
  1582 			graphicsContext.DiscardFont();
       
  1583 			graphicsContext.SetPenColor(KRgbBlack);
       
  1584 			}
       
  1585 		TBuf<200> textToDisplay;
       
  1586 		textToDisplay=KLitInputMethodColonSpace;
       
  1587 		switch (iInputMethod)
       
  1588 			{
       
  1589 		case EInputMethodPlain:
       
  1590 			textToDisplay.Append(KLitPlain);
       
  1591 			break;
       
  1592 		case EInputMethodHexadecimalCharacterCode:
       
  1593 			textToDisplay.Append(KLitHexadecimalCharacterCode);
       
  1594 			break;
       
  1595 		default:
       
  1596 #if defined(_DEBUG)
       
  1597 			Panic(EPanicBadInputMethod5);
       
  1598 #endif
       
  1599 			break;
       
  1600 			}
       
  1601 		const TInt statusFontHeightInPixels=iStatusFont->HeightInPixels();
       
  1602 		const TInt statusFontAscentInPixels=iStatusFont->AscentInPixels();
       
  1603 		graphicsContext.SetBrushColor(KRgbGray);
       
  1604 		graphicsContext.UseFont(iStatusFont);
       
  1605 		temp.iTl.iY=temp.iBr.iY;
       
  1606 		temp.iBr.iY+=EGapAboveTopStatusLine+statusFontHeightInPixels+EGapBetweenEachStatusLine;
       
  1607 		graphicsContext.DrawText(textToDisplay, temp, EGapAboveTopStatusLine+statusFontAscentInPixels, CGraphicsContext::ELeft, EGapLeftOfEachLine);
       
  1608 		textToDisplay=KLitInlineEditingColonSpace;
       
  1609 		textToDisplay.Append((iFlags&EFlagInlineEditingEnabled)? KLitEnabled(): KLitDisabled());
       
  1610 		temp.iTl.iY=temp.iBr.iY;
       
  1611 		temp.iBr.iY+=statusFontHeightInPixels+EGapBetweenEachStatusLine;
       
  1612 		graphicsContext.DrawText(textToDisplay, temp, statusFontAscentInPixels, CGraphicsContext::ELeft, EGapLeftOfEachLine);
       
  1613 		textToDisplay=KLitOpeningSquareBracket;
       
  1614 		textToDisplay.Append(KLitCaptionColonSpace);
       
  1615 		textToDisplay.Append(KLitQuotationMark);
       
  1616 		const MCoeCaptionRetrieverForFep* captionRetrieverForFep=iInputCapabilities.CaptionRetrieverForFep();
       
  1617 		if (captionRetrieverForFep!=NULL)
       
  1618 			{
       
  1619 			TBuf<51> caption;
       
  1620 			captionRetrieverForFep->GetCaptionForFep(caption);
       
  1621 			const TInt captionLength=caption.Length();
       
  1622 			if (captionLength==caption.MaxLength())
       
  1623 				{
       
  1624 				caption[captionLength-1]=KEllipsisCharacter;
       
  1625 				}
       
  1626 			textToDisplay.Append(caption);
       
  1627 			}
       
  1628 		textToDisplay.Append(KLitQuotationMark);
       
  1629 		textToDisplay.Append(KLitClosingSquareBracket);
       
  1630 		temp.iTl.iY=temp.iBr.iY;
       
  1631 		temp.iBr.iY+=statusFontHeightInPixels+EGapBetweenEachStatusLine;
       
  1632 		graphicsContext.DrawText(textToDisplay, temp, statusFontAscentInPixels, CGraphicsContext::ELeft, EGapLeftOfEachLine);
       
  1633 		textToDisplay=KLitOpeningSquareBracket;
       
  1634 		textToDisplay.Append(KLitStateColonSpace);
       
  1635 		textToDisplay.Append(KLitQuotationMark);
       
  1636 		MCoeFepAwareTextEditor* const fepAwareTextEditor=iInputCapabilities.FepAwareTextEditor();
       
  1637 		if (fepAwareTextEditor!=NULL)
       
  1638 			{
       
  1639 			MCoeFepAwareTextEditor_Extension1* const extension1=fepAwareTextEditor->Extension1();
       
  1640 			if (extension1!=NULL)
       
  1641 				{
       
  1642 				MCoeFepAwareTextEditor_Extension1::CState* const state=extension1->State(TUid::Uid(KTfep1Uid));
       
  1643 				if (state!=NULL)
       
  1644 					{
       
  1645 					textToDisplay.AppendNum(STATIC_CAST(CStateInformation*, state)->MeaninglessNumber()); // this cast is safe as KTfep1Uid is used to retrieve state
       
  1646 					}
       
  1647 				}
       
  1648 			}
       
  1649 		textToDisplay.Append(KLitQuotationMark);
       
  1650 		textToDisplay.Append(KLitClosingSquareBracket);
       
  1651 		temp.iTl.iY=temp.iBr.iY;
       
  1652 		temp.iBr.iY+=statusFontHeightInPixels+EGapBetweenEachStatusLine;
       
  1653 		graphicsContext.DrawText(textToDisplay, temp, statusFontAscentInPixels, CGraphicsContext::ELeft, EGapLeftOfEachLine);
       
  1654 		textToDisplay=KLitOpeningSquareBracket;
       
  1655 		textToDisplay.Append(KLitInputCapabilitiesColonSpace);
       
  1656 		if (iInputCapabilities.IsNone())
       
  1657 			{
       
  1658 			textToDisplay.Append(KLitNone);
       
  1659 			}
       
  1660 		else
       
  1661 			{
       
  1662 			TBool deleteLastSeparator=EFalse;
       
  1663 			if (iInputCapabilities.SupportsWesternNumericIntegerPositive())
       
  1664 				{
       
  1665 				textToDisplay.Append(KLitWesternNumericIntegerPositive);
       
  1666 				textToDisplay.Append(KLitCommaSpace);
       
  1667 				deleteLastSeparator=ETrue;
       
  1668 				}
       
  1669 			if (iInputCapabilities.SupportsWesternNumericIntegerNegative())
       
  1670 				{
       
  1671 				textToDisplay.Append(KLitWesternNumericIntegerNegative);
       
  1672 				textToDisplay.Append(KLitCommaSpace);
       
  1673 				deleteLastSeparator=ETrue;
       
  1674 				}
       
  1675 			if (iInputCapabilities.SupportsWesternNumericReal())
       
  1676 				{
       
  1677 				textToDisplay.Append(KLitWesternNumericReal);
       
  1678 				textToDisplay.Append(KLitCommaSpace);
       
  1679 				deleteLastSeparator=ETrue;
       
  1680 				}
       
  1681 			if (iInputCapabilities.SupportsWesternAlphabetic())
       
  1682 				{
       
  1683 				textToDisplay.Append(KLitWesternAlphabetic);
       
  1684 				textToDisplay.Append(KLitCommaSpace);
       
  1685 				deleteLastSeparator=ETrue;
       
  1686 				}
       
  1687 			if (iInputCapabilities.SupportsJapaneseHiragana())
       
  1688 				{
       
  1689 				textToDisplay.Append(KLitJapaneseHiragana);
       
  1690 				textToDisplay.Append(KLitCommaSpace);
       
  1691 				deleteLastSeparator=ETrue;
       
  1692 				}
       
  1693 			if (iInputCapabilities.SupportsJapaneseKatakanaHalfWidth())
       
  1694 				{
       
  1695 				textToDisplay.Append(KLitJapaneseKatakanaHalfWidth);
       
  1696 				textToDisplay.Append(KLitCommaSpace);
       
  1697 				deleteLastSeparator=ETrue;
       
  1698 				}
       
  1699 			if (iInputCapabilities.SupportsJapaneseKatakanaFullWidth())
       
  1700 				{
       
  1701 				textToDisplay.Append(KLitJapaneseKatakanaFullWidth);
       
  1702 				textToDisplay.Append(KLitCommaSpace);
       
  1703 				deleteLastSeparator=ETrue;
       
  1704 				}
       
  1705 			if (iInputCapabilities.SupportsDialableCharacters())
       
  1706 				{
       
  1707 				textToDisplay.Append(KLitDialableCharacters);
       
  1708 				textToDisplay.Append(KLitCommaSpace);
       
  1709 				deleteLastSeparator=ETrue;
       
  1710 				}
       
  1711 			if (iInputCapabilities.SupportsSecretText())
       
  1712 				{
       
  1713 				textToDisplay.Append(KLitSecretText);
       
  1714 				textToDisplay.Append(KLitCommaSpace);
       
  1715 				deleteLastSeparator=ETrue;
       
  1716 				}
       
  1717 			if (iInputCapabilities.SupportsAllText())
       
  1718 				{
       
  1719 				textToDisplay.Append(KLitAllText);
       
  1720 				textToDisplay.Append(KLitCommaSpace);
       
  1721 				deleteLastSeparator=ETrue;
       
  1722 				}
       
  1723 			if (iInputCapabilities.SupportsNavigation())
       
  1724 				{
       
  1725 				textToDisplay.Append(KLitNavigation);
       
  1726 				textToDisplay.Append(KLitCommaSpace);
       
  1727 				deleteLastSeparator=ETrue;
       
  1728 				}
       
  1729 			const TCoeInputCapabilities::MCoeFepSpecificExtensions* const fepSpecificInputCapabilityExtensions=iInputCapabilities.FepSpecificExtensions(TUid::Uid(KTfep1Uid));
       
  1730 			if (fepSpecificInputCapabilityExtensions!=NULL)
       
  1731 				{
       
  1732 				textToDisplay.Append(KLitExtensionsColonSpace);
       
  1733 				if (fepSpecificInputCapabilityExtensions->SupportsPhoneticAlphabet())
       
  1734 					{
       
  1735 					textToDisplay.Append(KLitPhoneticAlphabet);
       
  1736 					textToDisplay.Append(KLitCommaSpace);
       
  1737 					deleteLastSeparator=ETrue;
       
  1738 					}
       
  1739 				}
       
  1740 			if (deleteLastSeparator)
       
  1741 				{
       
  1742 				const TInt lengthToDelete=KLitCommaSpace().Length();
       
  1743 				textToDisplay.Delete(textToDisplay.Length()-lengthToDelete, lengthToDelete);
       
  1744 				}
       
  1745 			}
       
  1746 		textToDisplay.Append(KLitClosingSquareBracket);
       
  1747 		temp.iTl.iY=temp.iBr.iY;
       
  1748 		temp.iBr.iY=rectangle.iBr.iY;
       
  1749 		__ASSERT_DEBUG(temp.iBr.iY==temp.iTl.iY+statusFontHeightInPixels+EGapBelowBottomStatusLine, Panic(EPanicBadHeight));
       
  1750 		graphicsContext.DrawText(textToDisplay, temp, statusFontAscentInPixels, CGraphicsContext::ELeft, EGapLeftOfEachLine);
       
  1751 		graphicsContext.DiscardFont();
       
  1752 		}
       
  1753 	}
       
  1754 
       
  1755 void CTstControl::DrawText(const TParam& aParam, const TLineInfo& aLineInfo, const TCharFormat& aFormat, const TDesC& aText, const TPoint& aTextOrigin, TInt aExtraPixels) const
       
  1756 	{
       
  1757 	MFormCustomDraw::DrawText(aParam, aLineInfo, aFormat, aText, aTextOrigin, aExtraPixels);
       
  1758 	// ?? draw the dotted underline whose phase starts at aParam.iTextLayoutTopLeft.iX
       
  1759 	}
       
  1760 
       
  1761 void CTstControl::GetFormatOfFepInlineText(TCharFormat& aFormat, TInt& aNumberOfCharactersWithSameFormat, TInt aPositionOfCharacter) const
       
  1762 	{
       
  1763 	const TInt lengthOfSelection=iSelectedCompositionText.Length();
       
  1764 	const TInt startOfSelectedInlineText=iSelectedCompositionText.LowerPos();
       
  1765 	const TInt endOfSelectedInlineText=iSelectedCompositionText.HigherPos();
       
  1766 	const MCoeFepAwareTextEditor& fepAwareTextEditor=*iInputCapabilities.FepAwareTextEditor();
       
  1767 	TCursorSelection cursorSelection;
       
  1768 	fepAwareTextEditor.GetCursorSelectionForFep(cursorSelection);
       
  1769 	TCharFormat formatBeforeInlineText;
       
  1770 	GetFormatAtDocumentPosition(formatBeforeInlineText, cursorSelection.LowerPos()-1, fepAwareTextEditor);
       
  1771 	TCharFormat formatAfterInlineText;
       
  1772 	GetFormatAtDocumentPosition(formatAfterInlineText, cursorSelection.HigherPos()+1, fepAwareTextEditor);
       
  1773 	aFormat=formatBeforeInlineText;
       
  1774 	if ((lengthOfSelection>0) && (aPositionOfCharacter>=startOfSelectedInlineText) && (aPositionOfCharacter<endOfSelectedInlineText))
       
  1775 		{
       
  1776 		aFormat.iFontPresentation.iTextColor=KRgbGreen;
       
  1777 		}
       
  1778 	else
       
  1779 		{
       
  1780 		aFormat.iFontPresentation.iTextColor=KRgbRed;
       
  1781 		}
       
  1782 	if ((formatBeforeInlineText.iFontPresentation.iUnderline!=EUnderlineOn) && (formatAfterInlineText.iFontPresentation.iUnderline!=EUnderlineOn))
       
  1783 		{
       
  1784 		aFormat.iFontPresentation.iUnderline=EUnderlineOn;
       
  1785 		}
       
  1786 	else if ((formatBeforeInlineText.iFontPresentation.iUnderline!=EUnderlineOff) && (formatAfterInlineText.iFontPresentation.iUnderline!=EUnderlineOff))
       
  1787 		{
       
  1788 		aFormat.iFontPresentation.iUnderline=EUnderlineOff;
       
  1789 		}
       
  1790 	else
       
  1791 		{
       
  1792 		aFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
       
  1793 		}
       
  1794 	const TInt endOfRunOfCharactersOfSameFormat=((lengthOfSelection==0) || (aPositionOfCharacter>=endOfSelectedInlineText))?
       
  1795 													iBuffer.Length():
       
  1796 												(aPositionOfCharacter>=startOfSelectedInlineText)?
       
  1797 													endOfSelectedInlineText:
       
  1798 													startOfSelectedInlineText;
       
  1799 	aNumberOfCharactersWithSameFormat=endOfRunOfCharactersOfSameFormat-aPositionOfCharacter;
       
  1800 	}
       
  1801 
       
  1802 void CTstControl::HandlePointerEventInInlineTextL(TPointerEvent::TType aType, TUint, TInt aPositionInInlineText)
       
  1803 	{
       
  1804 	MCoeFepAwareTextEditor* const fepAwareTextEditor=iInputCapabilities.FepAwareTextEditor();
       
  1805 	__ASSERT_DEBUG(fepAwareTextEditor!=NULL, Panic(EPanicNoFepAwareTextEditorAlthoughCurrentlyInlineEditing));
       
  1806 	const TCursorSelection oldSelectedCompositionText=iSelectedCompositionText;
       
  1807 	switch (aType)
       
  1808 		{
       
  1809 	case TPointerEvent::EButton1Down:
       
  1810 		iSelectedCompositionText.iAnchorPos=aPositionInInlineText;
       
  1811 		// fall through
       
  1812 	case TPointerEvent::EDrag:
       
  1813 		iSelectedCompositionText.iCursorPos=aPositionInInlineText;
       
  1814 		break;
       
  1815 #if defined(__GCC32__)
       
  1816 	default:
       
  1817 		break;
       
  1818 #endif
       
  1819 		}
       
  1820 	if ((iSelectedCompositionText.iCursorPos!=oldSelectedCompositionText.iCursorPos) || (iSelectedCompositionText.iAnchorPos!=oldSelectedCompositionText.iAnchorPos))
       
  1821 		{
       
  1822 		fepAwareTextEditor->UpdateFepInlineTextL(iBuffer, iSelectedCompositionText.iCursorPos);
       
  1823 		}
       
  1824 	}
       
  1825 
       
  1826 void CTstControl::ExecuteFunctionL()
       
  1827 	{
       
  1828 	InsertCompositionCharacterAndDrawNowL(iCharacterCode);
       
  1829 	}
       
  1830 
       
  1831 // CTstControl::CStateInformation
       
  1832 
       
  1833 CTstControl::CStateInformation* CTstControl::CStateInformation::NewLC(TInt aMeaninglessNumber)
       
  1834 	{
       
  1835 	CStateInformation* const stateInformation=new(ELeave) CStateInformation;
       
  1836 	CleanupStack::PushL(stateInformation);
       
  1837 	stateInformation->ConstructL(aMeaninglessNumber);
       
  1838 	return stateInformation;
       
  1839 	}
       
  1840 
       
  1841 CTstControl::CStateInformation::~CStateInformation()
       
  1842 	{
       
  1843 	delete iMeaninglessNumber;
       
  1844 	}
       
  1845 
       
  1846 CTstControl::CStateInformation::CStateInformation()
       
  1847 	:iMeaninglessNumber(NULL)
       
  1848 	{
       
  1849 	}
       
  1850 
       
  1851 void CTstControl::CStateInformation::ConstructL(TInt aMeaninglessNumber)
       
  1852 	{
       
  1853 	BaseConstructL();
       
  1854 	iMeaninglessNumber=new(ELeave) TInt(aMeaninglessNumber);
       
  1855 	}
       
  1856 
       
  1857 // CTstFep
       
  1858 
       
  1859 CTstFep::CTstFep(CCoeEnv& aConeEnvironment)
       
  1860 	:CCoeFep(aConeEnvironment)
       
  1861 	{
       
  1862 	}
       
  1863 
       
  1864 void CTstFep::ConstructL(const CCoeFepParameters& aFepParameters)
       
  1865 	{
       
  1866 	BaseConstructL(aFepParameters);
       
  1867 	iControl=CTstControl::NewL(*this);
       
  1868 	ReadAllAttributesL();
       
  1869 	iControl->ActivateL();
       
  1870 	}
       
  1871 
       
  1872 CTstFep::~CTstFep()
       
  1873 	{
       
  1874 	delete iControl;
       
  1875 	}
       
  1876 
       
  1877 void CTstFep::CancelTransaction()
       
  1878 	{
       
  1879 	iControl->CancelTransaction();
       
  1880 	}
       
  1881 
       
  1882 void CTstFep::IsOnHasChangedState()
       
  1883 	{
       
  1884 	iControl->IsOnHasChangedState();
       
  1885 	}
       
  1886 
       
  1887 void CTstFep::OfferKeyEventL(TEventResponse& aEventResponse, const TKeyEvent& aKeyEvent, TEventCode aEventCode)
       
  1888 	{
       
  1889 	// this function must correctly set aEventResponse *before* calling anything that can leave
       
  1890 	aEventResponse=EEventWasConsumed; // this assumes that CTstControl::OfferKeyEventL will not leave if it returns EKeyWasNotConsumed
       
  1891 	switch (iControl->OfferKeyEventL(aKeyEvent, aEventCode))
       
  1892 		{
       
  1893 	case EKeyWasNotConsumed:
       
  1894 		aEventResponse=EEventWasNotConsumed;
       
  1895 		break;
       
  1896 	case EKeyWasConsumed:
       
  1897 		aEventResponse=EEventWasConsumed;
       
  1898 		break;
       
  1899 #if defined(_DEBUG)
       
  1900 	default:
       
  1901 		Panic(EPanicBadKeyResponse);
       
  1902 		break;
       
  1903 #endif
       
  1904 		}
       
  1905 	}
       
  1906 
       
  1907 void CTstFep::OfferPointerEventL(TEventResponse& aEventResponse, const TPointerEvent& aPointerEvent, const CCoeControl* aWindowOwningControl)
       
  1908 	{
       
  1909 	iControl->OfferPointerEventL(aEventResponse, aPointerEvent, aWindowOwningControl);
       
  1910 	}
       
  1911 
       
  1912 void CTstFep::OfferPointerBufferReadyEventL(TEventResponse& aEventResponse, const CCoeControl*)
       
  1913 	{
       
  1914 	aEventResponse=EEventWasNotConsumed;
       
  1915 	}
       
  1916 
       
  1917 TInt CTstFep::NumberOfAttributes() const
       
  1918 	{
       
  1919 	return CTstControl::NumberOfAttributes();
       
  1920 	}
       
  1921 
       
  1922 TUid CTstFep::AttributeAtIndex(TInt aIndex) const
       
  1923 	{
       
  1924 	return CTstControl::AttributeAtIndex(aIndex);
       
  1925 	}
       
  1926 
       
  1927 void CTstFep::WriteAttributeDataToStreamL(TUid aAttributeUid, RWriteStream& aStream) const
       
  1928 	{
       
  1929 	iControl->WriteAttributeDataToStreamL(aAttributeUid, aStream);
       
  1930 	}
       
  1931 
       
  1932 void CTstFep::ReadAttributeDataFromStreamL(TUid aAttributeUid, RReadStream& aStream)
       
  1933 	{
       
  1934 	iControl->ReadAttributeDataFromStreamL(aAttributeUid, aStream);
       
  1935 	}
       
  1936 
       
  1937 void CTstFep::HandleGainingForeground()
       
  1938 	{
       
  1939 	iControl->HandleGainingForeground();
       
  1940 	}
       
  1941 
       
  1942 void CTstFep::HandleLosingForeground()
       
  1943 	{
       
  1944 	iControl->HandleLosingForeground();
       
  1945 	}
       
  1946 
       
  1947 void CTstFep::HandleChangeInFocus()
       
  1948 	{
       
  1949 	iControl->HandleChangeInFocus();
       
  1950 	}
       
  1951 
       
  1952 void CTstFep::HandleDestructionOfFocusedItem()
       
  1953 	{
       
  1954 	iControl->HandleDestructionOfFocusedItem();
       
  1955 	}
       
  1956 
       
  1957 // TTstResourceFileId
       
  1958 
       
  1959 #pragma warning(disable: 4355) // "'this' : used in base member initializer list"
       
  1960 
       
  1961 TTstResourceFileId::TTstResourceFileId(CCoeEnv& aConeEnvironment, TInt aResourceFileId)
       
  1962 	:TCleanupItem(UnloadResourceFile, this),
       
  1963 	 iConeEnvironment(aConeEnvironment),
       
  1964 	 iResourceFileId(aResourceFileId)
       
  1965 	{
       
  1966 	}
       
  1967 
       
  1968 #pragma warning(default: 4355)
       
  1969 
       
  1970 void TTstResourceFileId::UnloadResourceFile(TAny* aThis)
       
  1971 	{
       
  1972 	TTstResourceFileId& resourceFileId=*STATIC_CAST(TTstResourceFileId*, aThis);
       
  1973 	resourceFileId.iConeEnvironment.DeleteResourceFile(resourceFileId.iResourceFileId);
       
  1974 	}
       
  1975 
       
  1976 // CTstSettingsDialog
       
  1977 
       
  1978 CTstSettingsDialog::CTstSettingsDialog()
       
  1979 	:iInlineEditingEnabled(ETrue),
       
  1980 	 iInputMethod(0)
       
  1981 	{
       
  1982 	}
       
  1983 
       
  1984 TBool CTstSettingsDialog::OkToExitL(TInt aButtonId)
       
  1985 	{
       
  1986 	__ASSERT_ALWAYS(aButtonId==EEikBidOk, Panic(EPanicUnexpectedButtonId));
       
  1987 	switch (STATIC_CAST(CEikCheckBox*, Control(EControlIdInlineEditingEnabled))->State())
       
  1988 		{
       
  1989 	case CEikButtonBase::EClear:
       
  1990 		iInlineEditingEnabled=EFalse;
       
  1991 		break;
       
  1992 	case CEikButtonBase::ESet:
       
  1993 		iInlineEditingEnabled=ETrue;
       
  1994 		break;
       
  1995 	case CEikButtonBase::EIndeterminate:
       
  1996 #if defined(_DEBUG)
       
  1997 	default:
       
  1998 		Panic(EPanicBadCheckBoxState);
       
  1999 #endif
       
  2000 		break;
       
  2001 		}
       
  2002 	iInputMethod=STATIC_CAST(CEikChoiceListBase*, Control(EControlIdInputMethod))->CurrentItem();
       
  2003 	TFixedArray<TUid, 2> attributeUids;
       
  2004 	__ASSERT_DEBUG(NumberOfAttributes()==2, Panic(EPanicBadNumberOfAttributes));
       
  2005 	attributeUids[0].iUid=AttributeAtIndex(0).iUid;
       
  2006 	attributeUids[1].iUid=AttributeAtIndex(1).iUid;
       
  2007 	WriteAttributeDataAndBroadcastL(*iCoeEnv, attributeUids.Array());
       
  2008 	return ETrue;
       
  2009 	}
       
  2010 
       
  2011 void CTstSettingsDialog::PreLayoutDynInitL()
       
  2012 	{
       
  2013 	ReadAllAttributesL(*iCoeEnv);
       
  2014 	STATIC_CAST(CEikCheckBox*, Control(EControlIdInlineEditingEnabled))->SetState(iInlineEditingEnabled? CEikButtonBase::ESet: CEikButtonBase::EClear);
       
  2015 	STATIC_CAST(CEikChoiceListBase*, Control(EControlIdInputMethod))->SetCurrentItem(iInputMethod);
       
  2016 	}
       
  2017 
       
  2018 TInt CTstSettingsDialog::NumberOfAttributes() const
       
  2019 	{
       
  2020 	return CTstControl::NumberOfAttributes();
       
  2021 	}
       
  2022 
       
  2023 TUid CTstSettingsDialog::AttributeAtIndex(TInt aIndex) const
       
  2024 	{
       
  2025 	return CTstControl::AttributeAtIndex(aIndex);
       
  2026 	}
       
  2027 
       
  2028 void CTstSettingsDialog::WriteAttributeDataToStreamL(TUid aAttributeUid, RWriteStream& aStream) const
       
  2029 	{
       
  2030 	CTstControl::WriteAttributeDataToStreamL(aAttributeUid, aStream, iInlineEditingEnabled, iInputMethod);
       
  2031 	}
       
  2032 
       
  2033 void CTstSettingsDialog::ReadAttributeDataFromStreamL(TUid aAttributeUid, RReadStream& aStream)
       
  2034 	{
       
  2035 	CTstControl::ReadAttributeDataFromStreamL(aAttributeUid, aStream, iInlineEditingEnabled, iInputMethod);
       
  2036 	}
       
  2037 
       
  2038 
       
  2039