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

📄 aknexeditorcontainer.cpp

📁 国内著名嵌入式培训机构内部资料,内含一些实例代码,包括技术专题书籍
💻 CPP
字号:
/*
* ==============================================================================
*  Name        : aknexeditorcontainer.cpp
*  Part of     : Editor example
*  Interface   :
*  Description :
*  Version     :
*
*  Copyright (c) 2004 - 2006 Nokia Corporation.
*  This material, including documentation and any related
*  computer programs, is protected by copyright controlled by
*  Nokia Corporation.
* ==============================================================================
*/

// 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 <aknutils.h>  // for Fonts

#include <AknExEditor.rsg>
#include "aknexeditor.hrh"
#include "AknExEditorContainer.h"

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

// ----------------------------------------------------------------------------
// CAknExEditorContainer::CAknExEditorContainer()
// C++ default constructor can NOT contain any code, that
// might leave.
//-----------------------------------------------------------------------------
//
CAknExEditorContainer::CAknExEditorContainer()
: iLabel( NULL ), iGTextEd( NULL )
    {
    }

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

    iLabel = new ( ELeave ) CEikLabel;
    iLabel->SetContainerWindowL( *this );

    TResourceReader reader;
    iCoeEnv->CreateResourceReaderLC( reader, R_AKNEXEDITOR_VIEW_GTEXTED );
    iGTextEd = new ( ELeave ) CEikGlobalTextEditor;
    iGTextEd->SetContainerWindowL( *this );
    iGTextEd->ConstructFromResourceL( reader );
    CleanupStack::PopAndDestroy();  // Resource reader

    iGTextEd->SetAvkonWrap( ETrue );

    // Enable cut copy support
    iGTextEd->EnableCcpuSupportL( ETrue );
    iGTextEd->SetFocus( ETrue );

    SetRect( aRect );

    // editor takes care of drawing; this control does not draw anything
    SetBlank();
    ActivateL();
    }

// ----------------------------------------------------------------------------
// CAknExEditorContainer::~CAknExEditorContainer()
// Destructor
//-----------------------------------------------------------------------------
//
CAknExEditorContainer::~CAknExEditorContainer()
    {
    delete iLabel;
    delete iGTextEd;
    }

// ---------------------------------------------------------
// void CAknExEditorContainer::SetSystemFontL()
// Change font style of CEikGlobalTextEditor using system font.
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
void CAknExEditorContainer::SetSystemFontL( TInt aFontEnum )
    {
    const CFont* editorFont;

    switch ( aFontEnum )
        {
        case ELatinBold13:
            editorFont = LatinBold13();
            break;
        case ELatinBold17:
            editorFont = LatinBold17();
            break;
        case ELatinBold19:
            editorFont = LatinBold19();
            break;
        default:
            return;
        }

    TCharFormat     charFormat;
    TCharFormatMask charFormatMask;

    charFormat.iFontSpec = editorFont->FontSpecInTwips();
    charFormatMask.SetAll();

    // Set font to GlobalTextEditor
    iGTextEd->ApplyCharFormatL( charFormat, charFormatMask );
    }

// ---------------------------------------------------------
// CAknExEditorContainer::SizeChanged()
// Called by framework when the view size is changed
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
void CAknExEditorContainer::SizeChanged()
    {
    TSize size = Size();
    if (iGTextEd->ScrollBarFrame())
        {
        size.iWidth -= iGTextEd->ScrollBarFrame()->VerticalScrollBar()->ScrollBarBreadth();
        }
    iGTextEd->SetExtent(TPoint(0,0), size);
    }

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

// ---------------------------------------------------------
// CAknExEditorContainer::ComponentControl()
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
CCoeControl* CAknExEditorContainer::ComponentControl( TInt aIndex ) const
    {
    switch ( aIndex )
        {
        case EGTextEdPrompt:
            return iLabel;
        case EGTextEd:
            return iGTextEd;
        default:
            return NULL;
        }
    }

//---------------------------------------------------------
// CAknExEditorContainer::TestSelectedCase()
//---------------------------------------------------------
//
void CAknExEditorContainer::TestSelectedCase( TInt aCommand )
    {
    CEikGlobalTextEditor* gtextedptr = iGTextEd;

    if ( aCommand == EAknExEditorSelectText )
        {
        if( gtextedptr->TextLength() )
            {
            gtextedptr->SelectAllL();
            }
        }

    else if( aCommand == EAknExEditorClearSelection )
        {
        if ( gtextedptr->SelectionLength() )
            {
            gtextedptr->ClearSelectionL();
            }
        }

    else if( aCommand == EAknExEditorCut )
        {
        if( gtextedptr->CcpuCanCut() )
            {
            gtextedptr->CcpuCutL();
            }
        }

    else if( aCommand == EAknExEditorCopy )
        {
        if( gtextedptr->CcpuCanCopy() && gtextedptr->TextLength() )
            {
            gtextedptr->CcpuCopyL();
            }
        }

    else if( aCommand == EAknExEditorPaste )
        {
        if( gtextedptr->CcpuCanPaste() )
            {
            gtextedptr->CcpuPasteL();
            }
        }
    }

//---------------------------------------------------------
// CAknExEditorContainer::ScrollTextL()
//---------------------------------------------------------
//
void CAknExEditorContainer::ScrollTextL( TInt aCommand )
    {
    if ( aCommand == EAknExEditorScrollUp )
        {
        iGTextEd->MoveCursorL( TCursorPosition::EFPageUp, EFalse );
        }

    else if( aCommand == EAknExEditorScrollDown )
        {
        iGTextEd->MoveCursorL( TCursorPosition::EFPageDown, EFalse );
        }
    }

//---------------------------------------------------------
// CAknExEditorContainer::SaveToFileL()
//---------------------------------------------------------
//
void CAknExEditorContainer::SaveToFileL()
    {
    CPlainText* text = iGTextEd->Text();

    TFileName filePath;
    RFs fsSession;
    User::LeaveIfError(fsSession.Connect());
    fsSession.ShareProtected();

    User::LeaveIfError(fsSession.PrivatePath(filePath));

    // append the text file name to the private path
    filePath.Append(KAknExEditorFilePath);
    text->ExportAsTextL( filePath,
                         CPlainText::EOrganiseByParagraph, 0 );
    fsSession.Close();
    }

//---------------------------------------------------------
// CAknExEditorContainer::OpenFileL()
//---------------------------------------------------------
//
void CAknExEditorContainer::OpenFileL()
    {
    ClearTextL();

    TFileName filePath;
    RFs fsSession;
    User::LeaveIfError(fsSession.Connect());

    User::LeaveIfError(fsSession.PrivatePath(filePath));

    // append the text file name to the private path
    filePath.Append(KAknExEditorFilePath);
    iGTextEd->InsertFromTextFileL( filePath,
                                   CPlainText::EOrganiseByParagraph );
    fsSession.Close();
    }

// ---------------------------------------------------------
// CAknExEditorContainer::ClearTextL()
// Called when the text is cleared
// ---------------------------------------------------------
//
void CAknExEditorContainer::ClearTextL()
    {
    _LIT( KEmptyString, "" );
    const TDesC* ptr = &KEmptyString;
    iGTextEd->SetTextL( ptr );
    }

// ---------------------------------------------------------
// CAknExEditorContainer::OfferKeyEventL()
// Notify key events to the editor.
// ( other items were commented in a header ).
// ---------------------------------------------------------
//
TKeyResponse CAknExEditorContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent, TEventCode aType )
    {
    return iGTextEd->OfferKeyEventL( aKeyEvent, aType );
    }

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

// End of File

⌨️ 快捷键说明

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