sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include "stdgraphicdrawer.h"
sl@0: #include "wsgraphicdrawercontext.h"
sl@0: #include <s32mem.h>
sl@0: #include <fbs.h>
sl@0: 
sl@0: CWsGraphicDrawerBitmap* CWsGraphicDrawerBitmap::CreateL()
sl@0: 	{
sl@0: 	return new(ELeave) CWsGraphicDrawerBitmap;
sl@0: 	}
sl@0: 	
sl@0: void CWsGraphicDrawerBitmap::ConstructL(MWsGraphicDrawerEnvironment& aEnv,const TGraphicDrawerId& aId,MWsClient& aOwner,const TDesC8& aData)
sl@0: 	{
sl@0: 	TInt bitmapHandle = 0;
sl@0: 	TInt maskHandle = 0;
sl@0: 	RDesReadStream in(aData);
sl@0: 	in.PushL();
sl@0: 	bitmapHandle = in.ReadInt32L();
sl@0: 	maskHandle = in.ReadInt32L();
sl@0: 	in.Pop();
sl@0: 	BaseConstructL(aEnv,aId,aOwner);
sl@0: 	if(bitmapHandle)
sl@0: 		{
sl@0: 		iBitmap = new(ELeave) CFbsBitmap;
sl@0: 		User::LeaveIfError(iBitmap->Duplicate(bitmapHandle));
sl@0: 		if(maskHandle)
sl@0: 			{
sl@0: 			iMask = new(ELeave) CFbsBitmap;
sl@0: 			User::LeaveIfError(iMask->Duplicate(maskHandle));
sl@0: 			}
sl@0: 		}
sl@0: 	if (!(aEnv.Screen(0)->ResolveObjectInterface(KMWsCompositionContext) || aEnv.Screen(0)->ResolveObjectInterface(KMWsScene)))
sl@0: 		{
sl@0: 		iContext = CWsGraphicDrawerNonNgaContext::NewL();
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		iContext = CWsGraphicDrawerNgaContext::NewL();
sl@0: 		}
sl@0: 	}
sl@0: 	
sl@0: CWsGraphicDrawerBitmap::CWsGraphicDrawerBitmap()
sl@0: 	{
sl@0: 	}
sl@0: 	
sl@0: CWsGraphicDrawerBitmap::~CWsGraphicDrawerBitmap()
sl@0: 	{
sl@0: 	if (iContext)
sl@0: 		{
sl@0: 		iContext->Destroy();
sl@0: 		iContext = NULL;
sl@0: 		}
sl@0: 	delete iBitmap;
sl@0: 	delete iMask;
sl@0: 	}
sl@0: 
sl@0: void CWsGraphicDrawerBitmap::DoDraw(MWsGc& aGc,const TRect& aRect,const TDesC8& /*aData*/) const
sl@0: 	{
sl@0: 	if (iBitmap)
sl@0: 		{
sl@0: 		if (KErrNone != iContext->Push(aGc))
sl@0: 			{
sl@0: 			return;
sl@0: 			}
sl@0: 		TRect bmpRect(aRect.iTl,iBitmap->SizeInPixels());
sl@0: 		bmpRect.Intersection(aRect);
sl@0: 		iContext->DrawBitmap(aGc, aRect.iTl, iBitmap, bmpRect.Size(), iMask);
sl@0: 		iContext->Pop(aGc);
sl@0: 		}
sl@0: 	}
sl@0: 	
sl@0: void CWsGraphicDrawerBitmap::HandleMessage(const TDesC8& /*aData*/)
sl@0: 	{
sl@0: 	}
sl@0: