📄 chinesedisplaycontainer.cpp
字号:
/*
* ============================================================================
* Name : CChineseDisplayContainer from CChineseDisplayContainer.h
* Part of : ChineseDisplay
* Created : 18.3.2003 by Forum Nokia
* Implementation notes:
* Version :
* Copyright: Nokia Corporation, 2003
* ============================================================================
*/
#include "ChineseDisplayContainer.h"
#include <eiklabel.h> // for example label control
#include <eikenv.h>
#include <gdi.h> // TFontSpec
#include <charconv.h> // CCnvCharacterSetConverter
#include <ChineseDisplay.rsg>
#include "ChineseDisplayAppUi.h"
// ---------------------------------------------------------
// ChineseDisplayAppContainer::ConstructL(const TRect& aRect)
// Second phase constructor
// ---------------------------------------------------------
//
void CChineseDisplayContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
CFont *font;
CWsScreenDevice *aDeviceMap = iEikonEnv->ScreenDevice();
TInt height = 200; // The font size in twips
TFontSpec fontSpec(_L( "System"), height );
// If the proper font libaray exist, can call the specific font
// TFontSpec fontSpec(_L("MS Song"), height );
User::LeaveIfError(aDeviceMap->GetNearestFontInTwips(font, fontSpec));
// Use system font
iLabel->SetFont( font );
aDeviceMap->ReleaseFont( font );
TBuf<64> buf;
CEikonEnv::Static()->ReadResource( buf, R_EXAMPLE_VIEW_TITLE );
iLabel->SetTextL( buf );
iToDoLabel = new (ELeave) CEikLabel;
iToDoLabel->SetContainerWindowL( *this );
CEikonEnv::Static()->ReadResource( buf, R_EXAMPLE_ADD_CONTROL_HERE );
// Read in the hello text
iHelloText = iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_HELLO);
CCnvCharacterSetConverter* converter=CCnvCharacterSetConverter::NewLC();
// Check if there is conversion between GBK/GB2312 and unicode
// if(converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb2312,
if(converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGbk,
iEikonEnv->FsSession())!=CCnvCharacterSetConverter::EAvailable)
User::Leave(KErrNotSupported);
// The following string is "Nokia 7650C" in Chinese
TText8 *str = (TText8*)"诺基亚7650C";
TInt state=CCnvCharacterSetConverter::KStateDefault;
TPtrC8 source( str );
iInfoText = HBufC::NewL( source.Length() );
TPtr16 ptr = iInfoText->Des();
if(CCnvCharacterSetConverter::EErrorIllFormedInput == converter->ConvertToUnicode(ptr, source, state))
User::Leave(KErrArgument); //Leave if error in conversion.
iToDoLabel->SetTextL( ptr );
CleanupStack::PopAndDestroy(); //clean for converter
SetRect(aRect);
ActivateL();
}
// ---------------------------------------------------------
// ChineseDisplayAppContainer::~ChineseDisplayAppContainer
// Destructor
// ---------------------------------------------------------
//
CChineseDisplayContainer::~CChineseDisplayContainer()
{
delete iHelloText;
delete iLabel;
delete iToDoLabel;
delete iInfoText;
}
// ---------------------------------------------------------
// ChineseDisplayAppContainer::ChangeLabelsL()
// Change the label fonts and contents.
// ---------------------------------------------------------
//
void CChineseDisplayContainer::ChangeLabelsL()
{
CFont *font;
// Use Annotation font
font = (CFont*)iEikonEnv->AnnotationFont();
iLabel->SetFont( font );
iLabel->SetTextL( *iHelloText );
// Use Title font
font = (CFont*)iEikonEnv->TitleFont();
iToDoLabel->SetFont( font );
iToDoLabel->SetTextL( *iHelloText );
SizeChanged();
}
// ---------------------------------------------------------
// ChineseDisplayAppContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CChineseDisplayContainer::SizeChanged()
{
iLabel->SetExtent( TPoint( 10,10 ), iLabel->MinimumSize() );
iToDoLabel->SetExtent( TPoint( 10, 100 ), iToDoLabel->MinimumSize() );
}
// ---------------------------------------------------------
// ChineseDisplayAppContainer::CountComponentControls() const
// Return number of controls inside this container. Called by
// the framework.
// ---------------------------------------------------------
//
TInt CChineseDisplayContainer::CountComponentControls() const
{
return 2; // 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;
case 1:
return iToDoLabel;
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);
CFont *font;
CWsScreenDevice *aDeviceMap = iEikonEnv->ScreenDevice();
// The following font may not be displayed exactly what you want
// in a real device if the font library is not available. You may
// copy the font library from a 9210 SDK to the following directory:
// \Symbian\6.1\Series60\Epoc32\Release\wins\UDEB\Z\SYSTEM\Fonts.
// In this case, you may see the font change.
TInt height = 600; // Height in twips
TFontSpec fontSpec( _L("PrcPlain12"), height );
// If the proper font libaray exist, can call the specific font
// TFontSpec fontSpec(_L("MS Song"), height );
User::LeaveIfError( aDeviceMap->GetNearestFontInTwips( font, fontSpec ) );
TRect rect=Rect();
// Use system font
gc.UseFont( font );
TInt baseline = rect.Height()/2 + font->AscentInPixels()/2 - 10;
gc.DrawText( *iHelloText, rect, baseline, CGraphicsContext::ECenter );
aDeviceMap->ReleaseFont( font );
}
// ---------------------------------------------------------
// ChineseDisplayAppContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CChineseDisplayContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -