×
Namespaces

Variants
Actions

通过MEikEdwinObserver监控CEikEdwin

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
beover1984 在 13 Sep 2007 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CEikEdwin提供了SetEdwinObserver()和 AddEdwinObserverL()方法用来设置和添加标准编辑框CEikEdwin的观察器,通过派生并实现MEikEdwinObserver中的纯虚函数HandleEdwinEventL()就可以获得编辑框的一些标准事件,下面的代码展示了具体的实现方法:

// INCLUDES
#include <coecntrl.h>
#include <eikedwob.h> //for MEikEdwinObserver
 
// CLASS DECLARATION
 
/**
* CEdwinContainer control class.
*
*/
class CEdwinContainer: public CCoeControl, public MEikEdwinObserver
{
public:
...............
// Functions from MEikEdwinObserver
void HandleEdwinEventL(CEikEdwin* aEdwin,TEdwinEvent aEventType);
private:
CEikEdwin *iEdwin;
}
 
 
void CEdwinContainer::ConstructL(const TRect& aRect)
{
iEdwin = new (ELeave) CEikEdwin;
iEdwin->SetContainerWindowL(*this);
iEdwin->ConstructL( EAknEditorFlagDefault, 15, 15, 1 );
iEdwin->SetEdwinObserverL( this );
iEdwin->SetFocus( ETrue );
}
 
void CEdwinContainer::HandleEdwinEventL(CEikEdwin* aEdwin,TEdwinEvent aEventType)
{
switch( aEventType )
{
case EEventFormatChanged: //Unknown
break;
 
case EEventTextUpdate: //编辑框的内容发生变化
break;
 
case EEventNavigation: //光标位置发生改变
break;
}
}

另外,在有些SDK的文档上没有给出EEventTextUpdate枚举值,却说明EEventFormatChanged对应的事件是编辑框的内容发生变化,这使我在开发时浪费了不少时间,最后直接看它的头文件才恍然大悟.

This page was last modified on 15 December 2011, at 13:12.
61 page views in the last 30 days.
×