Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
26 #include <ImageConversion.h>
30 Gets the size of the hardware display in pixels
31 @return TSize object containing the screen size
33 TSize CTWindow::GetDisplaySizeInPixels()
35 static TSize displaySize;
36 static TBool first = ETrue;
41 CWsScreenDevice* screen = new(ELeave) CWsScreenDevice(ws);
43 TPixelsAndRotation pixelsAndRotation;
44 screen->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
47 displaySize = pixelsAndRotation.iPixelSize;
51 // that doesn't work for S60 emulator, it returns wrong values
53 HAL::Get(HALData::EDisplayXPixels, x); // Get number x pixel of screen
55 HAL::Get(HALData::EDisplayYPixels, y); // Get number y pixel of screen
61 CFbsBitmap* CTWindow::CreateBitmapFromFileL(const TDesC& aFileName)
64 User::LeaveIfError(fs.Connect());
65 CleanupClosePushL(fs);
66 CImageDecoder* decoder = CImageDecoder::FileNewL(fs, aFileName, CImageDecoder::EOptionAlwaysThread);
67 CleanupStack::PushL(decoder);
69 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
70 CleanupStack::PushL(bitmap);
71 const TFrameInfo& info = decoder->FrameInfo();
72 User::LeaveIfError(bitmap->Create(info.iOverallSizeInPixels, info.iFrameDisplayMode));
73 TRequestStatus status;
74 decoder->Convert(&status, *bitmap);
75 User::WaitForRequest(status);
76 User::LeaveIfError(status.Int());
78 CleanupStack::Pop(bitmap);
79 CleanupStack::PopAndDestroy(decoder);
80 CleanupStack::PopAndDestroy(&fs);
84 CTWindow::CTWindow(const TPoint& aStartingPoint, const TSize& aWindowSize) :
85 iLoaded(EFalse), iSize(aWindowSize), iPosition(aStartingPoint)
87 iScreenSize = GetDisplaySizeInPixels();
90 void CTWindow::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent)
92 // Create a window with the window group as a parent
93 iWindow = RWindow(aWs);
94 // it's common to use the address of the owning object as an unique window handle
95 User::LeaveIfError(iWindow.Construct(aParent, reinterpret_cast<TUint32>(this)));
96 iWindow.SetPosition(iPosition);
97 iWindow.SetSize(iSize);
99 // Activate window and set it invisible
101 iWindow.SetVisible(EFalse);
104 CTWindow::~CTWindow()
106 iDirtyRegion.Close();
110 void CTWindow::LoadL(CSurfaceUtility* /*aUtility*/, TPtrC /*aFileName*/)
115 void CTWindow::RenderL()
117 iWindow.SetVisible(ETrue);
118 iDirtyRegion.Clear();
119 iDirtyRegion.AddRect(TRect(TPoint(0, 0), iScreenSize));
120 iDirtyRegion.ClipRect(TRect(iPosition, iSize));
123 void CTWindow::Move(TInt aX, TInt aY)
127 iWindow.SetPosition(iPosition);
130 TPoint CTWindow::CurrentPosition()
135 void CTWindow::SetPosition(TInt aX, TInt aY)
137 iPosition.SetXY(aX, aY);
140 void CTWindow::SetVisible(TBool aIsVisible)
142 iWindow.SetVisible(aIsVisible);
145 const RRegion& CTWindow::DirtyRegion() const
150 TInt CTWindow::SetBackgroundSurface(const TSurfaceId& aSurface)
152 return iWindow.SetBackgroundSurface(aSurface);
155 TSize CTWindow::Size()
157 return iWindow.Size();