aknexeditorcontainer9.cpp

来自「国内著名嵌入式培训机构内部资料,内含一些实例代码,包括技术专题书籍」· C++ 代码 · 共 221 行

CPP
221
字号
/*  Copyright (c) 2004, Nokia. All rights reserved */

// INCLUDE FILES
#include <eiklabel.h>  // for example label control
#include <barsread.h>  // for resource reader
#include <eikedwin.h>  // for CEikEdwin
#include <eikgted.h>   // for CEikGlobalTextEditor

#include <aknenv.h>
#include <avkon.hrh>

#include <AknExEditor.rsg>
#include "aknexeditor.hrh"
#include "AknExEditorContainer9.h"
#include "AknExEditorDialog.h"

// ================= MEMBER FUNCTIONS =======================

// ----------------------------------------------------------------------------
// CAknExEditorContainer9::CAknExEditorContainer9()
// C++ default constructor can NOT contain any code, that
// might leave.
//-----------------------------------------------------------------------------
//
CAknExEditorContainer9::CAknExEditorContainer9()
: iLabel1( NULL ), iLabel2( NULL ), iEdwin( NULL ), iGTextEd( NULL )
    {
    }

// ----------------------------------------------------------------------------
// CAknExEditorContainer9::ConstructL()
// two phased constructor
//-----------------------------------------------------------------------------
//
void CAknExEditorContainer9::ConstructL( const TRect& aRect )
    {
    CreateWindowL();

    TBuf<KBufLength> text;

    iCoeEnv->ReadResource( text, R_AKNEXEDITOR_VIEW9_LABEL1 );
    iLabel1 = new ( ELeave ) CEikLabel;
    iLabel1->SetContainerWindowL( *this );
    iLabel1->SetTextL( text );
    iLabel1->SetExtent( EDWIN_LABEL_POS, iLabel1->MinimumSize() );

    iCoeEnv->ReadResource( text, R_AKNEXEDITOR_VIEW9_LABEL2 );
    iLabel2 = new ( ELeave ) CEikLabel;
    iLabel2->SetContainerWindowL( *this );
    iLabel2->SetTextL( text );
    iLabel2->SetExtent( GTEXTED_LABEL_POS, iLabel1->MinimumSize() );

    TResourceReader reader;
    iCoeEnv->CreateResourceReaderLC( reader, R_AKNEXEDITOR_VIEW9_EDWIN );
    iEdwin = new ( ELeave ) CEikEdwin;
    iEdwin->SetContainerWindowL( *this );
    iEdwin->ConstructFromResourceL( reader );
    CleanupStack::PopAndDestroy();  // Resource reader
    iEdwin->SetExtent( EDWIN_POS, iEdwin->MinimumSize() );

    iCoeEnv->CreateResourceReaderLC( reader, R_AKNEXEDITOR_VIEW9_GTEXTED );
    iGTextEd = new ( ELeave ) CEikGlobalTextEditor;
    iGTextEd->SetContainerWindowL( *this );
    iGTextEd->ConstructFromResourceL( reader );
    CleanupStack::PopAndDestroy();  // Resource reader
    iGTextEd->SetExtent( GTEXTED_POS, iGTextEd->MinimumSize() );

    FocusTo( EAknExEditorCmdSelectEdwin1 );

    SetRect( aRect );
    ActivateL();
    }

// ----------------------------------------------------------------------------
// CAknExEditorContainer9::~CAknExEditorContainer9()
// Destructor
//-----------------------------------------------------------------------------
//
CAknExEditorContainer9::~CAknExEditorContainer9()
    {
    delete iLabel1;
    delete iLabel2;
    delete iEdwin;
    delete iGTextEd;
    }

// ---------------------------------------------------------
// CAknExEditorContainer::FocusTo()
// Change foccused control.
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
void CAknExEditorContainer9::FocusTo( TInt aCommand )
    {
    switch ( aCommand )
        {
        case EAknExEditorCmdSelectEdwin1:
            iGTextEd->SetFocus( EFalse );
            iEdwin->SetFocus( ETrue );
            break;
        case EAknExEditorCmdSelectGTextEd1:
            iEdwin->SetFocus( EFalse );
            iGTextEd->SetFocus( ETrue );
            break;
        default:
            break;
        }
    }

// ---------------------------------------------------------
// CAknExEditorContainer9::ShowFormL()
// Show form.
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
void CAknExEditorContainer9::ShowFormL()
    {
    CAknExEditorDialog* dialog = new ( ELeave ) CAknExEditorDialog();
    dialog->ExecuteLD( R_AKNEXEDITOR_VIEW9_DIALOG );
    }


// ---------------------------------------------------------
// CAknExEditorContainer9::SizeChanged()
// Called by framework when the view size is changed
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
void CAknExEditorContainer9::SizeChanged()
    {
    }

// ---------------------------------------------------------
// CAknExEditorContainer9::CountComponentControls() const
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
TInt CAknExEditorContainer9::CountComponentControls() const
    {
    return KNumberOfControls; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CAknExEditorContainer9::ComponentControl()
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
CCoeControl* CAknExEditorContainer9::ComponentControl( TInt aIndex ) const
    {
    switch ( aIndex )
        {
        case EEdwinPrompt:
            return iLabel1;
        case EEdwin:
            return iEdwin;
        case EGTextEdPrompt:
            return iLabel2;
        case EGTextEd:
            return iGTextEd;
        default:
            return NULL;
        }
    }

// ---------------------------------------------------------
// CAknExEditorContainer9::Draw()
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
void CAknExEditorContainer9::Draw( const TRect& aRect ) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }

// ---------------------------------------------------------
// CAknExEditorContainer9::OfferKeyEventL()
// Notify key events to editors.
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
TKeyResponse CAknExEditorContainer9::OfferKeyEventL( 
    const TKeyEvent& aKeyEvent, TEventCode aType )
    {
    TKeyResponse ret = EKeyWasNotConsumed;

    if ( iEdwin )
        {
        if ( iEdwin->IsFocused() )
            {
            ret =  iEdwin->OfferKeyEventL( aKeyEvent, aType );
            return ret;
            }
        }
    if ( iGTextEd )
        {
        if ( iGTextEd->IsFocused() )
            {
            ret =  iGTextEd->OfferKeyEventL( aKeyEvent, aType );
            return ret;
            }
        }
    return EKeyWasNotConsumed;
    }


// ---------------------------------------------------------
// CAknExEditorContainer9::HandleControlEventL()
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
void CAknExEditorContainer9::HandleControlEventL( 
    CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/ )
    {
    }

// End of File  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?