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.

Revision as of 09:29, 10 June 2009 by mayankkedia (Talk | contribs)

Handle edwin events

From Wiki
Jump to: navigation, search

The following example shows how to handle edwin event primarily a text update. There are lot of times when we want to restrict what goes into the edwin such as only numbers, and nothing else.

Header file required:

#include <eikedwin.h>

Add following lines in .rssi file.

RESOURCE EDWIN r_your_edwin
maxlength = 511;
default_case = EAknEditorTextCase;
allowed_case_modes = EAknEditorAllCaseModes;
numeric_keymap = EAknEditorStandardNumberModeKeymap;
default_input_mode = EAknEditorTextInputMode;
allowed_input_modes = EAknEditorAllInputModes;

Add following lines in .h file.

class CYourContainer : public CCoeControl, public MEikEdwinObserver
void HandleEdwinEventL(CEikEdwin *aEdwin, TEdwinEvent aEventType);

Add following lines in .cpp file.

//In your container class
CEikEdwin* yourEdwin = new (ELeave)CEikEdwin;
yourEdwin->SetEdwinObserver(this); //to ensure you get callbacks when anything happens in the edwin
// Create a resource reader that we'll use to get the settings
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_YOUR_EDWIN);
CleanupStack::PopAndDestroy(); // reader
// Implement the HandleEdwinEventL in your container class
void CYourContainer::HandleEdwinEventL(CEikEdwin *aEdwin, TEdwinEvent aEventType)
if (aEventType == EEventTextUpdate)
TBuf<32> buf16;
TBool needReDraw = EFalse;
for (TInt i = buf16.Length()-1; i > -1; i--)
if (!TChar(buf16[i]).IsDigit())
buf16.Delete(i, 1);
needReDraw = ETrue;
if (needReDraw )
aEdwin->SetCursorPosL(buf16.Length(), EFalse);

In case of a CEikRichTextEditor, calling the SetTextL directly would result in a ETEXT 12 or a EIKCOCTL 70 panic, to avoid that modify the code a little bit in the HandleEdwinEventL above, in case of a text change needed(needReDraw is ETrue) like this.

CEikRichTextEditor* editor = static_cast< CEikRichTextEditor* >(aEdwin);
CRichText* richText = editor->RichText();
richText->InsertL(0, buf16); // insert starting from 0 pos
//aEdwin->SetTextL(&buf16); // This causes the EText12 or EIKCOCTL 70 panics
aEdwin->SetCursorPosL(buf16.Length(), EFalse);

Now when the HandleEdwinEvent function gets called the aEdwin would point to yourEdwin created earlier, and if there is a text inputted by the user, it would check if whats entered is not digit, it would keep removing them. Thereby ensuring that you have only digits in the edwin.

Added by - Mayank on 12/05/2009

30 page views in the last 30 days.