sl@0
|
1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@test
|
sl@0
|
19 |
@internalComponent - Internal Symbian test code
|
sl@0
|
20 |
*/
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "twindow.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
#include <hal.h>
|
sl@0
|
26 |
#include <ImageConversion.h>
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
/**
|
sl@0
|
30 |
Gets the size of the hardware display in pixels
|
sl@0
|
31 |
@return TSize object containing the screen size
|
sl@0
|
32 |
*/
|
sl@0
|
33 |
TSize CTWindow::GetDisplaySizeInPixels()
|
sl@0
|
34 |
{
|
sl@0
|
35 |
static TSize displaySize;
|
sl@0
|
36 |
static TBool first = ETrue;
|
sl@0
|
37 |
if (first)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
RWsSession ws;
|
sl@0
|
40 |
ws.Connect();
|
sl@0
|
41 |
CWsScreenDevice* screen = new(ELeave) CWsScreenDevice(ws);
|
sl@0
|
42 |
screen->Construct();
|
sl@0
|
43 |
TPixelsAndRotation pixelsAndRotation;
|
sl@0
|
44 |
screen->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
|
sl@0
|
45 |
delete screen;
|
sl@0
|
46 |
ws.Close();
|
sl@0
|
47 |
displaySize = pixelsAndRotation.iPixelSize;
|
sl@0
|
48 |
first = EFalse;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
/*
|
sl@0
|
51 |
// that doesn't work for S60 emulator, it returns wrong values
|
sl@0
|
52 |
TInt x;
|
sl@0
|
53 |
HAL::Get(HALData::EDisplayXPixels, x); // Get number x pixel of screen
|
sl@0
|
54 |
TInt y;
|
sl@0
|
55 |
HAL::Get(HALData::EDisplayYPixels, y); // Get number y pixel of screen
|
sl@0
|
56 |
return TSize(x,y);
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
return displaySize;
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
CFbsBitmap* CTWindow::CreateBitmapFromFileL(const TDesC& aFileName)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
RFs fs;
|
sl@0
|
64 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
65 |
CleanupClosePushL(fs);
|
sl@0
|
66 |
CImageDecoder* decoder = CImageDecoder::FileNewL(fs, aFileName, CImageDecoder::EOptionAlwaysThread);
|
sl@0
|
67 |
CleanupStack::PushL(decoder);
|
sl@0
|
68 |
|
sl@0
|
69 |
CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
|
sl@0
|
70 |
CleanupStack::PushL(bitmap);
|
sl@0
|
71 |
const TFrameInfo& info = decoder->FrameInfo();
|
sl@0
|
72 |
User::LeaveIfError(bitmap->Create(info.iOverallSizeInPixels, info.iFrameDisplayMode));
|
sl@0
|
73 |
TRequestStatus status;
|
sl@0
|
74 |
decoder->Convert(&status, *bitmap);
|
sl@0
|
75 |
User::WaitForRequest(status);
|
sl@0
|
76 |
User::LeaveIfError(status.Int());
|
sl@0
|
77 |
|
sl@0
|
78 |
CleanupStack::Pop(bitmap);
|
sl@0
|
79 |
CleanupStack::PopAndDestroy(decoder);
|
sl@0
|
80 |
CleanupStack::PopAndDestroy(&fs);
|
sl@0
|
81 |
return bitmap;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
CTWindow::CTWindow(const TPoint& aStartingPoint, const TSize& aWindowSize) :
|
sl@0
|
85 |
iLoaded(EFalse), iSize(aWindowSize), iPosition(aStartingPoint)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
iScreenSize = GetDisplaySizeInPixels();
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
void CTWindow::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
// Create a window with the window group as a parent
|
sl@0
|
93 |
iWindow = RWindow(aWs);
|
sl@0
|
94 |
// it's common to use the address of the owning object as an unique window handle
|
sl@0
|
95 |
User::LeaveIfError(iWindow.Construct(aParent, reinterpret_cast<TUint32>(this)));
|
sl@0
|
96 |
iWindow.SetPosition(iPosition);
|
sl@0
|
97 |
iWindow.SetSize(iSize);
|
sl@0
|
98 |
|
sl@0
|
99 |
// Activate window and set it invisible
|
sl@0
|
100 |
iWindow.Activate();
|
sl@0
|
101 |
iWindow.SetVisible(EFalse);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
CTWindow::~CTWindow()
|
sl@0
|
105 |
{
|
sl@0
|
106 |
iDirtyRegion.Close();
|
sl@0
|
107 |
iWindow.Close();
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
void CTWindow::LoadL(CSurfaceUtility* /*aUtility*/, TPtrC /*aFileName*/)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
// empty
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
void CTWindow::RenderL()
|
sl@0
|
116 |
{
|
sl@0
|
117 |
iWindow.SetVisible(ETrue);
|
sl@0
|
118 |
iDirtyRegion.Clear();
|
sl@0
|
119 |
iDirtyRegion.AddRect(TRect(TPoint(0, 0), iScreenSize));
|
sl@0
|
120 |
iDirtyRegion.ClipRect(TRect(iPosition, iSize));
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
void CTWindow::Move(TInt aX, TInt aY)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
iPosition.iX += aX;
|
sl@0
|
126 |
iPosition.iY += aY;
|
sl@0
|
127 |
iWindow.SetPosition(iPosition);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
TPoint CTWindow::CurrentPosition()
|
sl@0
|
131 |
{
|
sl@0
|
132 |
return iPosition;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
void CTWindow::SetPosition(TInt aX, TInt aY)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
iPosition.SetXY(aX, aY);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
void CTWindow::SetVisible(TBool aIsVisible)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
iWindow.SetVisible(aIsVisible);
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
const RRegion& CTWindow::DirtyRegion() const
|
sl@0
|
146 |
{
|
sl@0
|
147 |
return iDirtyRegion;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
TInt CTWindow::SetBackgroundSurface(const TSurfaceId& aSurface)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
return iWindow.SetBackgroundSurface(aSurface);
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
TSize CTWindow::Size()
|
sl@0
|
156 |
{
|
sl@0
|
157 |
return iWindow.Size();
|
sl@0
|
158 |
}
|