如何实现UCWEB类似的CEikEdwin?

ss1969 2007-10-30 02:13:19
如何实现这样的一个输入框CEikEdwin:

按一下OK聚焦,输入完成之后再按一下OK取消焦点。就是和UCWEB的那个一样。

我自己这样判断(代码在后),会出现问题:选字的OK事件也要调用OfferKeyEventL,导致失去焦点。
求解~~~



//----------------------------------------------------------------------------
// CCEikEdwinTestContainer (The View of the MVC)
//----------------------------------------------------------------------------

// Second-phase construction function.
// Initializes the container (creates a window, sets its bounds and activates
// it) and creates the child/nested controls (if any).
// Called from the AppUi after creating a new container object.
void CCEikEdwinTestContainer::ConstructL(const TRect& aRect) {
CreateWindowL();
#if 1
iEdwin = new (ELeave) CEikEdwin(TGulBorder::ESingleGray);
iEdwin->SetContainerWindowL(*this);
// iEdwin->ConstructL(CEikEdwin::EAllowUndo, 12, 10, 1);
iEdwin->ConstructL(EAknEditorFlagDefault,16,16,1);
// iEdwin->SetAknEditorFlags(EAknEditorFlagLatinInputModesOnly); //设定输入限制

iEdwin->SetExtent(TPoint(0, 20), iEdwin->MinimumSize());// iEdwin->MinimumSize());
iEdwin->EnableCcpuSupportL(ETrue);
// iEdwin->SupportsUndo();
iEdwin->SetFocus(ETrue);
#endif
// CCEikEdwinTestAppUi* appui = static_cast<CCEikEdwinTestAppUi*>(iEikonEnv->AppUi());
// appui->AddToStackL(iEdwin);

SetRect(aRect);
ActivateL();
}

// Destructor used for releasing the resources used by his container.
// Called from the AppUi's destructor.
CCEikEdwinTestContainer::~CCEikEdwinTestContainer() {
delete iEdwin;
}

// Lays out the child controls (if any).
// Called when the control is resized.
void CCEikEdwinTestContainer::SizeChanged() {
// TODO: Add here control resize code etc.
// iEdwin->SetExtent( TPoint(0,20), iEdwin->MinimumSize() );
}

// Returns the number of child controls, 0 if none.
TInt CCEikEdwinTestContainer::CountComponentControls() const {
return 1; // return nbr of controls inside this container
}

// Returns the child control at the given index, NULL if none.
CCoeControl* CCEikEdwinTestContainer::ComponentControl(TInt aIndex) const {
switch ( aIndex )
{
case 0:
return iEdwin;
default:
return NULL;
}
}

// Draws to this controls canvas using graphics primitives.
// Note that the UI framework takes care of drawing the child controls.
void CCEikEdwinTestContainer::Draw(const TRect& aRect) const {
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}

// Handles events generated by the child controls.
void CCEikEdwinTestContainer::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) {
// TODO: Add your control event handler code here
}

TKeyResponse CCEikEdwinTestContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
//我想实现就是:按一下OK聚焦,输入完成之后再按一下OK取消焦点。
//问题出在只要选字的时候按了OK,也会取消焦点。。

TKeyResponse keyConsumed = EKeyWasNotConsumed;

if(iEdwin->IsFocused()){
keyConsumed = iEdwin->OfferKeyEventL(aKeyEvent, aType);
if(aType==EEventKeyDown && keyConsumed==EKeyWasNotConsumed && aKeyEvent.iScanCode==EStdKeyDevice3){
iEdwin->SetFocus(EFalse);
}
}
else if(aType==EEventKeyDown && aKeyEvent.iScanCode==EStdKeyDevice3){
iEdwin->SetFocus(ETrue);
}

return keyConsumed;
}
...全文
158 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ss1969 2007-11-14
  • 打赏
  • 举报
回复
To 3楼,不行,我试验了各种添加的位置,都不行


请。。高手解答。。。
Juncof 2007-11-07
  • 打赏
  • 举报
回复
if((EEventKey == aType) && (EKeyDevice3 == aKeyEvent.iCode))
{
iEdwin->SetFocus(iEdwin->IsFocused());
}
ss1969 2007-10-31
  • 打赏
  • 举报
回复
回楼上,我就是不知道怎么做才是对的
能帮忙改下不?
anel 2007-10-30
  • 打赏
  • 举报
回复
keyConsumed==EKeyWasNotConsumed 这句没什么用吧?

3,119

社区成员

发帖
与我相关
我的任务
社区描述
塞班系统(Symbian系统)是塞班公司为手机而设计的操作系统,它的前身是英国宝意昂公司的 EP ( Electronic Piece of cheese)操作系统。
社区管理员
  • Symbian社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧