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

📄 chinesedisplaycontainer.cpp

📁 This C++ application demonstrates how to display Chinese characters from resource files. The applica
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CChineseDisplayContainer from CChineseDisplayContainer.h
*  Part of  : ChineseDisplay
*  Created  : 18.3.2003 by Forum Nokia
*  Implementation notes:
*  Version  :
*  Copyright: Nokia Corporation, 2003
* ============================================================================
*/

#include <eiklabel.h> 
#include <eikenv.h>
#include <gdi.h>
#include <charconv.h>
#include <e32cons.h>
#include <aknenv.h>
#include <aknutils.h>
#include <e32def.h>
#include <ChineseDisplay.rsg>

#include "ChineseDisplayAppUi.h"
#include "ChineseDisplayContainer.h"
#include "ChineseDisplayApp.h"
#include "..\help\ChineseDisplay.hlp.hrh"

// ---------------------------------------------------------
// ChineseDisplayAppContainer::ConstructL(const TRect& aRect)
// Second phase constructor
// ---------------------------------------------------------
//
void CChineseDisplayContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
    
	// Read in the hello text
	iEikonEnv->ReadResourceL(iHelloText, R_EXAMPLE_TEXT_HELLO );
	iLabel->SetTextL( iHelloText );    
	
	CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
	// Check if there is conversion between GBK/GB2312 and unicode 
	// if(converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb2312,

	TBool chineseLanguageSupported = EFalse;

	if( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGbk,
		iEikonEnv->FsSession()) == CCnvCharacterSetConverter::EAvailable )
		{
		chineseLanguageSupported = ETrue;
		}
	else if ( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGb2312,
		iEikonEnv->FsSession() ) == CCnvCharacterSetConverter::EAvailable )
		{
		chineseLanguageSupported = ETrue;
		}

	// The following string is "Nokia" in simplified Chinese
	TText8  *str = (TText8*)"诺基亚";
    TInt state=CCnvCharacterSetConverter::KStateDefault;

	TPtrC8 source( str );
	iInfoText = HBufC::NewL( source.Length() );
	TPtr16 ptr = iInfoText->Des();

	if( chineseLanguageSupported )
		{
		TRAP_IGNORE( converter->ConvertToUnicode( ptr, source, state ) )
		}

	CleanupStack::PopAndDestroy();  // converter

    SetRect( aRect );
    ActivateL();
    }

// ---------------------------------------------------------
// ChineseDisplayAppContainer::~ChineseDisplayAppContainer
// Destructor
// ---------------------------------------------------------
//
CChineseDisplayContainer::~CChineseDisplayContainer()
    {
    delete iLabel;
	delete iInfoText;
    }

// ---------------------------------------------------------
// ChineseDisplayAppContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CChineseDisplayContainer::SizeChanged()
    {
    iLabel->SetExtent( TPoint( 10,10 ), iLabel->MinimumSize() );
    }

// ---------------------------------------------------------
// ChineseDisplayAppContainer::CountComponentControls() const
// Return number of controls inside this container. Called by
// the framework.
// ---------------------------------------------------------
//
TInt CChineseDisplayContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// ChineseDisplayAppContainer::ComponentControl(TInt aIndex) const
// Return the control pointers according to the index. Called 
// by the GUI framework.
// ---------------------------------------------------------
//
CCoeControl* CChineseDisplayContainer::ComponentControl( TInt aIndex ) const
    {
    switch ( aIndex )
        {
        case 0:
            return iLabel;
        default:
            return NULL;
        }
    }

// ---------------------------------------------------------
// ChineseDisplayAppContainer::Draw(const TRect& aRect) const
// Draw the screen.
// ---------------------------------------------------------
//
void CChineseDisplayContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();

    gc.SetPenStyle( CGraphicsContext::ESolidPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect(aRect);

	const CFont* font;
	// Define the buffer to display
	TBuf<KMaxStringLength> buf;
	
	TLanguage language =  User::Language(); 

	if ( language == ELangPrcChinese || 
		 language == ELangTaiwanChinese ||
		 language == ELangHongKongChinese )
		{
		font = ApacPlain16();
		buf.Copy( iInfoText->Des() );
		
		TRect rect = Rect();

		// Use system font
		gc.UseFont( font );
		TInt baseline = rect.Height()/2 + font->AscentInPixels()/2 - 10;
		gc.DrawText( buf, rect, baseline, CGraphicsContext::ECenter );
		}
    }

// ---------------------------------------------------------
// ChineseDisplayAppContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CChineseDisplayContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    }

void CChineseDisplayContainer::GetHelpContext( TCoeHelpContext& aContext ) const
    {
    // Get any special help context for the control with focus, else a default 
    aContext.iMajor = KUidChineseDisplay;

    aContext.iContext = KContextChinese;
    }

⌨️ 快捷键说明

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