Symbian界面编程中关于Edit焦点切换的问题

来源:互联网 发布:教皇的权力 知乎 编辑:程序博客网 时间:2024/05/16 02:18

注意几点:

1. 需要自己绘制

2. 

 

void CNugrujxtContainer::ConstructL(const TRect& aRect)

    {

    CreateWindowL();

 

    iEdwin = new (ELeave) CEikEdwin();

    iEdwin->SetContainerWindowL( *this );

    iEdwin->ConstructL();

    iEdwin->SetFocus(ETrue);

    iEdwin->SetMaxLength(20);

 

 

    iEdwin2 = new (ELeave) CEikEdwin();

    iEdwin2->SetContainerWindowL( *this );

    iEdwin2->ConstructL();

//    iEdwin2->SetFocus(ETrue);

    iEdwin2->SetMaxLength(20);

 

    SetRect(aRect);

    ActivateL();

    }

 

// Destructor

CNugrujxtContainer::~CNugrujxtContainer()

    {

    delete iEdwin;

    delete iEdwin2;

    }

 

// ---------------------------------------------------------

// CNugrujxtContainer::SizeChanged()

// Called by framework when the view size is changed

// ---------------------------------------------------------

//

void CNugrujxtContainer::SizeChanged()

    {

    // TODO: Add here control resize code etc.

    iEdwin->SetExtent(TPoint(2,2), TSize(100, 20));

    iEdwin2->SetExtent(TPoint(2,25), TSize(100, 20));

    }

 

// ---------------------------------------------------------

// CNugrujxtContainer::CountComponentControls() const

// ---------------------------------------------------------

//

TInt CNugrujxtContainer::CountComponentControls() const

    {

    return 2; // return nbr of controls inside this container

    }

 

// ---------------------------------------------------------

// CNugrujxtContainer::ComponentControl(TInt aIndex) const

// ---------------------------------------------------------

//

CCoeControl* CNugrujxtContainer::ComponentControl(TInt aIndex) const

    {

    switch ( aIndex )

        {

        case 0:

            return iEdwin;

        case 1:

            return iEdwin2;

        default:

            return NULL;

        }

    }

 

// ---------------------------------------------------------

// CNugrujxtContainer::Draw(const TRect& aRect) const

// ---------------------------------------------------------

//

void CNugrujxtContainer::Draw(const TRect& aRect) const

    {

    CWindowGc& gc = SystemGc();

 

    gc.SetPenStyle( CGraphicsContext::ENullPen );

    gc.SetBrushColor( KRgbWhite );

    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );

    gc.DrawRect( aRect );

 

    gc.SetPenStyle( CGraphicsContext::ESolidPen);

    gc.SetPenColor(KRgbBlack);

//    gc.SetBrushStyle( CGraphicsContext::ENullBrush );

 

    TRect rect(iEdwin->Rect());

    rect.Shrink(-1,-1);

    gc.DrawRect(rect);

 

    TRect rect2(iEdwin2->Rect());

    rect2.Shrink(-1,-1);

    gc.DrawRect(rect2);

    }

 

 

// ----------------------------------------------------

// CNugrujxtContainer::OfferKeyEventL(

//     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)

// takes care of key event handling

// ----------------------------------------------------

//

TKeyResponse CNugrujxtContainer::OfferKeyEventL(

    const TKeyEvent& aKeyEvent,TEventCode aType)

    {

    if((aKeyEvent.iCode==EKeyUpArrow)||(aKeyEvent.iCode==EKeyDownArrow))

        {

        if(aType==EEventKey)

            {

            if(iEdwin->IsFocused())

                {

                iEdwin->SetFocus(EFalse);

                iEdwin2->SetFocus(ETrue);

                DrawDeferred();

                }

            else

                {

                iEdwin2->SetFocus(EFalse);

                iEdwin->SetFocus(ETrue);

                DrawDeferred();

                }

            return EKeyWasConsumed;

            }

        }

    else

        {

        if(iEdwin->IsFocused())

            {

            return iEdwin->OfferKeyEventL(aKeyEvent, aType);

            }

        if(iEdwin2->IsFocused())

            {

            return iEdwin2->OfferKeyEventL(aKeyEvent, aType);

            }

        }

    return EKeyWasNotConsumed;

    }

 

 

// End of File  

原创粉丝点击