sl@0: // Copyright (c) 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: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "twindow.h" sl@0: sl@0: #include sl@0: #include sl@0: sl@0: sl@0: /** sl@0: Gets the size of the hardware display in pixels sl@0: @return TSize object containing the screen size sl@0: */ sl@0: TSize CTWindow::GetDisplaySizeInPixels() sl@0: { sl@0: static TSize displaySize; sl@0: static TBool first = ETrue; sl@0: if (first) sl@0: { sl@0: RWsSession ws; sl@0: ws.Connect(); sl@0: CWsScreenDevice* screen = new(ELeave) CWsScreenDevice(ws); sl@0: screen->Construct(); sl@0: TPixelsAndRotation pixelsAndRotation; sl@0: screen->GetDefaultScreenSizeAndRotation(pixelsAndRotation); sl@0: delete screen; sl@0: ws.Close(); sl@0: displaySize = pixelsAndRotation.iPixelSize; sl@0: first = EFalse; sl@0: } sl@0: /* sl@0: // that doesn't work for S60 emulator, it returns wrong values sl@0: TInt x; sl@0: HAL::Get(HALData::EDisplayXPixels, x); // Get number x pixel of screen sl@0: TInt y; sl@0: HAL::Get(HALData::EDisplayYPixels, y); // Get number y pixel of screen sl@0: return TSize(x,y); sl@0: */ sl@0: return displaySize; sl@0: } sl@0: sl@0: CFbsBitmap* CTWindow::CreateBitmapFromFileL(const TDesC& aFileName) sl@0: { sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CImageDecoder* decoder = CImageDecoder::FileNewL(fs, aFileName, CImageDecoder::EOptionAlwaysThread); sl@0: CleanupStack::PushL(decoder); sl@0: sl@0: CFbsBitmap* bitmap = new (ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(bitmap); sl@0: const TFrameInfo& info = decoder->FrameInfo(); sl@0: User::LeaveIfError(bitmap->Create(info.iOverallSizeInPixels, info.iFrameDisplayMode)); sl@0: TRequestStatus status; sl@0: decoder->Convert(&status, *bitmap); sl@0: User::WaitForRequest(status); sl@0: User::LeaveIfError(status.Int()); sl@0: sl@0: CleanupStack::Pop(bitmap); sl@0: CleanupStack::PopAndDestroy(decoder); sl@0: CleanupStack::PopAndDestroy(&fs); sl@0: return bitmap; sl@0: } sl@0: sl@0: CTWindow::CTWindow(const TPoint& aStartingPoint, const TSize& aWindowSize) : sl@0: iLoaded(EFalse), iSize(aWindowSize), iPosition(aStartingPoint) sl@0: { sl@0: iScreenSize = GetDisplaySizeInPixels(); sl@0: } sl@0: sl@0: void CTWindow::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent) sl@0: { sl@0: // Create a window with the window group as a parent sl@0: iWindow = RWindow(aWs); sl@0: // it's common to use the address of the owning object as an unique window handle sl@0: User::LeaveIfError(iWindow.Construct(aParent, reinterpret_cast(this))); sl@0: iWindow.SetPosition(iPosition); sl@0: iWindow.SetSize(iSize); sl@0: sl@0: // Activate window and set it invisible sl@0: iWindow.Activate(); sl@0: iWindow.SetVisible(EFalse); sl@0: } sl@0: sl@0: CTWindow::~CTWindow() sl@0: { sl@0: iDirtyRegion.Close(); sl@0: iWindow.Close(); sl@0: } sl@0: sl@0: void CTWindow::LoadL(CSurfaceUtility* /*aUtility*/, TPtrC /*aFileName*/) sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: void CTWindow::RenderL() sl@0: { sl@0: iWindow.SetVisible(ETrue); sl@0: iDirtyRegion.Clear(); sl@0: iDirtyRegion.AddRect(TRect(TPoint(0, 0), iScreenSize)); sl@0: iDirtyRegion.ClipRect(TRect(iPosition, iSize)); sl@0: } sl@0: sl@0: void CTWindow::Move(TInt aX, TInt aY) sl@0: { sl@0: iPosition.iX += aX; sl@0: iPosition.iY += aY; sl@0: iWindow.SetPosition(iPosition); sl@0: } sl@0: sl@0: TPoint CTWindow::CurrentPosition() sl@0: { sl@0: return iPosition; sl@0: } sl@0: sl@0: void CTWindow::SetPosition(TInt aX, TInt aY) sl@0: { sl@0: iPosition.SetXY(aX, aY); sl@0: } sl@0: sl@0: void CTWindow::SetVisible(TBool aIsVisible) sl@0: { sl@0: iWindow.SetVisible(aIsVisible); sl@0: } sl@0: sl@0: const RRegion& CTWindow::DirtyRegion() const sl@0: { sl@0: return iDirtyRegion; sl@0: } sl@0: sl@0: TInt CTWindow::SetBackgroundSurface(const TSurfaceId& aSurface) sl@0: { sl@0: return iWindow.SetBackgroundSurface(aSurface); sl@0: } sl@0: sl@0: TSize CTWindow::Size() sl@0: { sl@0: return iWindow.Size(); sl@0: }