Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Navigate CEikRichTextEditor up and down with stylus

From Wiki
Jump to: navigation, search

This code example shows how to create a CEikRichTextEditor that can be navigated up and down with stylus (finger). It extends the 2008 code snippet CS000823 - Adding scrollbars to a rich text editor.

Article Metadata
Code ExampleTested with
Devices(s): N97 Mini, N97, N8
Platform Security
Capabilities: none
Keywords: CEikRichTextEditor, CEikScrollBarFrame
Created: nvaidy01 (16 Dec 2011)
Last edited: hamishwillee (19 Dec 2011)



This article explains how to navigate CEikRichTextEditor up and down with stylus(finger) and also to update the scroll bar position accordingly. Apart from this, the article also describes how to hide the scroll bar automatically if text is shorter than editor size.

Header File

class CRTEContainer : public CCoeControl
CEikRichTextEditor* iRtEd; // Rich Text Editor
* From CoeControl,SizeChanged,HandlePointerEventL.

void HandlePointerEventL(const TPointerEvent &aPointerEvent);

Source File

The below mentioned code describes construction of CEikRichTextEditor object, provides the touch effect to editor i.e. navigating editor up and down through stylus (finger) and also to hide the scroll bar automatically if text is shorter than editor size.

// Second phase construction.
void CRTEContainer::ConstructL(const TRect& aRect)
iRtEd->ConstructL(this, 15, 10000, CEikEdwin::EReadOnly|CEikEdwin::EAvkonEditor); /* 15 is the number of lines visible in the editor. 1000 is the maximum number of characters that can be entered into the editor.*/
iRtEd->CreateScrollBarFrameL()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iRtEd->TextLayout()->ReformatVerticalSpaceL(); //To remove vertical spaces
iRtEd->TextLayout()->RestrictScrollToTopsOfLines( EFalse );
if (iRtEd)
delete iRtEd;
void CRTEContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent)
static TInt firstpoint;
if(aPointerEvent.iType == TPointerEvent::EButton1Down)
firstpoint = aPointerEvent.iPosition.iY;
if(aPointerEvent.iType == TPointerEvent::EDrag)
if(aPointerEvent.iPosition.iY > firstpoint)
iRtEd->MoveDisplayL(TCursorPosition::EFLineUp); //Scrolls the text either horizontally or vertically without affecting the cursor’s position
iRtEd->MoveDisplayL(TCursorPosition::EFLineDown); //Scrolls the text either horizontally or vertically without affecting the cursor’s position
// ---------------------------------------------------------
// CRTEContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
void CRTEContainer::SizeChanged()
TRect rect = Rect();
TInt StatusLineHeight = iStatusLine->Font()->HeightInPixels() + 6;
iStatusLine->SetExtent(TPoint(0, 0), TSize(rect.Width(), StatusLineHeight));
TRect ScrollBarRect;
CEikScrollBar* scrlBar =iRtEd->ScrollBarFrame() ? iRtEd->ScrollBarFrame()->VerticalScrollBar(): NULL;
if (scrlBar)
ScrollBarRect = iRtEd->ScrollBarFrame()->VerticalScrollBar()->Rect();
//In 3rd edition CEikRichTextEditor draw the view for the whole rect and
//the scrollbar doesn't show. That is a reason why CEikRichTextEditor Width() is
iRtEd->SetExtent(TPoint(0, StatusLineHeight), TSize(rect.Width() - ScrollBarRect.Width(), rect.Height() - StatusLineHeight));

Supplementary material

Executables and source files are available in

This page was last modified on 19 December 2011, at 21:59.
21 page views in the last 30 days.