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: #include "tflowwindowscontroller.h" sl@0: #include "surfaceutility.h" sl@0: sl@0: sl@0: const TInt KDefaultFlowRate = -1; // by default window is moved by one pixel to the left sl@0: //const TInt KScreenMode = 1; // Default Screen Mode (used by rotate screen) sl@0: sl@0: sl@0: CTFlowWindowsController* CTFlowWindowsController::NewL (TBool aPreload, RArray& aFileNames, sl@0: TSize& aWindowSize, RArray& aNewLs, sl@0: RArray& aInitialPositions, TBool aBouncing, TBool aMoveHorizontal /*= ETrue*/) sl@0: { sl@0: CTFlowWindowsController* self = new (ELeave) CTFlowWindowsController(aFileNames.Count(), sl@0: aPreload, aWindowSize, aBouncing, aMoveHorizontal); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aFileNames, aNewLs, aInitialPositions); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CTFlowWindowsController::CTFlowWindowsController(TInt aNumWindows, TBool aPreload, TSize& aWindowSize, sl@0: TBool aBouncing, TBool aMoveHorizontal) : sl@0: iWindowSize (aWindowSize), iPreload (aPreload), iNumWindows (aNumWindows), iBouncing(aBouncing) sl@0: { sl@0: iScreenRect = TRect(CTWindow::GetDisplaySizeInPixels()); sl@0: // if screen is heigher than wide movement is vertical otherwise horizontal sl@0: if (aMoveHorizontal) sl@0: { sl@0: iDeltaX = KDefaultFlowRate; sl@0: iDeltaY = 0; sl@0: } sl@0: else sl@0: { sl@0: iDeltaX = 0; sl@0: iDeltaY = KDefaultFlowRate; sl@0: } sl@0: } sl@0: sl@0: void CTFlowWindowsController::ConstructL(RArray& aFileNames, sl@0: RArray& aNewLs, RArray& aInitialPositions) sl@0: { sl@0: iFileNames = aFileNames; sl@0: // Connect to windows server session sl@0: User::LeaveIfError(iWs.Connect()); sl@0: iScreenDev = new (ELeave) CWsScreenDevice(iWs); sl@0: User::LeaveIfError(iScreenDev->Construct()); sl@0: iUtility = CSurfaceUtility::NewL(); sl@0: sl@0: iWinGroup = RWindowGroup(iWs); sl@0: // it's common to use the address of the owning object as an unique window group handle sl@0: User::LeaveIfError(iWinGroup.Construct(reinterpret_cast(this))); sl@0: sl@0: CTWindow* flowWindow; sl@0: for (TInt w = 0; w < iNumWindows; w++) sl@0: { sl@0: flowWindow = aNewLs[w](iWs, iWinGroup, aInitialPositions[w], iWindowSize); sl@0: iWindowsRegion.AddRect(TRect(aInitialPositions[w], iWindowSize)); sl@0: CleanupStack::PushL(flowWindow); sl@0: // always preload the first window regardless of iPreload value sl@0: if (w == 0 || iPreload) sl@0: { sl@0: flowWindow->LoadL(iUtility, iFileNames[w]); sl@0: } sl@0: iFlowWindows.AppendL(flowWindow); sl@0: CleanupStack::Pop(flowWindow); sl@0: } sl@0: } sl@0: sl@0: CTFlowWindowsController::~CTFlowWindowsController() sl@0: { sl@0: // windows needs to be deleted seperately sl@0: for (TInt i = 0; i < iNumWindows; i++) sl@0: { sl@0: delete iFlowWindows[i]; sl@0: } sl@0: iFlowWindows.Close(); sl@0: iWindowsRegion.Close(); sl@0: iWinGroup.Close(); sl@0: delete iUtility; sl@0: delete iScreenDev; sl@0: iWs.Close(); sl@0: } sl@0: sl@0: /** sl@0: Move all Windows and draw them to the screen with the window server. sl@0: sl@0: */ sl@0: void CTFlowWindowsController::MoveL() sl@0: { sl@0: // Prepare to move block of small windows one step in the right direction. sl@0: // First check to see if moving them in the current direction would put them off sl@0: // the screen. If so, change the sign of the offset to make the block move in sl@0: // the other direction. sl@0: if (iBouncing) sl@0: { sl@0: iWindowsRegion.Offset(iDeltaX, iDeltaY); sl@0: if (!iWindowsRegion.IsContainedBy(iScreenRect)) sl@0: { sl@0: iDeltaX = -iDeltaX; sl@0: iDeltaY = -iDeltaY; sl@0: iWindowsRegion.Offset(2*iDeltaX, 2*iDeltaY); sl@0: } sl@0: } sl@0: sl@0: for (TInt w = iNumWindows - 1; w >= 0; --w) sl@0: { sl@0: // make sure that a window has loaded it's content before it moves into the screen rectangle sl@0: if (!iPreload) sl@0: { sl@0: if ((iFlowWindows[w]->CurrentPosition().iX == iWindowSize.iWidth - 1) sl@0: || (iFlowWindows[w]->CurrentPosition().iY == iWindowSize.iHeight - 1)) sl@0: { sl@0: iFlowWindows[w]->LoadL(iUtility, iFileNames[w]); sl@0: } sl@0: } sl@0: iFlowWindows[w]->Move(iDeltaX, iDeltaY); sl@0: iFlowWindows[w]->RenderL(); sl@0: if (!iBouncing) sl@0: { sl@0: if (iFlowWindows[w]->CurrentPosition().iX < -iWindowSize.iWidth * (iNumWindows - 1)) sl@0: { sl@0: iFlowWindows[w]->SetPosition(iScreenRect.Width() - 1, 0); sl@0: } sl@0: if (iFlowWindows[w]->CurrentPosition().iY < -iWindowSize.iHeight * (iNumWindows - 1)) sl@0: { sl@0: iFlowWindows[w]->SetPosition(0, iScreenRect.Height() - 1); sl@0: } sl@0: } sl@0: } sl@0: iWs.Flush(); sl@0: iWs.Finish(); sl@0: } sl@0: sl@0: void CTFlowWindowsController::SetWindowsVisibility(TBool aVisible) sl@0: { sl@0: for (TInt w = iNumWindows -1; w >= 0; --w) sl@0: { sl@0: iFlowWindows[w]->SetVisible(aVisible); sl@0: } sl@0: iWs.Flush(); sl@0: iWs.Finish(); sl@0: } sl@0: sl@0: /** sl@0: Rotate the screen to a given orientation. Note that if the screen device sl@0: and window server session used to display the image aren't used for the sl@0: rotation then the image will disappear. sl@0: */ sl@0: void CTFlowWindowsController::Rotate(CFbsBitGc::TGraphicsOrientation aOrientation) sl@0: { sl@0: // Set new screen mode. The mode is defined in wsini_rotate_test.ini. sl@0: //iScreenDev->SetAppScreenMode(KScreenMode); sl@0: //iScreenDev->SetScreenMode(KScreenMode); sl@0: sl@0: // Set the screen orientation. sl@0: // todo: check which mode to use sl@0: iScreenDev->SetCurrentRotations(iScreenDev->CurrentScreenMode(), aOrientation); sl@0: iWs.Flush(); sl@0: iWs.Finish(); sl@0: }