aknexeditorcontainer1.cpp

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

CPP
228
字号
/*  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 <AknExEditor.rsg>
#include "aknexeditor.hrh"
#include "AknExEditorContainer1.h"


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

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

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

    TBuf<KBufLength> text;

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

    iCoeEnv->ReadResource( text, R_AKNEXEDITOR_VIEW1_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_VIEW1_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_VIEW1_GTEXTED );
    iGTextEd = new ( ELeave ) CEikGlobalTextEditor;
    iGTextEd->SetContainerWindowL( *this );
    iGTextEd->ConstructFromResourceL( reader );
    CleanupStack::PopAndDestroy();  // Resource reader
    iGTextEd->SetExtent( GTEXTED_POS, iGTextEd->MinimumSize() );
    
    iEdwinDynamic = new ( ELeave ) CEikEdwin;
    iEdwinDynamic->ConstructL(0,8,20,1);
    iEdwinDynamic->SetContainerWindowL( *this );
    iEdwinDynamic->SetExtent( TPoint( 10, 100 ), iEdwinDynamic->MinimumSize() );
    
    //给文本编辑器设置初值
    TBuf<20> buf;
    buf.Append(_L("this is example"));
    iGTextEd->SetTextL(&buf);
    iEdwinDynamic->SetTextL(&buf);
    
    //获取编辑器中的内容
    TBuf<30> bufContent;
    iEdwinDynamic->GetText(&bufContent);
    iEdwin->SetTextL(&bufContent);
    
    
    iEdwinDynamic->SetFocus( ETrue );

    SetRect( aRect );
    ActivateL();
    }

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

// ---------------------------------------------------------
// CAknExEditorContainer::FocusTo()
// Change foccused control.
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
void CAknExEditorContainer1::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;
        }
    }

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

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

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

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

// ---------------------------------------------------------
// CAknExEditorContainer1::OfferKeyEventL()
// Notify key events to editors.
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
TKeyResponse CAknExEditorContainer1::OfferKeyEventL( 
            const TKeyEvent& aKeyEvent, TEventCode aType )
    {
    if ( iEdwin )
        {
        if ( iEdwin->IsFocused() )
            {
            return iEdwin->OfferKeyEventL( aKeyEvent, aType );
            }
        }
    if ( iGTextEd )
        {
        if ( iGTextEd->IsFocused() )
            {
            return iGTextEd->OfferKeyEventL( aKeyEvent, aType );
            }
        }
    if ( iEdwinDynamic )
            {
            if ( iEdwinDynamic->IsFocused() )
                {
                return iEdwinDynamic->OfferKeyEventL( aKeyEvent, aType );
                }
            }
    return EKeyWasNotConsumed;
    }


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

// End of File  

⌨️ 快捷键说明

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