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
22 #include "tflowwindowscontroller.h"
23 #include "surfaceutility.h"
26 const TInt KDefaultFlowRate = -1; // by default window is moved by one pixel to the left
27 //const TInt KScreenMode = 1; // Default Screen Mode (used by rotate screen)
30 CTFlowWindowsController* CTFlowWindowsController::NewL (TBool aPreload, RArray<TPtrC>& aFileNames,
31 TSize& aWindowSize, RArray<pTWindowCreatorFunction>& aNewLs,
32 RArray<TPoint>& aInitialPositions, TBool aBouncing, TBool aMoveHorizontal /*= ETrue*/)
34 CTFlowWindowsController* self = new (ELeave) CTFlowWindowsController(aFileNames.Count(),
35 aPreload, aWindowSize, aBouncing, aMoveHorizontal);
36 CleanupStack::PushL(self);
37 self->ConstructL(aFileNames, aNewLs, aInitialPositions);
38 CleanupStack::Pop(self);
42 CTFlowWindowsController::CTFlowWindowsController(TInt aNumWindows, TBool aPreload, TSize& aWindowSize,
43 TBool aBouncing, TBool aMoveHorizontal) :
44 iWindowSize (aWindowSize), iPreload (aPreload), iNumWindows (aNumWindows), iBouncing(aBouncing)
46 iScreenRect = TRect(CTWindow::GetDisplaySizeInPixels());
47 // if screen is heigher than wide movement is vertical otherwise horizontal
50 iDeltaX = KDefaultFlowRate;
56 iDeltaY = KDefaultFlowRate;
60 void CTFlowWindowsController::ConstructL(RArray<TPtrC>& aFileNames,
61 RArray<pTWindowCreatorFunction>& aNewLs, RArray<TPoint>& aInitialPositions)
63 iFileNames = aFileNames;
64 // Connect to windows server session
65 User::LeaveIfError(iWs.Connect());
66 iScreenDev = new (ELeave) CWsScreenDevice(iWs);
67 User::LeaveIfError(iScreenDev->Construct());
68 iUtility = CSurfaceUtility::NewL();
70 iWinGroup = RWindowGroup(iWs);
71 // it's common to use the address of the owning object as an unique window group handle
72 User::LeaveIfError(iWinGroup.Construct(reinterpret_cast<TUint32>(this)));
75 for (TInt w = 0; w < iNumWindows; w++)
77 flowWindow = aNewLs[w](iWs, iWinGroup, aInitialPositions[w], iWindowSize);
78 iWindowsRegion.AddRect(TRect(aInitialPositions[w], iWindowSize));
79 CleanupStack::PushL(flowWindow);
80 // always preload the first window regardless of iPreload value
81 if (w == 0 || iPreload)
83 flowWindow->LoadL(iUtility, iFileNames[w]);
85 iFlowWindows.AppendL(flowWindow);
86 CleanupStack::Pop(flowWindow);
90 CTFlowWindowsController::~CTFlowWindowsController()
92 // windows needs to be deleted seperately
93 for (TInt i = 0; i < iNumWindows; i++)
95 delete iFlowWindows[i];
98 iWindowsRegion.Close();
106 Move all Windows and draw them to the screen with the window server.
109 void CTFlowWindowsController::MoveL()
111 // Prepare to move block of small windows one step in the right direction.
112 // First check to see if moving them in the current direction would put them off
113 // the screen. If so, change the sign of the offset to make the block move in
114 // the other direction.
117 iWindowsRegion.Offset(iDeltaX, iDeltaY);
118 if (!iWindowsRegion.IsContainedBy(iScreenRect))
122 iWindowsRegion.Offset(2*iDeltaX, 2*iDeltaY);
126 for (TInt w = iNumWindows - 1; w >= 0; --w)
128 // make sure that a window has loaded it's content before it moves into the screen rectangle
131 if ((iFlowWindows[w]->CurrentPosition().iX == iWindowSize.iWidth - 1)
132 || (iFlowWindows[w]->CurrentPosition().iY == iWindowSize.iHeight - 1))
134 iFlowWindows[w]->LoadL(iUtility, iFileNames[w]);
137 iFlowWindows[w]->Move(iDeltaX, iDeltaY);
138 iFlowWindows[w]->RenderL();
141 if (iFlowWindows[w]->CurrentPosition().iX < -iWindowSize.iWidth * (iNumWindows - 1))
143 iFlowWindows[w]->SetPosition(iScreenRect.Width() - 1, 0);
145 if (iFlowWindows[w]->CurrentPosition().iY < -iWindowSize.iHeight * (iNumWindows - 1))
147 iFlowWindows[w]->SetPosition(0, iScreenRect.Height() - 1);
155 void CTFlowWindowsController::SetWindowsVisibility(TBool aVisible)
157 for (TInt w = iNumWindows -1; w >= 0; --w)
159 iFlowWindows[w]->SetVisible(aVisible);
166 Rotate the screen to a given orientation. Note that if the screen device
167 and window server session used to display the image aren't used for the
168 rotation then the image will disappear.
170 void CTFlowWindowsController::Rotate(CFbsBitGc::TGraphicsOrientation aOrientation)
172 // Set new screen mode. The mode is defined in wsini_rotate_test.ini.
173 //iScreenDev->SetAppScreenMode(KScreenMode);
174 //iScreenDev->SetScreenMode(KScreenMode);
176 // Set the screen orientation.
177 // todo: check which mode to use
178 iScreenDev->SetCurrentRotations(iScreenDev->CurrentScreenMode(), aOrientation);