Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



How to handle changes to the text view

After a change has been made to the text layout, a reformat and redraw should normally take place, otherwise a panic will occur, as the text view needs to be kept up to date with changes to the text content. The following examples demonstrate which handling functions should be used to carry out the necessary reformatting.


Reformatting and redrawing after changes to the formatting of a block of text.

To reformat either from the start of the line or the start of the paragraph containing the cursor position and redraw the view, after changes to the formatting of a block of text, use the CTextView::HandleRangeFormatChangeL() function.

In the following example, the code retrieves the current selection and formats it.

// Apply italics to the selected region
TCursorSelection cursorSelection;
charFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic); 
charFormatMask.SetAttrib(EAttFontPosture); // Want to set posture

When formatting text, set the attribute's value in the TCharFormat object and set the corresponding bit in the format mask.

cursorSelection=iTextView->Selection(); // get limits of selection
TInt lowerPos=cursorSelection.LowerPos();
TInt length=cursorSelection.Length();
// Apply format to selected region
iRichText->ApplyCharFormatL(charFormat,charFormatMask,lowerPos,length);
// Ensure selection is cancelled after reformatting
TInt cursorPos=cursorSelection.iCursorPos; // Get new cursor position
// Set pending selection of length zero
TCursorSelection pendingSelection(cursorPos,cursorPos);
// Zero length selection, beginning and ending at new cursor position
iTextView->SetPendingSelection(pendingSelection);
        // Cancels selection after reformatting complete 
iTextView->HandleRangeFormatChangeL(cursorSelection); // reformat everything from here


Notes

[Top]


Reformatting and redrawing after inserting, deleting or replacing text

To Reformat and redraw the view after inserting, deleting or replacing a block of text, use the CTextView::HandleInsertDeleteL() function.

In the following example the code inserts several lines of text into the document, followed by a paragraph delimiter.

// Insert lots of text
iRichText->InsertL(iRichText->DocumentLength(),_L(
    "To be, or not to be, that is the question "
    ...
    ..."));
iRichText->InsertL(iRichText->DocumentLength(),
    CEditableText::EParagraphDelimiter); // end para
TCursorSelection cursorSelection(0,iRichText->DocumentLength());
iTextView->HandleInsertDeleteL(cursorSelection,0); // Handle insertion

[Top]


Reformatting and redrawing after a global change

To reformat and redraw the view after a global change has been made to the layout, use the CTextView::HandleGlobalChangeL() function.

In the following example, the code sets the formatted band to the part of the document displayed in the view rectangle.

TBuf<80> message;
iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
iTextView->HandleGlobalChangeL(); // Global document change 

[Top]


Reformatting the whole document or visible text

To reformat the whole document, or just the visible text if formatting is set to the band only, use the CTextView::FormatTextL() function.

In the following example, the code inserts several lines of text, with increased height to aid visibility, then sets the formatted band.

TCharFormat charFormat;
TCharFormatMask charFormatMask;
charFormatMask.SetAttrib(EAttFontHeight); // want to set height to 10 point (200 twips)
charFormat.iFontSpec.iHeight=200;    
iRichText->ApplyCharFormatL(charFormat,charFormatMask,0,1);
    // apply format from position 0, for 1 character
iTextView->FormatTextL();