You Are Here:

Community: Wiki

This page was last modified on 18 September 2009, at 13:46.

Handle edwin events

From Forum Nokia Wiki

Reviewer Approved   


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;
special_character_table = R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG;
}

Add following lines in .h file.

class CYourContainer : public CCoeControl, public MEikEdwinObserver
{
public:
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);
yourEdwin->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader
 
// Implement the HandleEdwinEventL in your container class
void CYourContainer::HandleEdwinEventL(CEikEdwin *aEdwin, TEdwinEvent aEventType)
{
if (aEventType == EEventTextUpdate)
{
TBuf<32> buf16;
aEdwin->GetText(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->SetTextL(&buf16);
aEdwin->HandleTextChangedL();
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->Reset();
richText->InsertL(0, buf16); // insert starting from 0 pos
//aEdwin->SetTextL(&buf16); // This causes the EText12 or EIKCOCTL 70 panics
aEdwin->HandleTextChangedL();
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fPortingE5fBlackBerryE5fapplicationsE5fandE5fservicesE5ftoE5fS60E5fplatformX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ