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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
23 #include "cmultiplesurfaces.h"
24 #include "tsmallwindowraster.h"
27 const TInt KTimeBetweenFrames = 100000; // checks every 100 ms for a new message
29 // messages which are sent by the test step
30 const TInt KBringToFront = 1;
31 const TInt KTerminate = 2;
33 // defines number of windows on the screen
34 const TInt KWindowsAcross = 1;
35 const TInt KWindowsDown = 1;
37 _LIT(KSmallBitmap,"z:\\resource\\apps\\cover2.jpg"); // bitmap that is displayed by the windows
40 CMultipleSurfaces* CMultipleSurfaces::NewL(RWsSession& aWs, RWindowGroup& aWindowGroup, TPtrC childQueueName, CMultipleSurfacesAppUi* aMultipleSurfacesAppUi, TPtrC aParentQueueName)
42 CMultipleSurfaces* self = new (ELeave)CMultipleSurfaces(aWs, aWindowGroup, aMultipleSurfacesAppUi);
43 self->ConstructL(childQueueName, aParentQueueName);
47 CMultipleSurfaces::CMultipleSurfaces(RWsSession& aWs, RWindowGroup& aWindowGroup, CMultipleSurfacesAppUi* aMultipleSurfacesAppUi) :
48 iWs(aWs), iWindowGroup(aWindowGroup), iMultipleSurfacesAppUi(aMultipleSurfacesAppUi)
53 CMultipleSurfaces::~CMultipleSurfaces()
56 iParentMsgQueue.Send(KTerminate);
57 iParentMsgQueue.Close();
59 for (TInt w = 0; w < iSmallWindows.Count(); w++)
61 delete iSmallWindows[w];
63 iSmallWindows.Close();
66 void CMultipleSurfaces::ConstructL(TPtrC childQueueName, TPtrC aParentQueueName)
68 iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
69 // available screensize is reduced by the menu bar
70 TSize screenSize = iMultipleSurfacesAppUi->ClientRect().Size();
73 windowSize.iHeight = screenSize.iHeight/KWindowsDown;
74 windowSize.iWidth = screenSize.iWidth/KWindowsAcross;
75 // adjust window size to make square windows
76 if (windowSize.iWidth > windowSize.iHeight)
78 windowSize.iWidth = windowSize.iHeight;
82 windowSize.iHeight = windowSize.iWidth;
85 // available screensize is reduced by the menu bar
86 TPoint initialPosition(iMultipleSurfacesAppUi->ClientRect().iTl);
87 CSurfaceUtility* utility = CSurfaceUtility::NewL();
88 CleanupStack::PushL(utility);
89 CTWindow* smallWindow;
90 for (TInt i = 0; i < KWindowsAcross; i++)
92 initialPosition.iX = 0;
93 for (TInt j = 0; j < KWindowsDown; j++)
95 smallWindow = CTSmallWindowRaster::NewL(iWs, iWindowGroup, initialPosition, windowSize);
96 CleanupStack::PushL(smallWindow);
97 smallWindow->LoadL(utility, KSmallBitmap());
98 iSmallWindows.AppendL(smallWindow);
99 CleanupStack::Pop(smallWindow);
100 initialPosition.iX += windowSize.iWidth;
102 initialPosition.iY += windowSize.iHeight;
104 CleanupStack::PopAndDestroy(utility);
105 User::LeaveIfError(iMsgQueue.OpenGlobal(childQueueName));
106 User::LeaveIfError(iParentMsgQueue.OpenGlobal(aParentQueueName));
107 // inform test app that the message queues are ready
108 RProcess::Rendezvous(KErrNone);
114 * Starts a timer which redraws the screen periodically.
116 void CMultipleSurfaces::Start()
118 iTimer->Start(0, KTimeBetweenFrames, TCallBack(TimerCallBack, this));
121 TInt CMultipleSurfaces::TimerCallBack(TAny* MultipleSurfaces)
123 TRAPD(err, static_cast<CMultipleSurfaces*>(MultipleSurfaces)->RenderL());
128 * Meassures the time it takes to bring this application to the foreground.
129 * It receives a message from the test step which coordinates the switching.
131 void CMultipleSurfaces::RenderL()
134 iMsgQueue.ReceiveBlocking(msg);
136 for (TInt w = 0; w < iSmallWindows.Count(); w++)
138 iSmallWindows[w]->Move(0, 1);
139 iSmallWindows[w]->RenderL();
148 TUint32 timeStamp = User::FastCounter();
149 iMultipleSurfacesAppUi->BringToFront();
150 TUint32 time = User::FastCounter() - timeStamp;
151 iParentMsgQueue.Send(time);
157 iMultipleSurfacesAppUi->Terminate();
166 void CMultipleSurfaces::Stop()