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.
Retrieving the content of RichTextEditor at the tapped position on 5th Edition devices
S60 5th Edition
This article explains how to retrieve the content of RichTextEditor at the tapped position.
As S60 5th Edition devices are touch sensitive, the pointer events can be captured using HandlePointerEventL(). This is also used to handle such events as pointer down/up and dragging. Thus a class derived from CCoeControl can implement the HandlePointerEventL() function for customising the handling of pointer events.
In order to get the contents of the Editor, first we need to get the co-ordinates of the tapped event and then identify the document position of the nearest character edge to the window coordinates specified. This helps in retrieving the content (entire word) nearest to the tapped position.
#include <FRMTVIEW.H> #include <TXTRICH.H>
The following code snippet enables the retrieving of the contents of the editor at the tapped position. This has to be used in HandlePointerEentL().
TPoint tapPoint( aPointerEvent.iPosition );
//iEditor is a CEikRichTextEditor object
CTextView* iTextView = iEditor->TextView();
//Get the current document position based on the point where the stylus is tapped.
TInt docPos(iTextView->XyPosToDocPosL( tapPoint ) );
TInt start( 0 );
TInt length( 0 );
//By passing the current position of the document you can get the word information
//(the start position and the length)
iEditor->RichText()->GetWordInfo(docPos,start,length, EFalse, EFalse);
if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
// Based on the start position and the length get the word information.
// using the method Mid(TInt aPos, TInt aLength) const;
// the word at the tapped position can also be modifed
The above code snippet can also be used for highlighted items like URLs, phone numbers, and HTTP addresses. The Item Finder API can be used for highlighting URLs, phone numbers, and HTTP addresses.
In order to identify whether the stylus is tapped on the tag or not, the method CursorOverTag() can be used. The method returns a boolean value besides giving the start position and the length of the tag.
TBool iFlag = iEditor->RichText()->CursorOverTag( docPos, parser, start, length );
For information on the Item Finder API, see the following link: Item Finder API