📄 drawimagecontainer.cpp
字号:
/*
============================================================================
Name : DrawImageContainer.cpp
Author : caitong
Copyright : Your copyright notice
Description : Container control implementation
============================================================================
*/
// INCLUDE FILES
#include "DrawImageContainer.h"
#include <eiklabel.h> // for example label control
#include <DrawImage.mbg>
#include <aknutils.h>
#include <fbs.h>
_LIT(KBitBltBitmapPath,"\\system\\apps\\DrawImage\\DrawImage.mbm");
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CDrawImageContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CDrawImageContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL( _L("Example View") );
iToDoLabel = new (ELeave) CEikLabel;
iToDoLabel->SetContainerWindowL( *this );
iToDoLabel->SetTextL( _L("Add Your controls\n here") );
SetRect(aRect);
iBitmap = new (ELeave) CFbsBitmap();
TFileName bitmapFile (KBitBltBitmapPath);
User::LeaveIfError (CompleteWithAppPath (bitmapFile));
User::LeaveIfError(iBitmap->Load(bitmapFile, EMbmDrawimageLoginbg));
iOffScrnBmp = new (ELeave) CFbsBitmap;
User::LeaveIfError(iOffScrnBmp->Create(Size(), EColor4K));
iOffScrnBmpDevice = CFbsBitmapDevice::NewL(iOffScrnBmp);
User::LeaveIfError(iOffScrnBmpDevice->CreateContext(iOffScrnContext));
ActivateL();
}
// Destructor
CDrawImageContainer::~CDrawImageContainer()
{
delete iBitmap;
delete iOffScrnBmp;
delete iOffScrnBmpDevice;
delete iOffScrnContext;
delete iLabel;
delete iToDoLabel;
}
// ---------------------------------------------------------
// CDrawImageContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CDrawImageContainer::SizeChanged()
{
// TODO: Add here control resize code etc.
iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
}
// ---------------------------------------------------------
// CDrawImageContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CDrawImageContainer::CountComponentControls() const
{
return 2; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CDrawImageContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CDrawImageContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
case 1:
return iToDoLabel;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CDrawImageContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CDrawImageContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
gc.Clear(aRect);
TPoint topLeft(10,40);
gc.BitBlt(topLeft,iBitmap);
// iOffScrnContext->Clear(Rect());
for (int i=0; i<50; i+=2)
{
iOffScrnContext->DrawRect(TRect(TPoint(i+30, i+30), TSize(25, 25)));
}
// CWindowGc& gc = SystemGc();
gc.BitBlt(TPoint(0, 0), iOffScrnBmp);
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
// gc.DrawRect( aRect );
}
// ---------------------------------------------------------
// CDrawImageContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CDrawImageContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -