os/graphics/graphicstest/uibench/s60/src/windows/tsmallwindowraster.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code 
    20 */
    21 
    22 
    23 #include "tsmallwindowraster.h"
    24 
    25 
    26 _LIT(KBitmapPattern, "*.mbm");
    27 
    28 
    29 CTSmallWindowRaster::CTSmallWindowRaster(const TPoint& aStartingPoint, const TSize& aWindowSize) :
    30         CTWindow(aStartingPoint, aWindowSize)
    31 	{
    32 	// empty
    33 	}
    34 
    35 CTSmallWindowRaster::~CTSmallWindowRaster()
    36 	{
    37 	if (iGc)
    38 	    {
    39 	    iGc->Deactivate();
    40 	    delete iGc;
    41 	    }
    42 	delete iSourceBitmap;
    43 	delete iScreenDev;
    44 	}
    45 
    46 CTWindow* CTSmallWindowRaster::NewL(RWsSession &aWs, 
    47 		const RWindowTreeNode &aParent, 
    48 		const TPoint& aStartingPoint,
    49 		const TSize& aWindowSize)
    50 	{
    51 	CTSmallWindowRaster* self = new (ELeave) CTSmallWindowRaster(aStartingPoint, aWindowSize);
    52 	CleanupStack::PushL(self);
    53 	self->ConstructL(aWs, aParent);
    54 	CleanupStack::Pop(self);
    55 	return self;
    56 	}
    57 
    58 void CTSmallWindowRaster::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent)
    59 	{
    60 	CTWindow::ConstructL(aWs, aParent);
    61 	iScreenDev = new (ELeave) CWsScreenDevice(aWs);
    62 	User::LeaveIfError(iScreenDev->Construct());
    63 	iGc = new (ELeave)CWindowGc(iScreenDev);
    64 	User::LeaveIfError(iGc->Construct());
    65 	iGc->Activate(iWindow);
    66 	}
    67 
    68 void CTSmallWindowRaster::LoadL(CSurfaceUtility* /*aUtility*/, TPtrC aFileName)
    69 	{
    70 	iLoaded = ETrue;
    71 	if (aFileName.Match(KBitmapPattern()) != KErrNotFound) // it's a Bitmap
    72         {
    73         iSourceBitmap = new(ELeave) CFbsBitmap();
    74         User::LeaveIfError(iSourceBitmap->Load(aFileName, 0));
    75         }
    76 	else
    77 	    {
    78 	    iSourceBitmap = CreateBitmapFromFileL(aFileName);
    79 	    }
    80 	iSourceRect = iSourceBitmap->SizeInPixels();	
    81 	iDestRect = TRect(Size());
    82 	}
    83 
    84 void CTSmallWindowRaster::DrawBitmap(TRect& aSourceRect)
    85     {
    86     iWindow.BeginRedraw();
    87     iGc->DrawBitmap(iDestRect, iSourceBitmap, aSourceRect);
    88     iWindow.EndRedraw();
    89     }
    90 
    91 void CTSmallWindowRaster::RenderL()
    92 	{
    93 	CTWindow::RenderL();
    94 	if (iLoaded)
    95 	    {
    96 	    DrawBitmap(iSourceRect);
    97 	    }
    98 	}