⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aoexamplecontainer.cpp

📁 Active Object实现动画
💻 CPP
字号:
/*
* ==============================================================================
*  Name     : CAOExampleContainer
*  Part of  : AOExample
*  Created  : 3.5.2004 by Markus Pelkonen
*  Implementation notes: See detailed documentation from the file
*                        "AOExampleContainer.h"
*  Version  :
*  Copyright: Nokia
* ==============================================================================
*/

#include "AOExampleContainer.h"
#include <eikedwin.h>

// -----------------------------------------------------------------------------
void CAOExampleContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    iTextBox = new (ELeave) CEikEdwin();
    iTextBox->SetContainerWindowL( *this );
    iTextBox->SetAknEditorFlags(EAknEditorFlagEnableScrollBars);
    iTextBox->ConstructL( CEikEdwin::ENoAutoSelection |
                          CEikEdwin::EDisplayOnly |
                          CEikEdwin::EReadOnly );
    iTextBox->SetExtent(TPoint(), aRect.Size() );

    SetRect(aRect);
    ActivateL();
    }

// -----------------------------------------------------------------------------
CAOExampleContainer::~CAOExampleContainer()
    {
    delete iTextBox;
    }

// -----------------------------------------------------------------------------
void CAOExampleContainer::AppendTextL( const TDesC16& aText )
    {
    TInt pos = iBuf.Length();
    TInt spaceAvailable = iBuf.MaxLength() - iBuf.Length();
    iBuf.Append( aText.Left( spaceAvailable ) );
    UpdateTextL( pos );
    }

// -----------------------------------------------------------------------------
void CAOExampleContainer::AppendTextL( const TDesC8& aText )
    {
    TInt pos = iBuf.Length();
    // copy 8 bit character data to 16 bit descriptor
    TInt charsToCopy = iBuf.MaxLength() - iBuf.Length();
    if( aText.Length() < charsToCopy )
        {
            charsToCopy = aText.Length();
        }
    for(int i=0; i<charsToCopy; i++)
        {
        iBuf.Append( aText[i] );
        }
    UpdateTextL(pos);
    }

// -----------------------------------------------------------------------------
void CAOExampleContainer::Clear()
    {
    iBuf.Zero();
    UpdateTextL(0);
    }

// -----------------------------------------------------------------------------
void CAOExampleContainer::UpdateTextL(TInt aFromIndex)
    {
    // replace any '\n' characters from buffer with UCS paragraph separator if
    // unicode build.
#ifdef _UNICODE
    TText16* ptr = (TText16*)iBuf.Ptr();
    TText16* endPtr = ptr + iBuf.Length();
    ptr += aFromIndex;
    for(;ptr < endPtr; ptr++ )
    {
        if( *ptr == '\n' )
        {
            *ptr = 0x2029; // UCS_PARASEP = 0x2029
        }
    }
#endif
    iTextBox->SetTextL( &iBuf );
    iTextBox->DrawNow();
    iTextBox->SetFocus( ETrue );
    iTextBox->SetCursorPosL( iBuf.Length(), FALSE );
    }

// -----------------------------------------------------------------------------
TKeyResponse CAOExampleContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
                                                  TEventCode aType )
    {
    TKeyResponse result = EKeyWasNotConsumed;

    // map keys to cursor movements
    struct KeyMapping
        {
        TInt iScanCode;
        TCursorPosition::TMovementType iCursorMovement;
        };
    static const KeyMapping map[] =
        {
            { EStdKeyDownArrow,  TCursorPosition::EFPageDown },
            { EStdKeyUpArrow,    TCursorPosition::EFPageUp   },
            { EStdKeyRightArrow, TCursorPosition::EFLineDown },
            { EStdKeyLeftArrow,  TCursorPosition::EFLineUp   },
        };

    // iterate through mapping. If pressed key was is found from mappin, take
    // the cursor move mapped to the key for the edwin contorol.
    for( TUint i=0; i<(sizeof map)/sizeof(KeyMapping); i++ )
        {
        if( aKeyEvent.iScanCode == map[i].iScanCode )
            {
            result = EKeyWasConsumed;
            if( aType == EEventKeyDown )
                {
                iTextBox->MoveCursorL( map[i].iCursorMovement, EFalse );
                break; // for
                }
            }
        }
    return result;
    }

// -----------------------------------------------------------------------------
TInt CAOExampleContainer::CountComponentControls() const
    {
    return 1;
    }

// -----------------------------------------------------------------------------
CCoeControl* CAOExampleContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iTextBox;
        default:
            return NULL;
        }
    }

// -----------------------------------------------------------------------------
void CAOExampleContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    // TODO: Add your control event handler code here
    }

⌨️ 快捷键说明

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