textrendering/texthandling/stext/TXTETEXT.CPP
changeset 44 601ab138ba0b
parent 37 6be019398652
child 49 4d76f1414957
--- a/textrendering/texthandling/stext/TXTETEXT.CPP	Fri Jun 11 15:33:54 2010 +0300
+++ b/textrendering/texthandling/stext/TXTETEXT.CPP	Tue Jul 06 16:23:19 2010 +0300
@@ -41,6 +41,11 @@
 #include "TXTRTPFL.H"
 #include "TXTCLIPBOARD.H"
 
+#include "OstTraceDefinitions.h"
+#ifdef OST_TRACE_COMPILER_IN_USE
+#include "TXTETEXTTraces.h"
+#endif
+
 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
 #include "TXTETEXT_INTERNAL.H"
 #endif
@@ -258,7 +263,15 @@
 EXPORT_C void CEditableText::StartFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aInitialInlineText,TInt aPositionOfInlineTextInDocument,TInt aNumberOfCharactersToHide,MFepInlineTextFormatRetriever& aInlineTextFormatRetriever)
 /** @internalAll */	
 	{
+	if (aPositionOfInlineTextInDocument<0 || aNumberOfCharactersToHide<0 || aPositionOfInlineTextInDocument+aNumberOfCharactersToHide>DocumentLength())
+	    {
+	    OstTrace0( TRACE_DUMP, CEDITABLETEXT_STARTFEPINLINEEDITL, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPositionOfInlineTextInDocument>=0 && aNumberOfCharactersToHide>=0 && aPositionOfInlineTextInDocument+aNumberOfCharactersToHide<=DocumentLength(),Panic(ECharPosBeyondDocument));
+	if (InlineEditData()!=NULL)
+	    {
+	    OstTrace0( TRACE_DUMP, DUP1_CEDITABLETEXT_STARTFEPINLINEEDITL, "EAlreadyFepInlineEditing" );
+	    }
 	__ASSERT_ALWAYS(InlineEditData()==NULL,Panic(EAlreadyFepInlineEditing));
 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
 	aNumberOfCharactersSuccessfullyDeleted=0;
@@ -295,12 +308,20 @@
 /** @internalAll */	
     {
 	CInlineEditData* const inlineEditData=InlineEditData();
+	if (inlineEditData==NULL)
+	    {
+	    OstTrace0( TRACE_DUMP, CEDITABLETEXT_UPDATEFEPINLINETEXTL, "ENotCurrentlyFepInlineEditing" );
+	    }
 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
 	aNumberOfCharactersSuccessfullyDeleted=0;
 	aNumberOfCharactersSuccessfullyInserted=0;
 	HBufC*& inlineText=inlineEditData->iInlineText;
 	HBufC* oldInlineText=inlineText;
+	if (oldInlineText!=NULL && inlineEditData->iLengthOfInlineText!=oldInlineText->Length())
+	    {
+	    OstTrace0( TRACE_DUMP, DUP1_CEDITABLETEXT_UPDATEFEPINLINETEXTL, "EDebug" );
+	    }
 	__ASSERT_DEBUG(oldInlineText==NULL || inlineEditData->iLengthOfInlineText==oldInlineText->Length(),Panic(EDebug));
 	const TInt lengthOfNewInlineText=aNewInlineText.Length();
 	if (oldInlineText!=NULL && *oldInlineText==aNewInlineText)
@@ -346,7 +367,15 @@
  */	
     {
 	const CInlineEditData* const inlineEditData=InlineEditData();
+	if (inlineEditData==NULL)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP1_CEDITABLETEXT_COMMITFEPINLINEEDITL, "ENotCurrentlyFepInlineEditing" );
+	    }
 	__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
+	if (inlineEditData->iInlineText!=NULL && inlineEditData->iLengthOfInlineText!=inlineEditData->iInlineText->Length())
+	    {
+	    OstTrace0( TRACE_DUMP, CEDITABLETEXT_COMMITFEPINLINEEDITL, "EDebug" );
+	    }
 	__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || inlineEditData->iLengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
 	aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
 	const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
@@ -370,6 +399,10 @@
 		{
 		const TInt positionOfInlineTextInDocument=inlineEditData->iPositionOfInlineTextInDocument;
 		const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
+		if (inlineEditData->iInlineText!=NULL && lengthOfInlineText!=inlineEditData->iInlineText->Length())
+		    {
+		    OstTrace0( TRACE_DUMP, CEDITABLETEXT_CANCELFEPINLINEEDIT, "EDebug" );
+		    }
 		__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || lengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
 		TRAPD(notUsed,
 						if (lengthOfInlineText>0)
@@ -381,6 +414,10 @@
 						const HBufC* const hiddenText=inlineEditData->iHiddenText;
 						if (hiddenText!=NULL)
 							{
+							if (hiddenText->Length()<=0)
+							    {
+							    OstTrace0( TRACE_DUMP, DUP1_CEDITABLETEXT_CANCELFEPINLINEEDIT, "EDebug" );
+							    }
 							__ASSERT_DEBUG(hiddenText->Length()>0, Panic(EDebug));
 							InsertL(positionOfInlineTextInDocument,*hiddenText);
 							aNumberOfCharactersSuccessfullyInserted=hiddenText->Length();
@@ -562,6 +599,10 @@
 /** Allocates storage of CBufFlat or CBufSeg, according to the parameter aStorage.
 Creates & initializes the field set.*/
 	{
+	if (iByteStore!=NULL)
+	    {
+	    OstTrace0( TRACE_DUMP, CPLAINTEXT_DOCONSTRUCTL, "EConstructCalledTwice" );
+	    }
 	__ASSERT_DEBUG(iByteStore==NULL,Panic(EConstructCalledTwice));
 	
 	iByteStore=(aStorage==ESegmentedStorage)
@@ -884,8 +925,20 @@
 	{
 	__TEST_INVARIANT;
 	TInt documentLength = DocumentLength();
+	if (aPos < 0 || aPos > documentLength)
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOCOPYTOSTOREL, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
+	if (aLength < 0)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_DOCOPYTOSTOREL, "ECopyToStreamNegativeLength" );
+	    }
 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
+	if (aPos + aLength > documentLength)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_DOCOPYTOSTOREL, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
 
 	if (aLength == 0)
@@ -924,8 +977,20 @@
 	{
 	__TEST_INVARIANT;
 	TInt documentLength = DocumentLength();
+	if (aPos < 0 || aPos > documentLength)
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_COPYTOSTREAML, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
+	if (aLength < 0)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_COPYTOSTREAML, "ECopyToStreamNegativeLength" );
+	    }
 	__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
+	if (aPos + aLength > documentLength)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_COPYTOSTREAML, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
 
 	aStream.WriteInt32L(aLength);
@@ -961,6 +1026,10 @@
 
 TInt CPlainText::DoPasteFromStoreL(const CStreamStore& aStore,TStreamId aStreamId,TInt aPos)
 	{
+	if (aPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOPASTEFROMSTOREL, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 
 	TInt charsPasted=0;
@@ -1007,6 +1076,7 @@
 	if (error != KErrNone)
 		{
 		DoPtDelete(aPos,chars_read);
+		OstTrace1( TRACE_FATAL, DUP1_CPLAINTEXT_PASTEFROMSTREAML, "Leave code=%d", error );
 		User::Leave(error);
 		}
 
@@ -1058,6 +1128,10 @@
 /** Inserts the end-of-document character upon document construction.*/
 	{
 // ASSERT: The plain text component is empty.
+	if (DocumentLength()!=-1)
+	    {
+	    OstTrace0( TRACE_DUMP, DUP1_CPLAINTEXT_INSERTEODL, "ECorruptTextStore" );
+	    }
 	__ASSERT_DEBUG(DocumentLength()==-1,Panic(ECorruptTextStore));
 	TBuf<1> content;
 	content.Append(EParagraphDelimiter);
@@ -1113,6 +1187,10 @@
 @param aBuf The descriptor to insert. */
 	{
 	__TEST_INVARIANT;
+	if (aInsertPos<0 || aInsertPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_INSERTL, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aInsertPos>=0 && aInsertPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 
 	TInt contentLength = 1;
@@ -1156,6 +1234,10 @@
 Maintain field set.*/
 	{
 	__TEST_INVARIANT;
+	if (aPos<0 || aPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_PTINSERTL, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 
 	DoPtInsertL(aPos,aBuf);
@@ -1241,8 +1323,20 @@
  EFalse, so no reformatting occurs.*/
 	{
 	TInt documentLength=DocumentLength()+1;
+	if (aPos<0 || aPos>documentLength)
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_DOPTDELETE, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
+	if (aLength<0)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_DOPTDELETE, "EDeleteNegativeLength" );
+	    }
 	__ASSERT_ALWAYS(aLength>=0,Panic(EDeleteNegativeLength));
+	if (aPos+aLength>documentLength)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_DOPTDELETE, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos+aLength<=documentLength,Panic(ECharPosBeyondDocument));
 
 	iByteStore->Delete(aPos*sizeof(TText),aLength*sizeof(TText));
@@ -1290,6 +1384,10 @@
 		file.Close();
 		file_session.Close();
 		}
+	if (error < 0)
+	    {
+	    OstTrace1( TRACE_FATAL, DUP1_CPLAINTEXT_IMPORTTEXTFILEL, "Leave code=%x", error );
+	    }
 	User::LeaveIfError(error);
 	return chars_inserted;
 	}
@@ -1314,6 +1412,10 @@
 @param aMaxLineLength The maximum number of characters in each line, (only 
 relevant if the text organisation is EOrganiseByLine). */
 	{
+	if (aTextOrganisation != EOrganiseByParagraph && aLineWrap <= 0)
+	    {
+	    OstTrace0( TRACE_DUMP, CPLAINTEXT_EXPORTASTEXTL, "EExportLineWrapInvalid" );
+	    }
 	__ASSERT_DEBUG(aTextOrganisation == EOrganiseByParagraph || aLineWrap > 0,Panic(EExportLineWrapInvalid));
 	RFs file_session;
 	TInt error = file_session.Connect();
@@ -1332,6 +1434,10 @@
 		file.Close();
 		file_session.Close();
 		}
+	if (error < 0)
+	    {
+	    OstTrace1( TRACE_FATAL, DUP2_CPLAINTEXT_EXPORTASTEXTL, "Leave code=%x", error );
+	    }
 	User::LeaveIfError(error);
 	}
 
@@ -1485,6 +1591,10 @@
 */	
     {
 	__TEST_INVARIANT;
+	if (aStartPos<0 || aStartPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_READ, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 	
 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
@@ -1511,6 +1621,10 @@
 */
 	{
 	__TEST_INVARIANT;
+	if (aStartPos<0 || aStartPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_READ, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 	
 	TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
@@ -1534,7 +1648,15 @@
     {
 	__TEST_INVARIANT;
 	TInt documentLength=DocumentLength();
+	if (aPos<0 || aPos>documentLength)
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_EXTRACT, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
+	if (aBuf.MaxLength()<documentLength - aPos)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_EXTRACT, "EExtractBufferTooSmall" );
+	    }
 	__ASSERT_ALWAYS(aBuf.MaxLength()>=documentLength - aPos,Panic(EExtractBufferTooSmall));
 
 	DoExtract(aBuf,aPos,documentLength-aPos);
@@ -1556,7 +1678,15 @@
 @param aLength The number of characters to copy. */
 	{
 	__TEST_INVARIANT;
+	if (aPos<0 || aPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, DUP2_CPLAINTEXT_EXTRACT, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
+	if (aBuf.MaxLength()<aLength)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP3_CPLAINTEXT_EXTRACT, "EExtractBufferTooSmall" );
+	    }
 	__ASSERT_ALWAYS(aBuf.MaxLength()>=aLength,Panic(EExtractBufferTooSmall));
 
 	DoExtract(aBuf,aPos,aLength);
@@ -1566,6 +1696,10 @@
 // inline text, depending on the flag.
 EXPORT_C void CPlainText::ExtractSelectively(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags)
 	{
+	if (aPos < 0 || aPos > DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_EXTRACTSELECTIVELY, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos >= 0 && aPos <= DocumentLength(),Panic(ECharPosBeyondDocument));
 	DoExtract(aBuf,aPos,aLength,aFlags);
 	}
@@ -1656,6 +1790,10 @@
 //
 	{
 	__TEST_INVARIANT;
+	if (aPos<0 || aPos>DocumentLength()+1)
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_UPDATEPAGETABLE, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength()+1,Panic(ECharPosBeyondDocument));
 	
 	if (iPageTable)
@@ -1672,6 +1810,10 @@
 @return The page number containing document position aPos. */
     {
 	__TEST_INVARIANT;
+	if (aPos<0 || aPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_PAGECONTAININGPOS, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 
     if (!iPageTable || (iPageTable->Count()<1))
@@ -1725,7 +1867,15 @@
 field types, see the UID values defined in flddef.h. */
 	{
 	__TEST_INVARIANT;
+	if (aPos<0 || aPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_INSERTFIELDL, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
+	if (!aField)
+	    {
+	    OstTrace0( TRACE_FATAL, DUP1_CPLAINTEXT_INSERTFIELDL, "ENoTextField" );
+	    }
 	__ASSERT_ALWAYS(aField,Panic(ENoTextField));
 
 	if (!FieldSetPresent())
@@ -1752,6 +1902,10 @@
 position, or a panic occurs. */
 	{
 	__TEST_INVARIANT;
+	if (aPos<0 || aPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_UPDATEFIELDL, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 
 	if (!FieldSetPresent())
@@ -1816,6 +1970,10 @@
 at aPos. */
 	{
 	__TEST_INVARIANT;
+	if (aPos<0 || aPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_REMOVEFIELD, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 
 	TBool fieldRemoved=EFalse;
@@ -1902,6 +2060,10 @@
 field located at aPos. */
 	{
 	__TEST_INVARIANT;
+	if (aPos<0 || aPos>DocumentLength())
+	    {
+	    OstTrace0( TRACE_FATAL, CPLAINTEXT_CONVERTFIELDTOTEXT, "ECharPosBeyondDocument" );
+	    }
 	__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
 
 	TBool fieldConverted=EFalse;