fontsandtextbasiccontainer.cpp
来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 103 行
CPP
103 行
/**
*
* @brief Definition of CFontsAndTextBasicContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class includes
#include "FontsAndTextBasicContainer.h"
// System includes
#include <eikenv.h> // CEikonEnv iEikonEnv
#include <FontsAndText.rsg> // R_FONTSANDTEXT_LOCALIZATION_TEXT
#include <StringLoader.h> // StringLoader
// CONSTANTS
const TInt KHorizOffset = 5;
const TInt KVertOffset = 2;
const TInt KTextMaxLength = 50;
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2 phase constructor.
* Constructs the CFontsAndTextBasicContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CFontsAndTextBasicContainer
*/
CFontsAndTextBasicContainer* CFontsAndTextBasicContainer::NewL(const TRect& aRect)
{
CFontsAndTextBasicContainer* self = CFontsAndTextBasicContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CFontsAndTextBasicContainer using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CFontsAndTextBasicContainer
*/
CFontsAndTextBasicContainer* CFontsAndTextBasicContainer::NewLC(const TRect& aRect)
{
CFontsAndTextBasicContainer* self = new (ELeave) CFontsAndTextBasicContainer();
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
/**
* Symbian OS 2nd phase constructor. Creates a Window for the control to draw to.
* Activates the control
* @param aRect The rectangle for this window
*/
void CFontsAndTextBasicContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
ActivateL();
}
/**
* Destructor.
*/
CFontsAndTextBasicContainer::~CFontsAndTextBasicContainer()
{
}
/**
* This draw function obtains a handle to a graphics context and clears it
* Using the 'Normal Font' of the system a text string is drawn
*
* @param aRect the rectangular area to draw in. Used to position text
*/
void CFontsAndTextBasicContainer::Draw(const TRect& aRect) const
{
// Obtain graphics context and clear it
CWindowGc& gc = SystemGc();
gc.Clear();
// Set position of text relative to the rectangle of the control
TPoint textPoint(aRect.Width() / KHorizOffset, aRect.Height() / KVertOffset);
// Use resource architecture to obtain localizable string
TBuf<KTextMaxLength> text;
StringLoader::Load(text, R_FONTSANDTEXT_LOCALIZATION_TEXT);
// Gain handle to Normal font of the system
const CFont* normalFont = iEikonEnv->NormalFont();
gc.UseFont(normalFont);
gc.DrawText(text, textPoint); // Draw text
gc.DiscardFont(); // Discard font
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?