Archived:Applying background color for paragraphs in a CEikRichTextEditor

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition FP1
Created: User:Technical writer 2 (29 Dec 2006)
Last edited: hamishwillee (14 Jun 2012)


Applying background color for paragraphs in a CEikRichTextEditor


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
    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
    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

This page was last modified on 14 June 2012, at 06:23.
35 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.