os/graphics/graphicstest/uibench/s60/src/windows/tflowwindowscontroller.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code 
    20 */
    21 
    22 #include "tflowwindowscontroller.h"
    23 #include "surfaceutility.h"
    24 
    25 
    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)
    28 
    29 
    30 CTFlowWindowsController* CTFlowWindowsController::NewL (TBool aPreload, RArray<TPtrC>& aFileNames,
    31         TSize& aWindowSize, RArray<pTWindowCreatorFunction>& aNewLs,
    32         RArray<TPoint>& aInitialPositions, TBool aBouncing, TBool aMoveHorizontal /*= ETrue*/)
    33     {
    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);
    39     return self;
    40     }
    41 
    42 CTFlowWindowsController::CTFlowWindowsController(TInt aNumWindows, TBool aPreload, TSize& aWindowSize, 
    43         TBool aBouncing, TBool aMoveHorizontal) :
    44         iWindowSize (aWindowSize), iPreload (aPreload), iNumWindows (aNumWindows), iBouncing(aBouncing)
    45     {
    46     iScreenRect = TRect(CTWindow::GetDisplaySizeInPixels());
    47     // if screen is heigher than wide movement is vertical otherwise horizontal
    48     if (aMoveHorizontal)
    49         {
    50         iDeltaX = KDefaultFlowRate;
    51         iDeltaY = 0;
    52         }
    53     else
    54         {
    55         iDeltaX = 0;
    56         iDeltaY = KDefaultFlowRate;
    57         }
    58     }
    59 
    60 void CTFlowWindowsController::ConstructL(RArray<TPtrC>& aFileNames,
    61         RArray<pTWindowCreatorFunction>& aNewLs, RArray<TPoint>& aInitialPositions)
    62     {
    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();    
    69 
    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)));
    73     
    74     CTWindow* flowWindow;
    75     for (TInt w = 0; w < iNumWindows; w++)
    76         {
    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)
    82             {            
    83             flowWindow->LoadL(iUtility, iFileNames[w]);
    84             }
    85         iFlowWindows.AppendL(flowWindow);
    86         CleanupStack::Pop(flowWindow);        
    87         }
    88     }
    89 
    90 CTFlowWindowsController::~CTFlowWindowsController()
    91     {
    92     // windows needs to be deleted seperately
    93     for (TInt i = 0; i < iNumWindows; i++)
    94         {
    95         delete iFlowWindows[i];
    96         }
    97     iFlowWindows.Close();
    98     iWindowsRegion.Close();
    99 	iWinGroup.Close();
   100 	delete iUtility;
   101 	delete iScreenDev;
   102 	iWs.Close();
   103     }
   104 
   105 /**
   106 Move all Windows and draw them to the screen with the window server.
   107 
   108 */
   109 void CTFlowWindowsController::MoveL()
   110 	{
   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.
   115     if (iBouncing)
   116         {
   117         iWindowsRegion.Offset(iDeltaX, iDeltaY);
   118         if (!iWindowsRegion.IsContainedBy(iScreenRect))
   119             {
   120             iDeltaX = -iDeltaX;
   121             iDeltaY = -iDeltaY;
   122             iWindowsRegion.Offset(2*iDeltaX, 2*iDeltaY);
   123             }
   124         }
   125 	    
   126 	for (TInt w = iNumWindows - 1; w >= 0; --w)
   127 		{
   128 		// make sure that a window has loaded it's content before it moves into the screen rectangle
   129 		if (!iPreload)
   130             {
   131             if ((iFlowWindows[w]->CurrentPosition().iX == iWindowSize.iWidth - 1)
   132                     || (iFlowWindows[w]->CurrentPosition().iY == iWindowSize.iHeight - 1))
   133                 {
   134                 iFlowWindows[w]->LoadL(iUtility, iFileNames[w]);
   135                 }
   136             }
   137 		iFlowWindows[w]->Move(iDeltaX, iDeltaY);
   138 		iFlowWindows[w]->RenderL();
   139         if (!iBouncing)
   140             {
   141             if (iFlowWindows[w]->CurrentPosition().iX < -iWindowSize.iWidth * (iNumWindows - 1))
   142                 {
   143                 iFlowWindows[w]->SetPosition(iScreenRect.Width() - 1, 0);
   144                 }
   145             if (iFlowWindows[w]->CurrentPosition().iY < -iWindowSize.iHeight * (iNumWindows - 1))
   146                 {
   147                 iFlowWindows[w]->SetPosition(0, iScreenRect.Height() - 1);
   148                 }
   149             }
   150 		}
   151 	iWs.Flush();
   152 	iWs.Finish();
   153 	}
   154 
   155 void CTFlowWindowsController::SetWindowsVisibility(TBool aVisible)
   156     {
   157 	for (TInt w = iNumWindows -1; w >= 0; --w)
   158 		{
   159 		iFlowWindows[w]->SetVisible(aVisible);
   160         }
   161 	iWs.Flush();
   162 	iWs.Finish();
   163     }
   164     
   165 /**
   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.
   169 */    
   170 void CTFlowWindowsController::Rotate(CFbsBitGc::TGraphicsOrientation aOrientation)
   171     {
   172     // Set new screen mode. The mode is defined in wsini_rotate_test.ini.
   173     //iScreenDev->SetAppScreenMode(KScreenMode);
   174 	//iScreenDev->SetScreenMode(KScreenMode);
   175     
   176     // Set the screen orientation.
   177 	// todo: check which mode to use
   178 	iScreenDev->SetCurrentRotations(iScreenDev->CurrentScreenMode(), aOrientation);
   179 	iWs.Flush();
   180 	iWs.Finish();
   181     }