?? emptycontainer.cpp
字號:
#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 "Empty.rsg"
#include "EmptyUi.h"
#include "EmptyContainer.h"
#include "Empty.h"
#include "..\help\Empty.hlp.hrh"
void CEmptyContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL(_L("first window"));
//另外一種顯示中文的方法。。。
CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
TBool chineseLanguageSupported = EFalse;
if( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGbk,
iEikonEnv->FsSession()) == CCnvCharacterSetConverter::EAvailable )
{
chineseLanguageSupported = ETrue;
}
else if ( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGb2312,
iEikonEnv->FsSession() ) == CCnvCharacterSetConverter::EAvailable )
{
chineseLanguageSupported = ETrue;
}
TText8 *str = (TText8*)"拍拍365";
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();
}
void CEmptyContainer2::ConstructL(const TRect& aRect,CEmptyContainer2* iAppContainer2)
{
// Create a window for this application view
CreateWindowL();//復合控件創建窗口
iLabel2=new(ELeave) CEikLabel;
iLabel2->SetContainerWindowL(*iAppContainer2);//將不擁有窗口的控件和窗口關聯
iLabel2->SetTextL(_L("sencond window"));
//另外一種顯示中文的方法。。。
CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
TBool chineseLanguageSupported = EFalse;
if( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGbk,
iEikonEnv->FsSession()) == CCnvCharacterSetConverter::EAvailable )
{
chineseLanguageSupported = ETrue;
}
else if ( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGb2312,
iEikonEnv->FsSession() ) == CCnvCharacterSetConverter::EAvailable )
{
chineseLanguageSupported = ETrue;
}
TText8 *str = (TText8*)"不要365";
TInt state=CCnvCharacterSetConverter::KStateDefault;
TPtrC8 source( str );
iInfoText2 = HBufC::NewL( source.Length() );
TPtr16 ptr = iInfoText2->Des();
if( chineseLanguageSupported )
{
TRAP_IGNORE( converter->ConvertToUnicode( ptr, source, state ) );
}
//到此...........
CleanupStack::PopAndDestroy(); // converter
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
CEmptyContainer::~CEmptyContainer()
{
delete iLabel;
delete iInfoText;
//指針為空嗎? iLabel=NULL
}
CEmptyContainer2::~CEmptyContainer2()
{
delete iLabel2;
delete iInfoText2;
}
void CEmptyContainer::SizeChanged()
{
iLabel->SetExtent( TPoint( 10,10 ), iLabel->MinimumSize());
}
void CEmptyContainer2::SizeChanged()
{
iLabel2->SetExtent( TPoint( 10,10 ), iLabel2->MinimumSize());
}
TInt CEmptyContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
TInt CEmptyContainer2::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
CCoeControl* CEmptyContainer::ComponentControl( TInt aIndex ) const
{
switch ( aIndex )
{
case 0:
return iLabel;
default:
return NULL;
}
}
CCoeControl* CEmptyContainer2::ComponentControl( TInt aIndex ) const
{
switch ( aIndex )
{
case 0:
return iLabel2;
default:
return NULL;
}
}
void CEmptyContainer::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 );
}
}
void CEmptyContainer2::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(iInfoText2->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 );
}
}
void CEmptyContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
void CEmptyContainer2::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
void CEmptyContainer::GetHelpContext(TCoeHelpContext& aContext ) const
{
aContext.iMajor = KUidEmpty;
aContext.iContext = KContextChinese;
}
void CEmptyContainer2::GetHelpContext(TCoeHelpContext& aContext ) const
{
aContext.iMajor = KUidEmpty;
aContext.iContext = KContextChinese;
}
/*void CEmptyContainer::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
}
void CEmptyContainer::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
}
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -