textrendering/texthandling/stext/TXTETEXT.CPP
changeset 44 601ab138ba0b
parent 37 6be019398652
child 49 4d76f1414957
equal deleted inserted replaced
37:6be019398652 44:601ab138ba0b
    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 
    44 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    49 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    45 #include "TXTETEXT_INTERNAL.H"
    50 #include "TXTETEXT_INTERNAL.H"
    46 #endif
    51 #endif
    47 
    52 
    48 const TUint KFieldCountLimit = 255;
    53 const TUint KFieldCountLimit = 255;
   256 	}
   261 	}
   257 
   262 
   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)
   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)
   259 /** @internalAll */	
   264 /** @internalAll */	
   260 	{
   265 	{
       
   266 	if (aPositionOfInlineTextInDocument<0 || aNumberOfCharactersToHide<0 || aPositionOfInlineTextInDocument+aNumberOfCharactersToHide>DocumentLength())
       
   267 	    {
       
   268 	    OstTrace0( TRACE_DUMP, CEDITABLETEXT_STARTFEPINLINEEDITL, "ECharPosBeyondDocument" );
       
   269 	    }
   261 	__ASSERT_ALWAYS(aPositionOfInlineTextInDocument>=0 && aNumberOfCharactersToHide>=0 && aPositionOfInlineTextInDocument+aNumberOfCharactersToHide<=DocumentLength(),Panic(ECharPosBeyondDocument));
   270 	__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 	    }
   262 	__ASSERT_ALWAYS(InlineEditData()==NULL,Panic(EAlreadyFepInlineEditing));
   275 	__ASSERT_ALWAYS(InlineEditData()==NULL,Panic(EAlreadyFepInlineEditing));
   263 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   276 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   264 	aNumberOfCharactersSuccessfullyDeleted=0;
   277 	aNumberOfCharactersSuccessfullyDeleted=0;
   265 	aNumberOfCharactersSuccessfullyInserted=0;
   278 	aNumberOfCharactersSuccessfullyInserted=0;
   266 	CInlineEditData* const inlineEditData=new(ELeave) CInlineEditData;
   279 	CInlineEditData* const inlineEditData=new(ELeave) CInlineEditData;
   293 
   306 
   294 EXPORT_C void CEditableText::UpdateFepInlineTextL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aNewInlineText)
   307 EXPORT_C void CEditableText::UpdateFepInlineTextL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aNewInlineText)
   295 /** @internalAll */	
   308 /** @internalAll */	
   296     {
   309     {
   297 	CInlineEditData* const inlineEditData=InlineEditData();
   310 	CInlineEditData* const inlineEditData=InlineEditData();
       
   311 	if (inlineEditData==NULL)
       
   312 	    {
       
   313 	    OstTrace0( TRACE_DUMP, CEDITABLETEXT_UPDATEFEPINLINETEXTL, "ENotCurrentlyFepInlineEditing" );
       
   314 	    }
   298 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
   315 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
   299 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   316 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   300 	aNumberOfCharactersSuccessfullyDeleted=0;
   317 	aNumberOfCharactersSuccessfullyDeleted=0;
   301 	aNumberOfCharactersSuccessfullyInserted=0;
   318 	aNumberOfCharactersSuccessfullyInserted=0;
   302 	HBufC*& inlineText=inlineEditData->iInlineText;
   319 	HBufC*& inlineText=inlineEditData->iInlineText;
   303 	HBufC* oldInlineText=inlineText;
   320 	HBufC* oldInlineText=inlineText;
       
   321 	if (oldInlineText!=NULL && inlineEditData->iLengthOfInlineText!=oldInlineText->Length())
       
   322 	    {
       
   323 	    OstTrace0( TRACE_DUMP, DUP1_CEDITABLETEXT_UPDATEFEPINLINETEXTL, "EDebug" );
       
   324 	    }
   304 	__ASSERT_DEBUG(oldInlineText==NULL || inlineEditData->iLengthOfInlineText==oldInlineText->Length(),Panic(EDebug));
   325 	__ASSERT_DEBUG(oldInlineText==NULL || inlineEditData->iLengthOfInlineText==oldInlineText->Length(),Panic(EDebug));
   305 	const TInt lengthOfNewInlineText=aNewInlineText.Length();
   326 	const TInt lengthOfNewInlineText=aNewInlineText.Length();
   306 	if (oldInlineText!=NULL && *oldInlineText==aNewInlineText)
   327 	if (oldInlineText!=NULL && *oldInlineText==aNewInlineText)
   307 		{
   328 		{
   308 		aNumberOfCharactersSuccessfullyDeleted=lengthOfNewInlineText;
   329 		aNumberOfCharactersSuccessfullyDeleted=lengthOfNewInlineText;
   344 /**
   365 /**
   345  * @internalAll
   366  * @internalAll
   346  */	
   367  */	
   347     {
   368     {
   348 	const CInlineEditData* const inlineEditData=InlineEditData();
   369 	const CInlineEditData* const inlineEditData=InlineEditData();
       
   370 	if (inlineEditData==NULL)
       
   371 	    {
       
   372 	    OstTrace0( TRACE_FATAL, DUP1_CEDITABLETEXT_COMMITFEPINLINEEDITL, "ENotCurrentlyFepInlineEditing" );
       
   373 	    }
   349 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
   374 	__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 	    }
   350 	__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || inlineEditData->iLengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
   379 	__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || inlineEditData->iLengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
   351 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   380 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
   352 	const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
   381 	const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
   353 	aNumberOfCharactersSuccessfullyDeleted=lengthOfInlineText;
   382 	aNumberOfCharactersSuccessfullyDeleted=lengthOfInlineText;
   354 	aNumberOfCharactersSuccessfullyInserted=lengthOfInlineText;
   383 	aNumberOfCharactersSuccessfullyInserted=lengthOfInlineText;
   368 	const CInlineEditData* inlineEditData=InlineEditData();
   397 	const CInlineEditData* inlineEditData=InlineEditData();
   369 	if (inlineEditData!=NULL)
   398 	if (inlineEditData!=NULL)
   370 		{
   399 		{
   371 		const TInt positionOfInlineTextInDocument=inlineEditData->iPositionOfInlineTextInDocument;
   400 		const TInt positionOfInlineTextInDocument=inlineEditData->iPositionOfInlineTextInDocument;
   372 		const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
   401 		const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
       
   402 		if (inlineEditData->iInlineText!=NULL && lengthOfInlineText!=inlineEditData->iInlineText->Length())
       
   403 		    {
       
   404 		    OstTrace0( TRACE_DUMP, CEDITABLETEXT_CANCELFEPINLINEEDIT, "EDebug" );
       
   405 		    }
   373 		__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || lengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
   406 		__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || lengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
   374 		TRAPD(notUsed,
   407 		TRAPD(notUsed,
   375 						if (lengthOfInlineText>0)
   408 						if (lengthOfInlineText>0)
   376 							{
   409 							{
   377 							aParagraphContainingStartPositionOfInlineTextHasChangedFormat=DeleteWithoutDestroyingFormatL(positionOfInlineTextInDocument,lengthOfInlineText);
   410 							aParagraphContainingStartPositionOfInlineTextHasChangedFormat=DeleteWithoutDestroyingFormatL(positionOfInlineTextInDocument,lengthOfInlineText);
   379 							aPositionOfInsertionPointInDocument=inlineEditData->iPositionOfInlineTextInDocument;
   412 							aPositionOfInsertionPointInDocument=inlineEditData->iPositionOfInlineTextInDocument;
   380 							}
   413 							}
   381 						const HBufC* const hiddenText=inlineEditData->iHiddenText;
   414 						const HBufC* const hiddenText=inlineEditData->iHiddenText;
   382 						if (hiddenText!=NULL)
   415 						if (hiddenText!=NULL)
   383 							{
   416 							{
       
   417 							if (hiddenText->Length()<=0)
       
   418 							    {
       
   419 							    OstTrace0( TRACE_DUMP, DUP1_CEDITABLETEXT_CANCELFEPINLINEEDIT, "EDebug" );
       
   420 							    }
   384 							__ASSERT_DEBUG(hiddenText->Length()>0, Panic(EDebug));
   421 							__ASSERT_DEBUG(hiddenText->Length()>0, Panic(EDebug));
   385 							InsertL(positionOfInlineTextInDocument,*hiddenText);
   422 							InsertL(positionOfInlineTextInDocument,*hiddenText);
   386 							aNumberOfCharactersSuccessfullyInserted=hiddenText->Length();
   423 							aNumberOfCharactersSuccessfullyInserted=hiddenText->Length();
   387 							aPositionOfInsertionPointInDocument=aNewPositionOfInsertionPointInDocument;
   424 							aPositionOfInsertionPointInDocument=aNewPositionOfInsertionPointInDocument;
   388 							}
   425 							}
   560 
   597 
   561 EXPORT_C void CPlainText::DoConstructL(TDocumentStorage aStorage,TInt aDefaultTextGranularity,MTextFieldFactory* aFieldFactory)
   598 EXPORT_C void CPlainText::DoConstructL(TDocumentStorage aStorage,TInt aDefaultTextGranularity,MTextFieldFactory* aFieldFactory)
   562 /** Allocates storage of CBufFlat or CBufSeg, according to the parameter aStorage.
   599 /** Allocates storage of CBufFlat or CBufSeg, according to the parameter aStorage.
   563 Creates & initializes the field set.*/
   600 Creates & initializes the field set.*/
   564 	{
   601 	{
       
   602 	if (iByteStore!=NULL)
       
   603 	    {
       
   604 	    OstTrace0( TRACE_DUMP, CPLAINTEXT_DOCONSTRUCTL, "EConstructCalledTwice" );
       
   605 	    }
   565 	__ASSERT_DEBUG(iByteStore==NULL,Panic(EConstructCalledTwice));
   606 	__ASSERT_DEBUG(iByteStore==NULL,Panic(EConstructCalledTwice));
   566 	
   607 	
   567 	iByteStore=(aStorage==ESegmentedStorage)
   608 	iByteStore=(aStorage==ESegmentedStorage)
   568 		? (CBufBase*)CBufSeg::NewL(aDefaultTextGranularity*sizeof(TText))
   609 		? (CBufBase*)CBufSeg::NewL(aDefaultTextGranularity*sizeof(TText))
   569 		: (CBufBase*)CBufFlat::NewL(aDefaultTextGranularity*sizeof(TText));
   610 		: (CBufBase*)CBufFlat::NewL(aDefaultTextGranularity*sizeof(TText));
   882 
   923 
   883 TStreamId CPlainText::DoCopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const
   924 TStreamId CPlainText::DoCopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const
   884 	{
   925 	{
   885 	__TEST_INVARIANT;
   926 	__TEST_INVARIANT;
   886 	TInt documentLength = DocumentLength();
   927 	TInt documentLength = DocumentLength();
       
   928 	if (aPos < 0 || aPos > documentLength)
       
   929 	    {
       
   930 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOCOPYTOSTOREL, "ECharPosBeyondDocument" );
       
   931 	    }
   887 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
   932 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
       
   933 	if (aLength < 0)
       
   934 	    {
       
   935 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_DOCOPYTOSTOREL, "ECopyToStreamNegativeLength" );
       
   936 	    }
   888 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
   937 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
       
   938 	if (aPos + aLength > documentLength)
       
   939 	    {
       
   940 	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_DOCOPYTOSTOREL, "ECharPosBeyondDocument" );
       
   941 	    }
   889 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
   942 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
   890 
   943 
   891 	if (aLength == 0)
   944 	if (aLength == 0)
   892 		return KNullStreamId;
   945 		return KNullStreamId;
   893 
   946 
   922 // Write the plain text to the stream.
   975 // Write the plain text to the stream.
   923 void CPlainText::CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength)const
   976 void CPlainText::CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength)const
   924 	{
   977 	{
   925 	__TEST_INVARIANT;
   978 	__TEST_INVARIANT;
   926 	TInt documentLength = DocumentLength();
   979 	TInt documentLength = DocumentLength();
       
   980 	if (aPos < 0 || aPos > documentLength)
       
   981 	    {
       
   982 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_COPYTOSTREAML, "ECharPosBeyondDocument" );
       
   983 	    }
   927 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
   984 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
       
   985 	if (aLength < 0)
       
   986 	    {
       
   987 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_COPYTOSTREAML, "ECopyToStreamNegativeLength" );
       
   988 	    }
   928 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
   989 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
       
   990 	if (aPos + aLength > documentLength)
       
   991 	    {
       
   992 	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_COPYTOSTREAML, "ECharPosBeyondDocument" );
       
   993 	    }
   929 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
   994 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
   930 
   995 
   931 	aStream.WriteInt32L(aLength);
   996 	aStream.WriteInt32L(aLength);
   932 	::ExternalizeTextL(aStream,*iByteStore,aPos,aLength,FALSE);
   997 	::ExternalizeTextL(aStream,*iByteStore,aPos,aLength,FALSE);
   933 
   998 
   959 	}
  1024 	}
   960 
  1025 
   961 
  1026 
   962 TInt CPlainText::DoPasteFromStoreL(const CStreamStore& aStore,TStreamId aStreamId,TInt aPos)
  1027 TInt CPlainText::DoPasteFromStoreL(const CStreamStore& aStore,TStreamId aStreamId,TInt aPos)
   963 	{
  1028 	{
       
  1029 	if (aPos>DocumentLength())
       
  1030 	    {
       
  1031 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOPASTEFROMSTOREL, "ECharPosBeyondDocument" );
       
  1032 	    }
   964 	__ASSERT_ALWAYS(aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1033 	__ASSERT_ALWAYS(aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
   965 
  1034 
   966 	TInt charsPasted=0;
  1035 	TInt charsPasted=0;
   967 	if (aStreamId!=KNullStreamId)
  1036 	if (aStreamId!=KNullStreamId)
   968 		{// There is a recognised type in the clipboard.
  1037 		{// There is a recognised type in the clipboard.
  1005 	implied elsewhere, such as in the formatting information stored in CRichText objects.
  1074 	implied elsewhere, such as in the formatting information stored in CRichText objects.
  1006 	*/
  1075 	*/
  1007 	if (error != KErrNone)
  1076 	if (error != KErrNone)
  1008 		{
  1077 		{
  1009 		DoPtDelete(aPos,chars_read);
  1078 		DoPtDelete(aPos,chars_read);
       
  1079 		OstTrace1( TRACE_FATAL, DUP1_CPLAINTEXT_PASTEFROMSTREAML, "Leave code=%d", error );
  1010 		User::Leave(error);
  1080 		User::Leave(error);
  1011 		}
  1081 		}
  1012 
  1082 
  1013 	__TEST_INVARIANT;
  1083 	__TEST_INVARIANT;
  1014 	return chars_read;
  1084 	return chars_read;
  1056 
  1126 
  1057 void CPlainText::InsertEodL()
  1127 void CPlainText::InsertEodL()
  1058 /** Inserts the end-of-document character upon document construction.*/
  1128 /** Inserts the end-of-document character upon document construction.*/
  1059 	{
  1129 	{
  1060 // ASSERT: The plain text component is empty.
  1130 // ASSERT: The plain text component is empty.
       
  1131 	if (DocumentLength()!=-1)
       
  1132 	    {
       
  1133 	    OstTrace0( TRACE_DUMP, DUP1_CPLAINTEXT_INSERTEODL, "ECorruptTextStore" );
       
  1134 	    }
  1061 	__ASSERT_DEBUG(DocumentLength()==-1,Panic(ECorruptTextStore));
  1135 	__ASSERT_DEBUG(DocumentLength()==-1,Panic(ECorruptTextStore));
  1062 	TBuf<1> content;
  1136 	TBuf<1> content;
  1063 	content.Append(EParagraphDelimiter);
  1137 	content.Append(EParagraphDelimiter);
  1064 	TPtrC eod(content);
  1138 	TPtrC eod(content);
  1065 	DoPtInsertL(0,eod);
  1139 	DoPtInsertL(0,eod);
  1111 Must be valid, or a panic occurs.
  1185 Must be valid, or a panic occurs.
  1112 @param aChar The character to insert.
  1186 @param aChar The character to insert.
  1113 @param aBuf The descriptor to insert. */
  1187 @param aBuf The descriptor to insert. */
  1114 	{
  1188 	{
  1115 	__TEST_INVARIANT;
  1189 	__TEST_INVARIANT;
       
  1190 	if (aInsertPos<0 || aInsertPos>DocumentLength())
       
  1191 	    {
       
  1192 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_INSERTL, "ECharPosBeyondDocument" );
       
  1193 	    }
  1116 	__ASSERT_ALWAYS(aInsertPos>=0 && aInsertPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1194 	__ASSERT_ALWAYS(aInsertPos>=0 && aInsertPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1117 
  1195 
  1118 	TInt contentLength = 1;
  1196 	TInt contentLength = 1;
  1119 	if (aChar < 0x10000)
  1197 	if (aChar < 0x10000)
  1120 		{
  1198 		{
  1154 EXPORT_C void CPlainText::PtInsertL(TInt aPos,const TDesC& aBuf)
  1232 EXPORT_C void CPlainText::PtInsertL(TInt aPos,const TDesC& aBuf)
  1155 /** Inserts the contents a aBuf into the document at position aInsertPos.
  1233 /** Inserts the contents a aBuf into the document at position aInsertPos.
  1156 Maintain field set.*/
  1234 Maintain field set.*/
  1157 	{
  1235 	{
  1158 	__TEST_INVARIANT;
  1236 	__TEST_INVARIANT;
       
  1237 	if (aPos<0 || aPos>DocumentLength())
       
  1238 	    {
       
  1239 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_PTINSERTL, "ECharPosBeyondDocument" );
       
  1240 	    }
  1159 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1241 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1160 
  1242 
  1161 	DoPtInsertL(aPos,aBuf);
  1243 	DoPtInsertL(aPos,aBuf);
  1162 	if (FieldSetPresent())
  1244 	if (FieldSetPresent())
  1163 		iFieldSet->NotifyInsertion(aPos,aBuf.Length());
  1245 		iFieldSet->NotifyInsertion(aPos,aBuf.Length());
  1239  must be reformatted.
  1321  must be reformatted.
  1240  In global text, this clearly has no reasonable meaning, so always returns
  1322  In global text, this clearly has no reasonable meaning, so always returns
  1241  EFalse, so no reformatting occurs.*/
  1323  EFalse, so no reformatting occurs.*/
  1242 	{
  1324 	{
  1243 	TInt documentLength=DocumentLength()+1;
  1325 	TInt documentLength=DocumentLength()+1;
       
  1326 	if (aPos<0 || aPos>documentLength)
       
  1327 	    {
       
  1328 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOPTDELETE, "ECharPosBeyondDocument" );
       
  1329 	    }
  1244 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
  1330 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
       
  1331 	if (aLength<0)
       
  1332 	    {
       
  1333 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_DOPTDELETE, "EDeleteNegativeLength" );
       
  1334 	    }
  1245 	__ASSERT_ALWAYS(aLength>=0,Panic(EDeleteNegativeLength));
  1335 	__ASSERT_ALWAYS(aLength>=0,Panic(EDeleteNegativeLength));
       
  1336 	if (aPos+aLength>documentLength)
       
  1337 	    {
       
  1338 	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_DOPTDELETE, "ECharPosBeyondDocument" );
       
  1339 	    }
  1246 	__ASSERT_ALWAYS(aPos+aLength<=documentLength,Panic(ECharPosBeyondDocument));
  1340 	__ASSERT_ALWAYS(aPos+aLength<=documentLength,Panic(ECharPosBeyondDocument));
  1247 
  1341 
  1248 	iByteStore->Delete(aPos*sizeof(TText),aLength*sizeof(TText));
  1342 	iByteStore->Delete(aPos*sizeof(TText),aLength*sizeof(TText));
  1249 	UpdatePageTable(aPos,-aLength);
  1343 	UpdatePageTable(aPos,-aLength);
  1250 
  1344 
  1288 			input_stream.Close();
  1382 			input_stream.Close();
  1289 			}
  1383 			}
  1290 		file.Close();
  1384 		file.Close();
  1291 		file_session.Close();
  1385 		file_session.Close();
  1292 		}
  1386 		}
       
  1387 	if (error < 0)
       
  1388 	    {
       
  1389 	    OstTrace1( TRACE_FATAL, DUP1_CPLAINTEXT_IMPORTTEXTFILEL, "Leave code=%x", error );
       
  1390 	    }
  1293 	User::LeaveIfError(error);
  1391 	User::LeaveIfError(error);
  1294 	return chars_inserted;
  1392 	return chars_inserted;
  1295 	}
  1393 	}
  1296 
  1394 
  1297 
  1395 
  1312 If EOrganiseByParagraph, lines do not wrap and paragraph delimiters are 
  1410 If EOrganiseByParagraph, lines do not wrap and paragraph delimiters are 
  1313 converted into CR/LF pairs.
  1411 converted into CR/LF pairs.
  1314 @param aMaxLineLength The maximum number of characters in each line, (only 
  1412 @param aMaxLineLength The maximum number of characters in each line, (only 
  1315 relevant if the text organisation is EOrganiseByLine). */
  1413 relevant if the text organisation is EOrganiseByLine). */
  1316 	{
  1414 	{
       
  1415 	if (aTextOrganisation != EOrganiseByParagraph && aLineWrap <= 0)
       
  1416 	    {
       
  1417 	    OstTrace0( TRACE_DUMP, CPLAINTEXT_EXPORTASTEXTL, "EExportLineWrapInvalid" );
       
  1418 	    }
  1317 	__ASSERT_DEBUG(aTextOrganisation == EOrganiseByParagraph || aLineWrap > 0,Panic(EExportLineWrapInvalid));
  1419 	__ASSERT_DEBUG(aTextOrganisation == EOrganiseByParagraph || aLineWrap > 0,Panic(EExportLineWrapInvalid));
  1318 	RFs file_session;
  1420 	RFs file_session;
  1319 	TInt error = file_session.Connect();
  1421 	TInt error = file_session.Connect();
  1320 	if (error == KErrNone)
  1422 	if (error == KErrNone)
  1321 		{
  1423 		{
  1330 			output_stream.Close();
  1432 			output_stream.Close();
  1331 			}
  1433 			}
  1332 		file.Close();
  1434 		file.Close();
  1333 		file_session.Close();
  1435 		file_session.Close();
  1334 		}
  1436 		}
       
  1437 	if (error < 0)
       
  1438 	    {
       
  1439 	    OstTrace1( TRACE_FATAL, DUP2_CPLAINTEXT_EXPORTASTEXTL, "Leave code=%x", error );
       
  1440 	    }
  1335 	User::LeaveIfError(error);
  1441 	User::LeaveIfError(error);
  1336 	}
  1442 	}
  1337 
  1443 
  1338 
  1444 
  1339 
  1445 
  1483 @param aStartPos The document position at which to begin reading. Must be valid or a panic occurs.
  1589 @param aStartPos The document position at which to begin reading. Must be valid or a panic occurs.
  1484 @return Constant pointer to a section of the text object. 
  1590 @return Constant pointer to a section of the text object. 
  1485 */	
  1591 */	
  1486     {
  1592     {
  1487 	__TEST_INVARIANT;
  1593 	__TEST_INVARIANT;
       
  1594 	if (aStartPos<0 || aStartPos>DocumentLength())
       
  1595 	    {
       
  1596 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_READ, "ECharPosBeyondDocument" );
       
  1597 	    }
  1488 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1598 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1489 	
  1599 	
  1490 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
  1600 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
  1491 	return TPtrC((TText*)buf.Ptr(),buf.Length()/sizeof(TText));
  1601 	return TPtrC((TText*)buf.Ptr(),buf.Length()/sizeof(TText));
  1492 	}
  1602 	}
  1509 @param aLength The number of characters to read, inclusive of the character at position aStartPos. 
  1619 @param aLength The number of characters to read, inclusive of the character at position aStartPos. 
  1510 @return Constant pointer to a section of the text object.
  1620 @return Constant pointer to a section of the text object.
  1511 */
  1621 */
  1512 	{
  1622 	{
  1513 	__TEST_INVARIANT;
  1623 	__TEST_INVARIANT;
       
  1624 	if (aStartPos<0 || aStartPos>DocumentLength())
       
  1625 	    {
       
  1626 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_READ, "ECharPosBeyondDocument" );
       
  1627 	    }
  1514 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1628 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1515 	
  1629 	
  1516 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
  1630 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
  1517 	TInt length=Min(aLength,((TInt)buf.Length()/sizeof(TText)));
  1631 	TInt length=Min(aLength,((TInt)buf.Length()/sizeof(TText)));
  1518 	return TPtrC((TText*)buf.Ptr(),length);
  1632 	return TPtrC((TText*)buf.Ptr(),length);
  1532 @param aPos The document position from which to copy. Must be valid or a 
  1646 @param aPos The document position from which to copy. Must be valid or a 
  1533 panic occurs.*/
  1647 panic occurs.*/
  1534     {
  1648     {
  1535 	__TEST_INVARIANT;
  1649 	__TEST_INVARIANT;
  1536 	TInt documentLength=DocumentLength();
  1650 	TInt documentLength=DocumentLength();
       
  1651 	if (aPos<0 || aPos>documentLength)
       
  1652 	    {
       
  1653 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_EXTRACT, "ECharPosBeyondDocument" );
       
  1654 	    }
  1537 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
  1655 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
       
  1656 	if (aBuf.MaxLength()<documentLength - aPos)
       
  1657 	    {
       
  1658 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_EXTRACT, "EExtractBufferTooSmall" );
       
  1659 	    }
  1538 	__ASSERT_ALWAYS(aBuf.MaxLength()>=documentLength - aPos,Panic(EExtractBufferTooSmall));
  1660 	__ASSERT_ALWAYS(aBuf.MaxLength()>=documentLength - aPos,Panic(EExtractBufferTooSmall));
  1539 
  1661 
  1540 	DoExtract(aBuf,aPos,documentLength-aPos);
  1662 	DoExtract(aBuf,aPos,documentLength-aPos);
  1541 	}
  1663 	}
  1542 
  1664 
  1554 @param aPos The document position from which to copy. Must be valid or a panic 
  1676 @param aPos The document position from which to copy. Must be valid or a panic 
  1555 occurs. 
  1677 occurs. 
  1556 @param aLength The number of characters to copy. */
  1678 @param aLength The number of characters to copy. */
  1557 	{
  1679 	{
  1558 	__TEST_INVARIANT;
  1680 	__TEST_INVARIANT;
       
  1681 	if (aPos<0 || aPos>DocumentLength())
       
  1682 	    {
       
  1683 	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_EXTRACT, "ECharPosBeyondDocument" );
       
  1684 	    }
  1559 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1685 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
       
  1686 	if (aBuf.MaxLength()<aLength)
       
  1687 	    {
       
  1688 	    OstTrace0( TRACE_FATAL, DUP3_CPLAINTEXT_EXTRACT, "EExtractBufferTooSmall" );
       
  1689 	    }
  1560 	__ASSERT_ALWAYS(aBuf.MaxLength()>=aLength,Panic(EExtractBufferTooSmall));
  1690 	__ASSERT_ALWAYS(aBuf.MaxLength()>=aLength,Panic(EExtractBufferTooSmall));
  1561 
  1691 
  1562 	DoExtract(aBuf,aPos,aLength);
  1692 	DoExtract(aBuf,aPos,aLength);
  1563 	}
  1693 	}
  1564 
  1694 
  1565 // Extract text, optionally discarding some characters such as control characters and soft hyphens or
  1695 // Extract text, optionally discarding some characters such as control characters and soft hyphens or
  1566 // inline text, depending on the flag.
  1696 // inline text, depending on the flag.
  1567 EXPORT_C void CPlainText::ExtractSelectively(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags)
  1697 EXPORT_C void CPlainText::ExtractSelectively(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags)
  1568 	{
  1698 	{
       
  1699 	if (aPos < 0 || aPos > DocumentLength())
       
  1700 	    {
       
  1701 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_EXTRACTSELECTIVELY, "ECharPosBeyondDocument" );
       
  1702 	    }
  1569 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= DocumentLength(),Panic(ECharPosBeyondDocument));
  1703 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= DocumentLength(),Panic(ECharPosBeyondDocument));
  1570 	DoExtract(aBuf,aPos,aLength,aFlags);
  1704 	DoExtract(aBuf,aPos,aLength,aFlags);
  1571 	}
  1705 	}
  1572 
  1706 
  1573 
  1707 
  1654 // specified by the character position aPos.
  1788 // specified by the character position aPos.
  1655 // Called from i) Insert  ii) Delete  iii) Paste from clipboard  iv) Text file import.
  1789 // Called from i) Insert  ii) Delete  iii) Paste from clipboard  iv) Text file import.
  1656 //
  1790 //
  1657 	{
  1791 	{
  1658 	__TEST_INVARIANT;
  1792 	__TEST_INVARIANT;
       
  1793 	if (aPos<0 || aPos>DocumentLength()+1)
       
  1794 	    {
       
  1795 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_UPDATEPAGETABLE, "ECharPosBeyondDocument" );
       
  1796 	    }
  1659 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength()+1,Panic(ECharPosBeyondDocument));
  1797 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength()+1,Panic(ECharPosBeyondDocument));
  1660 	
  1798 	
  1661 	if (iPageTable)
  1799 	if (iPageTable)
  1662 		(*iPageTable)[PageContainingPos(aPos)]+=aLength;
  1800 		(*iPageTable)[PageContainingPos(aPos)]+=aLength;
  1663 	}
  1801 	}
  1670 
  1808 
  1671 @param aPos A document position. Must be valid or a panic occurs. 
  1809 @param aPos A document position. Must be valid or a panic occurs. 
  1672 @return The page number containing document position aPos. */
  1810 @return The page number containing document position aPos. */
  1673     {
  1811     {
  1674 	__TEST_INVARIANT;
  1812 	__TEST_INVARIANT;
       
  1813 	if (aPos<0 || aPos>DocumentLength())
       
  1814 	    {
       
  1815 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_PAGECONTAININGPOS, "ECharPosBeyondDocument" );
       
  1816 	    }
  1675 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1817 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1676 
  1818 
  1677     if (!iPageTable || (iPageTable->Count()<1))
  1819     if (!iPageTable || (iPageTable->Count()<1))
  1678         return 0;
  1820         return 0;
  1679     else
  1821     else
  1723 NULL, or a panic occurs. 
  1865 NULL, or a panic occurs. 
  1724 @param aFieldType Identifies the type of field to insert. For the built in 
  1866 @param aFieldType Identifies the type of field to insert. For the built in 
  1725 field types, see the UID values defined in flddef.h. */
  1867 field types, see the UID values defined in flddef.h. */
  1726 	{
  1868 	{
  1727 	__TEST_INVARIANT;
  1869 	__TEST_INVARIANT;
       
  1870 	if (aPos<0 || aPos>DocumentLength())
       
  1871 	    {
       
  1872 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_INSERTFIELDL, "ECharPosBeyondDocument" );
       
  1873 	    }
  1728 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1874 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
       
  1875 	if (!aField)
       
  1876 	    {
       
  1877 	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_INSERTFIELDL, "ENoTextField" );
       
  1878 	    }
  1729 	__ASSERT_ALWAYS(aField,Panic(ENoTextField));
  1879 	__ASSERT_ALWAYS(aField,Panic(ENoTextField));
  1730 
  1880 
  1731 	if (!FieldSetPresent())
  1881 	if (!FieldSetPresent())
  1732 		CreateFieldSetL(DocumentLength());
  1882 		CreateFieldSetL(DocumentLength());
  1733 	iFieldSet->InsertFieldL(aPos,aField,aFieldType);
  1883 	iFieldSet->InsertFieldL(aPos,aField,aFieldType);
  1750 
  1900 
  1751 @param aPos A document position in the field to be updated. Must be a valid 
  1901 @param aPos A document position in the field to be updated. Must be a valid 
  1752 position, or a panic occurs. */
  1902 position, or a panic occurs. */
  1753 	{
  1903 	{
  1754 	__TEST_INVARIANT;
  1904 	__TEST_INVARIANT;
       
  1905 	if (aPos<0 || aPos>DocumentLength())
       
  1906 	    {
       
  1907 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_UPDATEFIELDL, "ECharPosBeyondDocument" );
       
  1908 	    }
  1755 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1909 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1756 
  1910 
  1757 	if (!FieldSetPresent())
  1911 	if (!FieldSetPresent())
  1758 		return;
  1912 		return;
  1759 	TFindFieldInfo info;
  1913 	TFindFieldInfo info;
  1814 valid position or a panic occurs. 
  1968 valid position or a panic occurs. 
  1815 @return ETrue if a field was located at aPos. EFalse if no field was located 
  1969 @return ETrue if a field was located at aPos. EFalse if no field was located 
  1816 at aPos. */
  1970 at aPos. */
  1817 	{
  1971 	{
  1818 	__TEST_INVARIANT;
  1972 	__TEST_INVARIANT;
       
  1973 	if (aPos<0 || aPos>DocumentLength())
       
  1974 	    {
       
  1975 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_REMOVEFIELD, "ECharPosBeyondDocument" );
       
  1976 	    }
  1819 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1977 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1820 
  1978 
  1821 	TBool fieldRemoved=EFalse;
  1979 	TBool fieldRemoved=EFalse;
  1822 	
  1980 	
  1823 	if (FieldSetPresent())
  1981 	if (FieldSetPresent())
  1900 position or a panic occurs. 
  2058 position or a panic occurs. 
  1901 @return ETrue if there was a field located at aPos. EFalse if there was no 
  2059 @return ETrue if there was a field located at aPos. EFalse if there was no 
  1902 field located at aPos. */
  2060 field located at aPos. */
  1903 	{
  2061 	{
  1904 	__TEST_INVARIANT;
  2062 	__TEST_INVARIANT;
       
  2063 	if (aPos<0 || aPos>DocumentLength())
       
  2064 	    {
       
  2065 	    OstTrace0( TRACE_FATAL, CPLAINTEXT_CONVERTFIELDTOTEXT, "ECharPosBeyondDocument" );
       
  2066 	    }
  1905 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  2067 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
  1906 
  2068 
  1907 	TBool fieldConverted=EFalse;
  2069 	TBool fieldConverted=EFalse;
  1908 	
  2070 	
  1909 	if (FieldSetPresent())
  2071 	if (FieldSetPresent())