os/graphics/graphicstest/uibench/s60/src/windows/tflowwindowscontroller.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
#include "tflowwindowscontroller.h"
sl@0
    23
#include "surfaceutility.h"
sl@0
    24
sl@0
    25
sl@0
    26
const TInt KDefaultFlowRate = -1; // by default window is moved by one pixel to the left
sl@0
    27
//const TInt KScreenMode = 1; // Default Screen Mode (used by rotate screen)
sl@0
    28
sl@0
    29
sl@0
    30
CTFlowWindowsController* CTFlowWindowsController::NewL (TBool aPreload, RArray<TPtrC>& aFileNames,
sl@0
    31
        TSize& aWindowSize, RArray<pTWindowCreatorFunction>& aNewLs,
sl@0
    32
        RArray<TPoint>& aInitialPositions, TBool aBouncing, TBool aMoveHorizontal /*= ETrue*/)
sl@0
    33
    {
sl@0
    34
    CTFlowWindowsController* self = new (ELeave) CTFlowWindowsController(aFileNames.Count(), 
sl@0
    35
            aPreload, aWindowSize, aBouncing, aMoveHorizontal);
sl@0
    36
    CleanupStack::PushL(self);        
sl@0
    37
    self->ConstructL(aFileNames, aNewLs, aInitialPositions);
sl@0
    38
    CleanupStack::Pop(self);
sl@0
    39
    return self;
sl@0
    40
    }
sl@0
    41
sl@0
    42
CTFlowWindowsController::CTFlowWindowsController(TInt aNumWindows, TBool aPreload, TSize& aWindowSize, 
sl@0
    43
        TBool aBouncing, TBool aMoveHorizontal) :
sl@0
    44
        iWindowSize (aWindowSize), iPreload (aPreload), iNumWindows (aNumWindows), iBouncing(aBouncing)
sl@0
    45
    {
sl@0
    46
    iScreenRect = TRect(CTWindow::GetDisplaySizeInPixels());
sl@0
    47
    // if screen is heigher than wide movement is vertical otherwise horizontal
sl@0
    48
    if (aMoveHorizontal)
sl@0
    49
        {
sl@0
    50
        iDeltaX = KDefaultFlowRate;
sl@0
    51
        iDeltaY = 0;
sl@0
    52
        }
sl@0
    53
    else
sl@0
    54
        {
sl@0
    55
        iDeltaX = 0;
sl@0
    56
        iDeltaY = KDefaultFlowRate;
sl@0
    57
        }
sl@0
    58
    }
sl@0
    59
sl@0
    60
void CTFlowWindowsController::ConstructL(RArray<TPtrC>& aFileNames,
sl@0
    61
        RArray<pTWindowCreatorFunction>& aNewLs, RArray<TPoint>& aInitialPositions)
sl@0
    62
    {
sl@0
    63
    iFileNames = aFileNames;    
sl@0
    64
    // Connect to windows server session
sl@0
    65
    User::LeaveIfError(iWs.Connect());    
sl@0
    66
    iScreenDev = new (ELeave) CWsScreenDevice(iWs);
sl@0
    67
    User::LeaveIfError(iScreenDev->Construct());
sl@0
    68
    iUtility = CSurfaceUtility::NewL();    
sl@0
    69
sl@0
    70
    iWinGroup = RWindowGroup(iWs);
sl@0
    71
    // it's common to use the address of the owning object as an unique window group handle 
sl@0
    72
    User::LeaveIfError(iWinGroup.Construct(reinterpret_cast<TUint32>(this)));
sl@0
    73
    
sl@0
    74
    CTWindow* flowWindow;
sl@0
    75
    for (TInt w = 0; w < iNumWindows; w++)
sl@0
    76
        {
sl@0
    77
        flowWindow = aNewLs[w](iWs, iWinGroup, aInitialPositions[w], iWindowSize);
sl@0
    78
        iWindowsRegion.AddRect(TRect(aInitialPositions[w], iWindowSize));
sl@0
    79
        CleanupStack::PushL(flowWindow);        
sl@0
    80
        // always preload the first window regardless of iPreload value
sl@0
    81
        if (w == 0 || iPreload)
sl@0
    82
            {            
sl@0
    83
            flowWindow->LoadL(iUtility, iFileNames[w]);
sl@0
    84
            }
sl@0
    85
        iFlowWindows.AppendL(flowWindow);
sl@0
    86
        CleanupStack::Pop(flowWindow);        
sl@0
    87
        }
sl@0
    88
    }
sl@0
    89
sl@0
    90
CTFlowWindowsController::~CTFlowWindowsController()
sl@0
    91
    {
sl@0
    92
    // windows needs to be deleted seperately
sl@0
    93
    for (TInt i = 0; i < iNumWindows; i++)
sl@0
    94
        {
sl@0
    95
        delete iFlowWindows[i];
sl@0
    96
        }
sl@0
    97
    iFlowWindows.Close();
sl@0
    98
    iWindowsRegion.Close();
sl@0
    99
	iWinGroup.Close();
sl@0
   100
	delete iUtility;
sl@0
   101
	delete iScreenDev;
sl@0
   102
	iWs.Close();
sl@0
   103
    }
sl@0
   104
sl@0
   105
/**
sl@0
   106
Move all Windows and draw them to the screen with the window server.
sl@0
   107
sl@0
   108
*/
sl@0
   109
void CTFlowWindowsController::MoveL()
sl@0
   110
	{
sl@0
   111
	// Prepare to move block of small windows one step in the right direction.
sl@0
   112
    // First check to see if moving them in the current direction would put them off
sl@0
   113
    // the screen.  If so, change the sign of the offset to make the block move in 
sl@0
   114
    // the other direction.
sl@0
   115
    if (iBouncing)
sl@0
   116
        {
sl@0
   117
        iWindowsRegion.Offset(iDeltaX, iDeltaY);
sl@0
   118
        if (!iWindowsRegion.IsContainedBy(iScreenRect))
sl@0
   119
            {
sl@0
   120
            iDeltaX = -iDeltaX;
sl@0
   121
            iDeltaY = -iDeltaY;
sl@0
   122
            iWindowsRegion.Offset(2*iDeltaX, 2*iDeltaY);
sl@0
   123
            }
sl@0
   124
        }
sl@0
   125
	    
sl@0
   126
	for (TInt w = iNumWindows - 1; w >= 0; --w)
sl@0
   127
		{
sl@0
   128
		// make sure that a window has loaded it's content before it moves into the screen rectangle
sl@0
   129
		if (!iPreload)
sl@0
   130
            {
sl@0
   131
            if ((iFlowWindows[w]->CurrentPosition().iX == iWindowSize.iWidth - 1)
sl@0
   132
                    || (iFlowWindows[w]->CurrentPosition().iY == iWindowSize.iHeight - 1))
sl@0
   133
                {
sl@0
   134
                iFlowWindows[w]->LoadL(iUtility, iFileNames[w]);
sl@0
   135
                }
sl@0
   136
            }
sl@0
   137
		iFlowWindows[w]->Move(iDeltaX, iDeltaY);
sl@0
   138
		iFlowWindows[w]->RenderL();
sl@0
   139
        if (!iBouncing)
sl@0
   140
            {
sl@0
   141
            if (iFlowWindows[w]->CurrentPosition().iX < -iWindowSize.iWidth * (iNumWindows - 1))
sl@0
   142
                {
sl@0
   143
                iFlowWindows[w]->SetPosition(iScreenRect.Width() - 1, 0);
sl@0
   144
                }
sl@0
   145
            if (iFlowWindows[w]->CurrentPosition().iY < -iWindowSize.iHeight * (iNumWindows - 1))
sl@0
   146
                {
sl@0
   147
                iFlowWindows[w]->SetPosition(0, iScreenRect.Height() - 1);
sl@0
   148
                }
sl@0
   149
            }
sl@0
   150
		}
sl@0
   151
	iWs.Flush();
sl@0
   152
	iWs.Finish();
sl@0
   153
	}
sl@0
   154
sl@0
   155
void CTFlowWindowsController::SetWindowsVisibility(TBool aVisible)
sl@0
   156
    {
sl@0
   157
	for (TInt w = iNumWindows -1; w >= 0; --w)
sl@0
   158
		{
sl@0
   159
		iFlowWindows[w]->SetVisible(aVisible);
sl@0
   160
        }
sl@0
   161
	iWs.Flush();
sl@0
   162
	iWs.Finish();
sl@0
   163
    }
sl@0
   164
    
sl@0
   165
/**
sl@0
   166
Rotate the screen to a given orientation. Note that if the screen device 
sl@0
   167
and window server session used to display the image aren't used for the 
sl@0
   168
rotation then the image will disappear.
sl@0
   169
*/    
sl@0
   170
void CTFlowWindowsController::Rotate(CFbsBitGc::TGraphicsOrientation aOrientation)
sl@0
   171
    {
sl@0
   172
    // Set new screen mode. The mode is defined in wsini_rotate_test.ini.
sl@0
   173
    //iScreenDev->SetAppScreenMode(KScreenMode);
sl@0
   174
	//iScreenDev->SetScreenMode(KScreenMode);
sl@0
   175
    
sl@0
   176
    // Set the screen orientation.
sl@0
   177
	// todo: check which mode to use
sl@0
   178
	iScreenDev->SetCurrentRotations(iScreenDev->CurrentScreenMode(), aOrientation);
sl@0
   179
	iWs.Flush();
sl@0
   180
	iWs.Finish();
sl@0
   181
    }