3,119
社区成员
发帖
与我相关
我的任务
分享
//----------------------------------------------------------------------------
// 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;
}