textrendering/texthandling/stext/TXTETEXT.CPP
branchRCL_3
changeset 55 336bee5c2d35
parent 54 748ec5531811
equal deleted inserted replaced
54:748ec5531811 55:336bee5c2d35
    39 #include "TXTPLAIN.H"
    39 #include "TXTPLAIN.H"
    40 #include "TXTSTD.H"
    40 #include "TXTSTD.H"
    41 #include "TXTRTPFL.H"
    41 #include "TXTRTPFL.H"
    42 #include "TXTCLIPBOARD.H"
    42 #include "TXTCLIPBOARD.H"
    43 
    43 
    44 #include "OstTraceDefinitions.h"
       
    45 #ifdef OST_TRACE_COMPILER_IN_USE
       
    46 #include "TXTETEXTTraces.h"
       
    47 #endif
       
    48 
       
    49 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    44 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    50 #include "TXTETEXT_INTERNAL.H"
    45 #include "TXTETEXT_INTERNAL.H"
    51 #endif
    46 #endif
    52 
    47 
    53 const TUint KFieldCountLimit = 255;
    48 const TUint KFieldCountLimit = 255;
   261 	}
   256 	}
   262 
   257 
   263 EXPORT_C void CEditableText::StartFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aInitialInlineText,TInt aPositionOfInlineTextInDocument,TInt aNumberOfCharactersToHide,MFepInlineTextFormatRetriever& aInlineTextFormatRetriever)
   258 EXPORT_C void CEditableText::StartFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aInitialInlineText,TInt aPositionOfInlineTextInDocument,TInt aNumberOfCharactersToHide,MFepInlineTextFormatRetriever& aInlineTextFormatRetriever)
   264 /** @internalAll */	
   259 /** @internalAll */	
   265 	{
   260 	{
   266 	if (aPositionOfInlineTextInDocument<0 || aNumberOfCharactersToHide<0 || aPositionOfInlineTextInDocument+aNumberOfCharactersToHide>DocumentLength())
       
   267 	    {
       
   268 	    OstTrace0( TRACE_DUMP, CEDITABLETEXT_STARTFEPINLINEEDITL, "ECharPosBeyondDocument" );
       
   269 	    }
       
   270 	__ASSERT_ALWAYS(aPositionOfInlineTextInDocument>=0 && aNumberOfCharactersToHide>=0 && aPositionOfInlineTextInDocument+aNumberOfCharactersToHide<=DocumentLength(),Panic(ECharPosBeyondDocument));
   261 	__ASSERT_ALWAYS(aPositionOfInlineTextInDocument>=0 && aNumberOfCharactersToHide>=0 && aPositionOfInlineTextInDocument+aNumberOfCharactersToHide<=DocumentLength(),Panic(ECharPosBeyondDocument));
   271 	if (InlineEditData()!=NULL)
       
   272 	    {
       
   273 	    OstTrace0( TRACE_DUMP, DUP1_CEDITABLETEXT_STARTFEPINLINEEDITL, "EAlreadyFepInlineEditing" );
       
   274 	    }
       
   275 	__ASSERT_ALWAYS(InlineEditData()==NULL,Panic(EAlreadyFepInlineEditing));
   262 	__ASSERT_ALWAYS(InlineEditData()==NULL,Panic(EAlreadyFepInlineEditing));
   276 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   263 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   277 	aNumberOfCharactersSuccessfullyDeleted=0;
   264 	aNumberOfCharactersSuccessfullyDeleted=0;
   278 	aNumberOfCharactersSuccessfullyInserted=0;
   265 	aNumberOfCharactersSuccessfullyInserted=0;
   279 	CInlineEditData* const inlineEditData=new(ELeave) CInlineEditData;
   266 	CInlineEditData* const inlineEditData=new(ELeave) CInlineEditData;
   306 
   293 
   307 EXPORT_C void CEditableText::UpdateFepInlineTextL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aNewInlineText)
   294 EXPORT_C void CEditableText::UpdateFepInlineTextL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aNewInlineText)
   308 /** @internalAll */	
   295 /** @internalAll */	
   309     {
   296     {
   310 	CInlineEditData* const inlineEditData=InlineEditData();
   297 	CInlineEditData* const inlineEditData=InlineEditData();
   311 	if (inlineEditData==NULL)
       
   312 	    {
       
   313 	    OstTrace0( TRACE_DUMP, CEDITABLETEXT_UPDATEFEPINLINETEXTL, "ENotCurrentlyFepInlineEditing" );
       
   314 	    }
       
   315 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
   298 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
   316 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   299 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   317 	aNumberOfCharactersSuccessfullyDeleted=0;
   300 	aNumberOfCharactersSuccessfullyDeleted=0;
   318 	aNumberOfCharactersSuccessfullyInserted=0;
   301 	aNumberOfCharactersSuccessfullyInserted=0;
   319 	HBufC*& inlineText=inlineEditData->iInlineText;
   302 	HBufC*& inlineText=inlineEditData->iInlineText;
   320 	HBufC* oldInlineText=inlineText;
   303 	HBufC* oldInlineText=inlineText;
   321 	if (oldInlineText!=NULL && inlineEditData->iLengthOfInlineText!=oldInlineText->Length())
       
   322 	    {
       
   323 	    OstTrace0( TRACE_DUMP, DUP1_CEDITABLETEXT_UPDATEFEPINLINETEXTL, "EDebug" );
       
   324 	    }
       
   325 	__ASSERT_DEBUG(oldInlineText==NULL || inlineEditData->iLengthOfInlineText==oldInlineText->Length(),Panic(EDebug));
   304 	__ASSERT_DEBUG(oldInlineText==NULL || inlineEditData->iLengthOfInlineText==oldInlineText->Length(),Panic(EDebug));
   326 	const TInt lengthOfNewInlineText=aNewInlineText.Length();
   305 	const TInt lengthOfNewInlineText=aNewInlineText.Length();
   327 	if (oldInlineText!=NULL && *oldInlineText==aNewInlineText)
   306 	if (oldInlineText!=NULL && *oldInlineText==aNewInlineText)
   328 		{
   307 		{
   329 		aNumberOfCharactersSuccessfullyDeleted=lengthOfNewInlineText;
   308 		aNumberOfCharactersSuccessfullyDeleted=lengthOfNewInlineText;
   365 /**
   344 /**
   366  * @internalAll
   345  * @internalAll
   367  */	
   346  */	
   368     {
   347     {
   369 	const CInlineEditData* const inlineEditData=InlineEditData();
   348 	const CInlineEditData* const inlineEditData=InlineEditData();
   370 	if (inlineEditData==NULL)
       
   371 	    {
       
   372 	    OstTrace0( TRACE_FATAL, DUP1_CEDITABLETEXT_COMMITFEPINLINEEDITL, "ENotCurrentlyFepInlineEditing" );
       
   373 	    }
       
   374 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
   349 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
   375 	if (inlineEditData->iInlineText!=NULL && inlineEditData->iLengthOfInlineText!=inlineEditData->iInlineText->Length())
       
   376 	    {
       
   377 	    OstTrace0( TRACE_DUMP, CEDITABLETEXT_COMMITFEPINLINEEDITL, "EDebug" );
       
   378 	    }
       
   379 	__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || inlineEditData->iLengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
   350 	__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || inlineEditData->iLengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
   380 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   351 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   381 	const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
   352 	const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
   382 	aNumberOfCharactersSuccessfullyDeleted=lengthOfInlineText;
   353 	aNumberOfCharactersSuccessfullyDeleted=lengthOfInlineText;
   383 	aNumberOfCharactersSuccessfullyInserted=lengthOfInlineText;
   354 	aNumberOfCharactersSuccessfullyInserted=lengthOfInlineText;
   397 	const CInlineEditData* inlineEditData=InlineEditData();
   368 	const CInlineEditData* inlineEditData=InlineEditData();
   398 	if (inlineEditData!=NULL)
   369 	if (inlineEditData!=NULL)
   399 		{
   370 		{
   400 		const TInt positionOfInlineTextInDocument=inlineEditData->iPositionOfInlineTextInDocument;
   371 		const TInt positionOfInlineTextInDocument=inlineEditData->iPositionOfInlineTextInDocument;
   401 		const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
   372 		const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
   402 		if (inlineEditData->iInlineText!=NULL && lengthOfInlineText!=inlineEditData->iInlineText->Length())
       
   403 		    {
       
   404 		    OstTrace0( TRACE_DUMP, CEDITABLETEXT_CANCELFEPINLINEEDIT, "EDebug" );
       
   405 		    }
       
   406 		__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || lengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
   373 		__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || lengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
   407 		TRAPD(notUsed,
   374 		TRAPD(notUsed,
   408 						if (lengthOfInlineText>0)
   375 						if (lengthOfInlineText>0)
   409 							{
   376 							{
   410 							aParagraphContainingStartPositionOfInlineTextHasChangedFormat=DeleteWithoutDestroyingFormatL(positionOfInlineTextInDocument,lengthOfInlineText);
   377 							aParagraphContainingStartPositionOfInlineTextHasChangedFormat=DeleteWithoutDestroyingFormatL(positionOfInlineTextInDocument,lengthOfInlineText);
   412 							aPositionOfInsertionPointInDocument=inlineEditData->iPositionOfInlineTextInDocument;
   379 							aPositionOfInsertionPointInDocument=inlineEditData->iPositionOfInlineTextInDocument;
   413 							}
   380 							}
   414 						const HBufC* const hiddenText=inlineEditData->iHiddenText;
   381 						const HBufC* const hiddenText=inlineEditData->iHiddenText;
   415 						if (hiddenText!=NULL)
   382 						if (hiddenText!=NULL)
   416 							{
   383 							{
   417 							if (hiddenText->Length()<=0)
       
   418 							    {
       
   419 							    OstTrace0( TRACE_DUMP, DUP1_CEDITABLETEXT_CANCELFEPINLINEEDIT, "EDebug" );
       
   420 							    }
       
   421 							__ASSERT_DEBUG(hiddenText->Length()>0, Panic(EDebug));
   384 							__ASSERT_DEBUG(hiddenText->Length()>0, Panic(EDebug));
   422 							InsertL(positionOfInlineTextInDocument,*hiddenText);
   385 							InsertL(positionOfInlineTextInDocument,*hiddenText);
   423 							aNumberOfCharactersSuccessfullyInserted=hiddenText->Length();
   386 							aNumberOfCharactersSuccessfullyInserted=hiddenText->Length();
   424 							aPositionOfInsertionPointInDocument=aNewPositionOfInsertionPointInDocument;
   387 							aPositionOfInsertionPointInDocument=aNewPositionOfInsertionPointInDocument;
   425 							}
   388 							}
   597 
   560 
   598 EXPORT_C void CPlainText::DoConstructL(TDocumentStorage aStorage,TInt aDefaultTextGranularity,MTextFieldFactory* aFieldFactory)
   561 EXPORT_C void CPlainText::DoConstructL(TDocumentStorage aStorage,TInt aDefaultTextGranularity,MTextFieldFactory* aFieldFactory)
   599 /** Allocates storage of CBufFlat or CBufSeg, according to the parameter aStorage.
   562 /** Allocates storage of CBufFlat or CBufSeg, according to the parameter aStorage.
   600 Creates & initializes the field set.*/
   563 Creates & initializes the field set.*/
   601 	{
   564 	{
   602 	if (iByteStore!=NULL)
       
   603 	    {
       
   604 	    OstTrace0( TRACE_DUMP, CPLAINTEXT_DOCONSTRUCTL, "EConstructCalledTwice" );
       
   605 	    }
       
   606 	__ASSERT_DEBUG(iByteStore==NULL,Panic(EConstructCalledTwice));
   565 	__ASSERT_DEBUG(iByteStore==NULL,Panic(EConstructCalledTwice));
   607 	
   566 	
   608 	iByteStore=(aStorage==ESegmentedStorage)
   567 	iByteStore=(aStorage==ESegmentedStorage)
   609 		? (CBufBase*)CBufSeg::NewL(aDefaultTextGranularity*sizeof(TText))
   568 		? (CBufBase*)CBufSeg::NewL(aDefaultTextGranularity*sizeof(TText))
   610 		: (CBufBase*)CBufFlat::NewL(aDefaultTextGranularity*sizeof(TText));
   569 		: (CBufBase*)CBufFlat::NewL(aDefaultTextGranularity*sizeof(TText));
   923 
   882 
   924 TStreamId CPlainText::DoCopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const
   883 TStreamId CPlainText::DoCopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const
   925 	{
   884 	{
   926 	__TEST_INVARIANT;
   885 	__TEST_INVARIANT;
   927 	TInt documentLength = DocumentLength();
   886 	TInt documentLength = DocumentLength();
   928 	if (aPos < 0 || aPos > documentLength)
       
   929 	    {
       
   930 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOCOPYTOSTOREL, "ECharPosBeyondDocument" );
       
   931 	    }
       
   932 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
   887 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
   933 	if (aLength < 0)
       
   934 	    {
       
   935 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_DOCOPYTOSTOREL, "ECopyToStreamNegativeLength" );
       
   936 	    }
       
   937 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
   888 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
   938 	if (aPos + aLength > documentLength)
       
   939 	    {
       
   940 	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_DOCOPYTOSTOREL, "ECharPosBeyondDocument" );
       
   941 	    }
       
   942 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
   889 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
   943 
   890 
   944 	if (aLength == 0)
   891 	if (aLength == 0)
   945 		return KNullStreamId;
   892 		return KNullStreamId;
   946 
   893 
   975 // Write the plain text to the stream.
   922 // Write the plain text to the stream.
   976 void CPlainText::CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength)const
   923 void CPlainText::CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength)const
   977 	{
   924 	{
   978 	__TEST_INVARIANT;
   925 	__TEST_INVARIANT;
   979 	TInt documentLength = DocumentLength();
   926 	TInt documentLength = DocumentLength();
   980 	if (aPos < 0 || aPos > documentLength)
       
   981 	    {
       
   982 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_COPYTOSTREAML, "ECharPosBeyondDocument" );
       
   983 	    }
       
   984 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
   927 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
   985 	if (aLength < 0)
       
   986 	    {
       
   987 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_COPYTOSTREAML, "ECopyToStreamNegativeLength" );
       
   988 	    }
       
   989 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
   928 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
   990 	if (aPos + aLength > documentLength)
       
   991 	    {
       
   992 	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_COPYTOSTREAML, "ECharPosBeyondDocument" );
       
   993 	    }
       
   994 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
   929 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
   995 
   930 
   996 	aStream.WriteInt32L(aLength);
   931 	aStream.WriteInt32L(aLength);
   997 	::ExternalizeTextL(aStream,*iByteStore,aPos,aLength,FALSE);
   932 	::ExternalizeTextL(aStream,*iByteStore,aPos,aLength,FALSE);
   998 
   933 
  1024 	}
   959 	}
  1025 
   960 
  1026 
   961 
  1027 TInt CPlainText::DoPasteFromStoreL(const CStreamStore& aStore,TStreamId aStreamId,TInt aPos)
   962 TInt CPlainText::DoPasteFromStoreL(const CStreamStore& aStore,TStreamId aStreamId,TInt aPos)
  1028 	{
   963 	{
  1029 	if (aPos>DocumentLength())
       
  1030 	    {
       
  1031 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOPASTEFROMSTOREL, "ECharPosBeyondDocument" );
       
  1032 	    }
       
  1033 	__ASSERT_ALWAYS(aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
   964 	__ASSERT_ALWAYS(aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1034 
   965 
  1035 	TInt charsPasted=0;
   966 	TInt charsPasted=0;
  1036 	if (aStreamId!=KNullStreamId)
   967 	if (aStreamId!=KNullStreamId)
  1037 		{// There is a recognised type in the clipboard.
   968 		{// There is a recognised type in the clipboard.
  1074 	implied elsewhere, such as in the formatting information stored in CRichText objects.
  1005 	implied elsewhere, such as in the formatting information stored in CRichText objects.
  1075 	*/
  1006 	*/
  1076 	if (error != KErrNone)
  1007 	if (error != KErrNone)
  1077 		{
  1008 		{
  1078 		DoPtDelete(aPos,chars_read);
  1009 		DoPtDelete(aPos,chars_read);
  1079 		OstTrace1( TRACE_FATAL, DUP1_CPLAINTEXT_PASTEFROMSTREAML, "Leave code=%d", error );
       
  1080 		User::Leave(error);
  1010 		User::Leave(error);
  1081 		}
  1011 		}
  1082 
  1012 
  1083 	__TEST_INVARIANT;
  1013 	__TEST_INVARIANT;
  1084 	return chars_read;
  1014 	return chars_read;
  1126 
  1056 
  1127 void CPlainText::InsertEodL()
  1057 void CPlainText::InsertEodL()
  1128 /** Inserts the end-of-document character upon document construction.*/
  1058 /** Inserts the end-of-document character upon document construction.*/
  1129 	{
  1059 	{
  1130 // ASSERT: The plain text component is empty.
  1060 // ASSERT: The plain text component is empty.
  1131 	if (DocumentLength()!=-1)
       
  1132 	    {
       
  1133 	    OstTrace0( TRACE_DUMP, DUP1_CPLAINTEXT_INSERTEODL, "ECorruptTextStore" );
       
  1134 	    }
       
  1135 	__ASSERT_DEBUG(DocumentLength()==-1,Panic(ECorruptTextStore));
  1061 	__ASSERT_DEBUG(DocumentLength()==-1,Panic(ECorruptTextStore));
  1136 	TBuf<1> content;
  1062 	TBuf<1> content;
  1137 	content.Append(EParagraphDelimiter);
  1063 	content.Append(EParagraphDelimiter);
  1138 	TPtrC eod(content);
  1064 	TPtrC eod(content);
  1139 	DoPtInsertL(0,eod);
  1065 	DoPtInsertL(0,eod);
  1173 
  1099 
  1174 @return The number of characters in the text object. */
  1100 @return The number of characters in the text object. */
  1175 	{return ((iByteStore->Size()/sizeof(TText))-1);}
  1101 	{return ((iByteStore->Size()/sizeof(TText))-1);}
  1176 
  1102 
  1177 
  1103 
       
  1104 
       
  1105 
  1178 EXPORT_C void CPlainText::InsertL(TInt aInsertPos,const TChar& aChar)
  1106 EXPORT_C void CPlainText::InsertL(TInt aInsertPos,const TChar& aChar)
  1179 /** Inserts either a single character or a descriptor into the text object
  1107 /** Inserts either a single character or a descriptor into the text object
  1180 at a specified document position.
  1108 at a specified document position.
  1181 
  1109 
  1182 Updates the page table.
  1110 Updates the page table.
  1185 Must be valid, or a panic occurs.
  1113 Must be valid, or a panic occurs.
  1186 @param aChar The character to insert.
  1114 @param aChar The character to insert.
  1187 @param aBuf The descriptor to insert. */
  1115 @param aBuf The descriptor to insert. */
  1188 	{
  1116 	{
  1189 	__TEST_INVARIANT;
  1117 	__TEST_INVARIANT;
  1190 	if (aInsertPos<0 || aInsertPos>DocumentLength())
       
  1191 	    {
       
  1192 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_INSERTL, "ECharPosBeyondDocument" );
       
  1193 	    }
       
  1194 	__ASSERT_ALWAYS(aInsertPos>=0 && aInsertPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1118 	__ASSERT_ALWAYS(aInsertPos>=0 && aInsertPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1195 
  1119 
  1196 	TInt contentLength = 1;
  1120 	TBuf<1> content;
  1197 	if (aChar < 0x10000)
  1121 	content.Append(aChar);
  1198 		{
  1122 	DoPtInsertL(aInsertPos,content);
  1199 		TBuf<1> content;
       
  1200 		content.Append(aChar);
       
  1201 		DoPtInsertL(aInsertPos,content);
       
  1202 		}
       
  1203 	else
       
  1204 		{
       
  1205 		TText16 high = TChar::GetHighSurrogate(aChar);
       
  1206 		TText16 low = TChar::GetLowSurrogate(aChar);
       
  1207 		RDebug::Print(_L("CPlainText::InsertL(%d), %X expand to %X %X."), aInsertPos, TUint(aChar), high, low);
       
  1208 	
       
  1209 		TBuf<2> content;
       
  1210 		contentLength = 2;
       
  1211 		content.Append(high);
       
  1212 		content.Append(low);
       
  1213 		DoPtInsertL(aInsertPos,content);
       
  1214 		}
       
  1215 	if (FieldSetPresent())
  1123 	if (FieldSetPresent())
  1216 		iFieldSet->NotifyInsertion(aInsertPos,contentLength);
  1124 		iFieldSet->NotifyInsertion(aInsertPos,content.Length()); // length always 1 - optimise???
  1217 
       
  1218 	SetHasChanged(ETrue);
  1125 	SetHasChanged(ETrue);
  1219 
  1126 
  1220 	__TEST_INVARIANT;
  1127 	__TEST_INVARIANT;
  1221 	}
  1128 	}
  1222 
  1129 
  1232 EXPORT_C void CPlainText::PtInsertL(TInt aPos,const TDesC& aBuf)
  1139 EXPORT_C void CPlainText::PtInsertL(TInt aPos,const TDesC& aBuf)
  1233 /** Inserts the contents a aBuf into the document at position aInsertPos.
  1140 /** Inserts the contents a aBuf into the document at position aInsertPos.
  1234 Maintain field set.*/
  1141 Maintain field set.*/
  1235 	{
  1142 	{
  1236 	__TEST_INVARIANT;
  1143 	__TEST_INVARIANT;
  1237 	if (aPos<0 || aPos>DocumentLength())
       
  1238 	    {
       
  1239 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_PTINSERTL, "ECharPosBeyondDocument" );
       
  1240 	    }
       
  1241 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1144 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1242 
  1145 
  1243 	DoPtInsertL(aPos,aBuf);
  1146 	DoPtInsertL(aPos,aBuf);
  1244 	if (FieldSetPresent())
  1147 	if (FieldSetPresent())
  1245 		iFieldSet->NotifyInsertion(aPos,aBuf.Length());
  1148 		iFieldSet->NotifyInsertion(aPos,aBuf.Length());
  1321  must be reformatted.
  1224  must be reformatted.
  1322  In global text, this clearly has no reasonable meaning, so always returns
  1225  In global text, this clearly has no reasonable meaning, so always returns
  1323  EFalse, so no reformatting occurs.*/
  1226  EFalse, so no reformatting occurs.*/
  1324 	{
  1227 	{
  1325 	TInt documentLength=DocumentLength()+1;
  1228 	TInt documentLength=DocumentLength()+1;
  1326 	if (aPos<0 || aPos>documentLength)
       
  1327 	    {
       
  1328 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOPTDELETE, "ECharPosBeyondDocument" );
       
  1329 	    }
       
  1330 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
  1229 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
  1331 	if (aLength<0)
       
  1332 	    {
       
  1333 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_DOPTDELETE, "EDeleteNegativeLength" );
       
  1334 	    }
       
  1335 	__ASSERT_ALWAYS(aLength>=0,Panic(EDeleteNegativeLength));
  1230 	__ASSERT_ALWAYS(aLength>=0,Panic(EDeleteNegativeLength));
  1336 	if (aPos+aLength>documentLength)
       
  1337 	    {
       
  1338 	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_DOPTDELETE, "ECharPosBeyondDocument" );
       
  1339 	    }
       
  1340 	__ASSERT_ALWAYS(aPos+aLength<=documentLength,Panic(ECharPosBeyondDocument));
  1231 	__ASSERT_ALWAYS(aPos+aLength<=documentLength,Panic(ECharPosBeyondDocument));
  1341 
  1232 
  1342 	iByteStore->Delete(aPos*sizeof(TText),aLength*sizeof(TText));
  1233 	iByteStore->Delete(aPos*sizeof(TText),aLength*sizeof(TText));
  1343 	UpdatePageTable(aPos,-aLength);
  1234 	UpdatePageTable(aPos,-aLength);
  1344 
  1235 
  1382 			input_stream.Close();
  1273 			input_stream.Close();
  1383 			}
  1274 			}
  1384 		file.Close();
  1275 		file.Close();
  1385 		file_session.Close();
  1276 		file_session.Close();
  1386 		}
  1277 		}
  1387 	if (error < 0)
       
  1388 	    {
       
  1389 	    OstTrace1( TRACE_FATAL, DUP1_CPLAINTEXT_IMPORTTEXTFILEL, "Leave code=%x", error );
       
  1390 	    }
       
  1391 	User::LeaveIfError(error);
  1278 	User::LeaveIfError(error);
  1392 	return chars_inserted;
  1279 	return chars_inserted;
  1393 	}
  1280 	}
  1394 
  1281 
  1395 
  1282 
  1410 If EOrganiseByParagraph, lines do not wrap and paragraph delimiters are 
  1297 If EOrganiseByParagraph, lines do not wrap and paragraph delimiters are 
  1411 converted into CR/LF pairs.
  1298 converted into CR/LF pairs.
  1412 @param aMaxLineLength The maximum number of characters in each line, (only 
  1299 @param aMaxLineLength The maximum number of characters in each line, (only 
  1413 relevant if the text organisation is EOrganiseByLine). */
  1300 relevant if the text organisation is EOrganiseByLine). */
  1414 	{
  1301 	{
  1415 	if (aTextOrganisation != EOrganiseByParagraph && aLineWrap <= 0)
       
  1416 	    {
       
  1417 	    OstTrace0( TRACE_DUMP, CPLAINTEXT_EXPORTASTEXTL, "EExportLineWrapInvalid" );
       
  1418 	    }
       
  1419 	__ASSERT_DEBUG(aTextOrganisation == EOrganiseByParagraph || aLineWrap > 0,Panic(EExportLineWrapInvalid));
  1302 	__ASSERT_DEBUG(aTextOrganisation == EOrganiseByParagraph || aLineWrap > 0,Panic(EExportLineWrapInvalid));
  1420 	RFs file_session;
  1303 	RFs file_session;
  1421 	TInt error = file_session.Connect();
  1304 	TInt error = file_session.Connect();
  1422 	if (error == KErrNone)
  1305 	if (error == KErrNone)
  1423 		{
  1306 		{
  1432 			output_stream.Close();
  1315 			output_stream.Close();
  1433 			}
  1316 			}
  1434 		file.Close();
  1317 		file.Close();
  1435 		file_session.Close();
  1318 		file_session.Close();
  1436 		}
  1319 		}
  1437 	if (error < 0)
       
  1438 	    {
       
  1439 	    OstTrace1( TRACE_FATAL, DUP2_CPLAINTEXT_EXPORTASTEXTL, "Leave code=%x", error );
       
  1440 	    }
       
  1441 	User::LeaveIfError(error);
  1320 	User::LeaveIfError(error);
  1442 	}
  1321 	}
  1443 
  1322 
  1444 
  1323 
  1445 
  1324 
  1589 @param aStartPos The document position at which to begin reading. Must be valid or a panic occurs.
  1468 @param aStartPos The document position at which to begin reading. Must be valid or a panic occurs.
  1590 @return Constant pointer to a section of the text object. 
  1469 @return Constant pointer to a section of the text object. 
  1591 */	
  1470 */	
  1592     {
  1471     {
  1593 	__TEST_INVARIANT;
  1472 	__TEST_INVARIANT;
  1594 	if (aStartPos<0 || aStartPos>DocumentLength())
       
  1595 	    {
       
  1596 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_READ, "ECharPosBeyondDocument" );
       
  1597 	    }
       
  1598 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1473 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1599 	
  1474 	
  1600 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
  1475 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
  1601 	return TPtrC((TText*)buf.Ptr(),buf.Length()/sizeof(TText));
  1476 	return TPtrC((TText*)buf.Ptr(),buf.Length()/sizeof(TText));
  1602 	}
  1477 	}
  1619 @param aLength The number of characters to read, inclusive of the character at position aStartPos. 
  1494 @param aLength The number of characters to read, inclusive of the character at position aStartPos. 
  1620 @return Constant pointer to a section of the text object.
  1495 @return Constant pointer to a section of the text object.
  1621 */
  1496 */
  1622 	{
  1497 	{
  1623 	__TEST_INVARIANT;
  1498 	__TEST_INVARIANT;
  1624 	if (aStartPos<0 || aStartPos>DocumentLength())
       
  1625 	    {
       
  1626 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_READ, "ECharPosBeyondDocument" );
       
  1627 	    }
       
  1628 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1499 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1629 	
  1500 	
  1630 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
  1501 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
  1631 	TInt length=Min(aLength,((TInt)buf.Length()/sizeof(TText)));
  1502 	TInt length=Min(aLength,((TInt)buf.Length()/sizeof(TText)));
  1632 	return TPtrC((TText*)buf.Ptr(),length);
  1503 	return TPtrC((TText*)buf.Ptr(),length);
  1646 @param aPos The document position from which to copy. Must be valid or a 
  1517 @param aPos The document position from which to copy. Must be valid or a 
  1647 panic occurs.*/
  1518 panic occurs.*/
  1648     {
  1519     {
  1649 	__TEST_INVARIANT;
  1520 	__TEST_INVARIANT;
  1650 	TInt documentLength=DocumentLength();
  1521 	TInt documentLength=DocumentLength();
  1651 	if (aPos<0 || aPos>documentLength)
       
  1652 	    {
       
  1653 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_EXTRACT, "ECharPosBeyondDocument" );
       
  1654 	    }
       
  1655 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
  1522 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
  1656 	if (aBuf.MaxLength()<documentLength - aPos)
       
  1657 	    {
       
  1658 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_EXTRACT, "EExtractBufferTooSmall" );
       
  1659 	    }
       
  1660 	__ASSERT_ALWAYS(aBuf.MaxLength()>=documentLength - aPos,Panic(EExtractBufferTooSmall));
  1523 	__ASSERT_ALWAYS(aBuf.MaxLength()>=documentLength - aPos,Panic(EExtractBufferTooSmall));
  1661 
  1524 
  1662 	DoExtract(aBuf,aPos,documentLength-aPos);
  1525 	DoExtract(aBuf,aPos,documentLength-aPos);
  1663 	}
  1526 	}
  1664 
  1527 
  1676 @param aPos The document position from which to copy. Must be valid or a panic 
  1539 @param aPos The document position from which to copy. Must be valid or a panic 
  1677 occurs. 
  1540 occurs. 
  1678 @param aLength The number of characters to copy. */
  1541 @param aLength The number of characters to copy. */
  1679 	{
  1542 	{
  1680 	__TEST_INVARIANT;
  1543 	__TEST_INVARIANT;
  1681 	if (aPos<0 || aPos>DocumentLength())
       
  1682 	    {
       
  1683 	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_EXTRACT, "ECharPosBeyondDocument" );
       
  1684 	    }
       
  1685 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1544 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1686 	if (aBuf.MaxLength()<aLength)
       
  1687 	    {
       
  1688 	    OstTrace0( TRACE_FATAL, DUP3_CPLAINTEXT_EXTRACT, "EExtractBufferTooSmall" );
       
  1689 	    }
       
  1690 	__ASSERT_ALWAYS(aBuf.MaxLength()>=aLength,Panic(EExtractBufferTooSmall));
  1545 	__ASSERT_ALWAYS(aBuf.MaxLength()>=aLength,Panic(EExtractBufferTooSmall));
  1691 
  1546 
  1692 	DoExtract(aBuf,aPos,aLength);
  1547 	DoExtract(aBuf,aPos,aLength);
  1693 	}
  1548 	}
  1694 
  1549 
  1695 // Extract text, optionally discarding some characters such as control characters and soft hyphens or
  1550 // Extract text, optionally discarding some characters such as control characters and soft hyphens or
  1696 // inline text, depending on the flag.
  1551 // inline text, depending on the flag.
  1697 EXPORT_C void CPlainText::ExtractSelectively(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags)
  1552 EXPORT_C void CPlainText::ExtractSelectively(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags)
  1698 	{
  1553 	{
  1699 	if (aPos < 0 || aPos > DocumentLength())
       
  1700 	    {
       
  1701 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_EXTRACTSELECTIVELY, "ECharPosBeyondDocument" );
       
  1702 	    }
       
  1703 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= DocumentLength(),Panic(ECharPosBeyondDocument));
  1554 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= DocumentLength(),Panic(ECharPosBeyondDocument));
  1704 	DoExtract(aBuf,aPos,aLength,aFlags);
  1555 	DoExtract(aBuf,aPos,aLength,aFlags);
  1705 	}
  1556 	}
  1706 
  1557 
  1707 
  1558 
  1788 // specified by the character position aPos.
  1639 // specified by the character position aPos.
  1789 // Called from i) Insert  ii) Delete  iii) Paste from clipboard  iv) Text file import.
  1640 // Called from i) Insert  ii) Delete  iii) Paste from clipboard  iv) Text file import.
  1790 //
  1641 //
  1791 	{
  1642 	{
  1792 	__TEST_INVARIANT;
  1643 	__TEST_INVARIANT;
  1793 	if (aPos<0 || aPos>DocumentLength()+1)
       
  1794 	    {
       
  1795 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_UPDATEPAGETABLE, "ECharPosBeyondDocument" );
       
  1796 	    }
       
  1797 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength()+1,Panic(ECharPosBeyondDocument));
  1644 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength()+1,Panic(ECharPosBeyondDocument));
  1798 	
  1645 	
  1799 	if (iPageTable)
  1646 	if (iPageTable)
  1800 		(*iPageTable)[PageContainingPos(aPos)]+=aLength;
  1647 		(*iPageTable)[PageContainingPos(aPos)]+=aLength;
  1801 	}
  1648 	}
  1808 
  1655 
  1809 @param aPos A document position. Must be valid or a panic occurs. 
  1656 @param aPos A document position. Must be valid or a panic occurs. 
  1810 @return The page number containing document position aPos. */
  1657 @return The page number containing document position aPos. */
  1811     {
  1658     {
  1812 	__TEST_INVARIANT;
  1659 	__TEST_INVARIANT;
  1813 	if (aPos<0 || aPos>DocumentLength())
       
  1814 	    {
       
  1815 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_PAGECONTAININGPOS, "ECharPosBeyondDocument" );
       
  1816 	    }
       
  1817 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1660 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1818 
  1661 
  1819     if (!iPageTable || (iPageTable->Count()<1))
  1662     if (!iPageTable || (iPageTable->Count()<1))
  1820         return 0;
  1663         return 0;
  1821     else
  1664     else
  1865 NULL, or a panic occurs. 
  1708 NULL, or a panic occurs. 
  1866 @param aFieldType Identifies the type of field to insert. For the built in 
  1709 @param aFieldType Identifies the type of field to insert. For the built in 
  1867 field types, see the UID values defined in flddef.h. */
  1710 field types, see the UID values defined in flddef.h. */
  1868 	{
  1711 	{
  1869 	__TEST_INVARIANT;
  1712 	__TEST_INVARIANT;
  1870 	if (aPos<0 || aPos>DocumentLength())
       
  1871 	    {
       
  1872 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_INSERTFIELDL, "ECharPosBeyondDocument" );
       
  1873 	    }
       
  1874 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1713 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1875 	if (!aField)
       
  1876 	    {
       
  1877 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_INSERTFIELDL, "ENoTextField" );
       
  1878 	    }
       
  1879 	__ASSERT_ALWAYS(aField,Panic(ENoTextField));
  1714 	__ASSERT_ALWAYS(aField,Panic(ENoTextField));
  1880 
  1715 
  1881 	if (!FieldSetPresent())
  1716 	if (!FieldSetPresent())
  1882 		CreateFieldSetL(DocumentLength());
  1717 		CreateFieldSetL(DocumentLength());
  1883 	iFieldSet->InsertFieldL(aPos,aField,aFieldType);
  1718 	iFieldSet->InsertFieldL(aPos,aField,aFieldType);
  1900 
  1735 
  1901 @param aPos A document position in the field to be updated. Must be a valid 
  1736 @param aPos A document position in the field to be updated. Must be a valid 
  1902 position, or a panic occurs. */
  1737 position, or a panic occurs. */
  1903 	{
  1738 	{
  1904 	__TEST_INVARIANT;
  1739 	__TEST_INVARIANT;
  1905 	if (aPos<0 || aPos>DocumentLength())
       
  1906 	    {
       
  1907 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_UPDATEFIELDL, "ECharPosBeyondDocument" );
       
  1908 	    }
       
  1909 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1740 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1910 
  1741 
  1911 	if (!FieldSetPresent())
  1742 	if (!FieldSetPresent())
  1912 		return;
  1743 		return;
  1913 	TFindFieldInfo info;
  1744 	TFindFieldInfo info;
  1968 valid position or a panic occurs. 
  1799 valid position or a panic occurs. 
  1969 @return ETrue if a field was located at aPos. EFalse if no field was located 
  1800 @return ETrue if a field was located at aPos. EFalse if no field was located 
  1970 at aPos. */
  1801 at aPos. */
  1971 	{
  1802 	{
  1972 	__TEST_INVARIANT;
  1803 	__TEST_INVARIANT;
  1973 	if (aPos<0 || aPos>DocumentLength())
       
  1974 	    {
       
  1975 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_REMOVEFIELD, "ECharPosBeyondDocument" );
       
  1976 	    }
       
  1977 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1804 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1978 
  1805 
  1979 	TBool fieldRemoved=EFalse;
  1806 	TBool fieldRemoved=EFalse;
  1980 	
  1807 	
  1981 	if (FieldSetPresent())
  1808 	if (FieldSetPresent())
  2058 position or a panic occurs. 
  1885 position or a panic occurs. 
  2059 @return ETrue if there was a field located at aPos. EFalse if there was no 
  1886 @return ETrue if there was a field located at aPos. EFalse if there was no 
  2060 field located at aPos. */
  1887 field located at aPos. */
  2061 	{
  1888 	{
  2062 	__TEST_INVARIANT;
  1889 	__TEST_INVARIANT;
  2063 	if (aPos<0 || aPos>DocumentLength())
       
  2064 	    {
       
  2065 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_CONVERTFIELDTOTEXT, "ECharPosBeyondDocument" );
       
  2066 	    }
       
  2067 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1890 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  2068 
  1891 
  2069 	TBool fieldConverted=EFalse;
  1892 	TBool fieldConverted=EFalse;
  2070 	
  1893 	
  2071 	if (FieldSetPresent())
  1894 	if (FieldSetPresent())