Code:
/*
============================================================================
Name : IMAppView.h
Author : 王秉先
Copyright : CartoonSMS
Description : Declares view class for application.
============================================================================
*/
#ifndef __IMAPPVIEW_h__
#define __IMAPPVIEW_h__
// INCLUDES
#include <coecntrl.h>
// CLASS DECLARATION
class CFbsBitmap;
class CIMAppView : public CCoeControl
{
public:
// New methods
/**
* NewL.
* Two-phased constructor.
* Create a CIMAppView object, which will draw itself to aRect.
* @param aRect The rectangle this view will be drawn to.
* @return a pointer to the created instance of CIMAppView.
*/
static CIMAppView* NewL(const TRect& aRect);
/**
* NewLC.
* Two-phased constructor.
* Create a CIMAppView object, which will draw itself
* to aRect.
* @param aRect Rectangle this view will be drawn to.
* @return A pointer to the created instance of CIMAppView.
*/
static CIMAppView* NewLC(const TRect& aRect);
/**
* ~CIMAppView
* Virtual Destructor.
*/
virtual ~CIMAppView();
public:
// Functions from base classes
/**
* From CCoeControl, Draw
* Draw this CIMAppView to the screen.
* @param aRect the rectangle of this view that needs updating
*/
void Draw(const TRect& aRect) const;
/**
* From CoeControl, SizeChanged.
* Called by framework when the view size is changed.
*/
virtual void SizeChanged();
/**
* From CoeControl, HandlePointerEventL.
* Called by framework when a pointer touch event occurs.
* Note: although this method is compatible with earlier SDKs,
* it will not be called in SDKs without Touch support.
* @param aPointerEvent the information about this event
*/
virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
void LoadBitmapL();
private:
// Constructors
/**
* ConstructL
* 2nd phase constructor.
* Perform the second phase construction of a
* CIMAppView object.
* @param aRect The rectangle this view will be drawn to.
*/
void ConstructL(const TRect& aRect);
/**
* CIMAppView.
* C++ default constructor.
*/
CIMAppView();
CFbsBitmap* iBitmap;
};
#endif // __IMAPPVIEW_h__
// End of File
/*
============================================================================
Name : IMAppView.cpp
Author : 王秉先
Copyright : CartoonSMS
Description : Application view implementation
============================================================================
*/
// INCLUDE FILES
#include <coemain.h>
#include <aknutils.h>
#include <IM.mbg>
#include "IMAppView.h"
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CIMAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CIMAppView* CIMAppView::NewL(const TRect& aRect)
{
CIMAppView* self = CIMAppView::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
// -----------------------------------------------------------------------------
// CIMAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CIMAppView* CIMAppView::NewLC(const TRect& aRect)
{
CIMAppView* self = new (ELeave) CIMAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
// -----------------------------------------------------------------------------
// CIMAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CIMAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
LoadBitmapL();
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
void CIMAppView::LoadBitmapL()
{
iBitmap=new (ELeave)CFbsBitmap();
_LIT(KMBMFILE,"\\system\\apps\\IM\\IM.mbm");
TFileName file(KMBMFILE);
// TFilename fname = _L("Multi.mbm");
User::LeaveIfError(CompleteWithAppPath(file));
TRAPD(err,iBitmap->Load(file,EMbmImFace);)
//User::LeaveIfError(iBitmap->Load(file,EMbmImFace));
User::LeaveIfError(err);
}
// -----------------------------------------------------------------------------
// CIMAppView::CIMAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CIMAppView::CIMAppView()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CIMAppView::~CIMAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CIMAppView::~CIMAppView()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CIMAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CIMAppView::Draw(const TRect& /*aRect*/) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
// Gets the control's extent
TRect drawRect(Rect());
// Clears the screen
gc.Clear(drawRect);
gc.BitBlt(TPoint(20,20), iBitmap);
}
// -----------------------------------------------------------------------------
// CIMAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CIMAppView::SizeChanged()
{
DrawNow();
}
// -----------------------------------------------------------------------------
// CIMAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs,
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CIMAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
// Call base class HandlePointerEventL()
CCoeControl::HandlePointerEventL(aPointerEvent);
}
// End of File