Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Revision as of 21:59, 19 December 2011 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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
Article
Keywords: CEikRichTextEditor, CEikScrollBarFrame
Created: nvaidy01 (16 Dec 2011)
Last edited: hamishwillee (19 Dec 2011)

Contents

Introduction

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
{
 
private:
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)
{
CreateWindowL();
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->SetContainerWindowL(*this);
iRtEd->CreateScrollBarFrameL()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iRtEd->SetFocus(ETrue);
iRtEd->TextLayout()->ReformatVerticalSpaceL(); //To remove vertical spaces
iRtEd->TextLayout()->RestrictScrollToTopsOfLines( EFalse );
SetRect(aRect);
ActivateL();
}
 
CRTEContainer::~CRTEContainer()
{
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->TextView()->ScrollDisplayL(TCursorPosition::EFLineUp);
iRtEd->MoveDisplayL(TCursorPosition::EFLineUp); //Scrolls the text either horizontally or vertically without affecting the cursor’s position
 
DrawNow();
iRtEd->DrawNow();
 
}
else
{
iRtEd->TextView()->ScrollDisplayL(TCursorPosition::EFLineDown);
iRtEd->MoveDisplayL(TCursorPosition::EFLineDown); //Scrolls the text either horizontally or vertically without affecting the cursor’s position
 
DrawNow();
iRtEd->DrawNow();
 
}
}
}
 
 
// ---------------------------------------------------------
// 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
//rect.Width()-ScrollBarRect.Width()
iRtEd->SetExtent(TPoint(0, StatusLineHeight), TSize(rect.Width() - ScrollBarRect.Width(), rect.Height() - StatusLineHeight));
 
}

Supplementary material

Executables and source files are available in File:RichTextEditor.zip.

This page was last modified on 19 December 2011, at 21:59.
43 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.

×