Archived:Applying background color for paragraphs in a CEikRichTextEditor
Article Metadata
Compatibility
Article
Overview
Applying background color for paragraphs in a CEikRichTextEditor
Description
When using a rich text editor (CEikRichTextEditor) with multiple paragraphs, it is possible to distinguish between paragraphs or to highlight one by applying a unique background color.
The following simple code snippet explains how to create a rich text editor and how to apply unique background colors for each paragraph.
iEditor = new ( ELeave ) CEikRichTextEditor;
iEditor->SetContainerWindowL( *this );
iEditor->ConstructL( this, 0, 0, 0 );
iEditor->SetRect( iEditorRect );
CRichText* richtext = iEditor->RichText();
CParaFormat* pf = new ( ELeave ) CParaFormat;
CleanupStack::PushL( pf );
pf->iFillColor = KRgbRed;
TParaFormatMask mask;
mask.SetAttrib( EAttFillColor );
_LIT( KText, "abcd" );
richtext->InsertL( 0, KText );
TInt paraLen; // Length of paragraph
TInt fiChPos; // First character position of paragraph
// Get the length of the first paragraph
fiChPos = richtext->CharPosOfParagraph( paraLen, 0 );
richtext->ApplyParaFormatL( pf, mask, fiChPos, paraLen );
CleanupStack::Pop(); // pf
// Applying different background color for the next paragraph
richtext->AppendParagraphL();
CParaFormat* pf1 = new ( ELeave ) CParaFormat;
CleanupStack::PushL( pf1 );
pf1->iFillColor = KRgbBlue;
TParaFormatMask mask1;
mask1.SetAttrib( EAttFillColor );
// Insert text in the second paragraph after the first one
// paraLen has the value of the length of the first paragraph
_LIT(KText1,"efgh");
richtext->InsertL ( paraLen, KText1 );
// Get the length of the second paragraph
fiChPos=richtext->CharPosOfParagraph( paraLen, 1 );
richtext->ApplyParaFormatL( pf1, mask1, fiChPos, paraLen );
CleanupStack::Pop(); // pf1
iEditor->ActivateL();

