os/graphics/graphicstest/uibench/s60/src/windows/twindow.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 
    23 #include "twindow.h"
    24 
    25 #include <hal.h>
    26 #include <ImageConversion.h>
    27 
    28 
    29 /**
    30 Gets the size of the hardware display in pixels
    31 @return TSize object containing the screen size
    32 */
    33 TSize CTWindow::GetDisplaySizeInPixels()
    34     {
    35     static TSize displaySize;
    36     static TBool first = ETrue;    
    37     if (first)
    38         {
    39         RWsSession ws;
    40         ws.Connect();
    41         CWsScreenDevice* screen = new(ELeave) CWsScreenDevice(ws);
    42         screen->Construct();        
    43         TPixelsAndRotation pixelsAndRotation;
    44         screen->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
    45         delete screen;
    46         ws.Close();
    47         displaySize = pixelsAndRotation.iPixelSize;
    48         first = EFalse;
    49         }
    50     /*
    51     // that doesn't work for S60 emulator, it returns wrong values
    52     TInt x;
    53     HAL::Get(HALData::EDisplayXPixels, x);  // Get number x pixel of screen
    54     TInt y;
    55     HAL::Get(HALData::EDisplayYPixels, y);  // Get number y pixel of screen
    56     return TSize(x,y);
    57     */
    58     return displaySize;
    59     }
    60 
    61 CFbsBitmap* CTWindow::CreateBitmapFromFileL(const TDesC& aFileName)
    62     {
    63     RFs fs;    
    64     User::LeaveIfError(fs.Connect());
    65     CleanupClosePushL(fs);
    66     CImageDecoder* decoder = CImageDecoder::FileNewL(fs, aFileName, CImageDecoder::EOptionAlwaysThread);
    67     CleanupStack::PushL(decoder);
    68 
    69     CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
    70     CleanupStack::PushL(bitmap);
    71     const TFrameInfo& info = decoder->FrameInfo();
    72     User::LeaveIfError(bitmap->Create(info.iOverallSizeInPixels, info.iFrameDisplayMode));
    73     TRequestStatus status;
    74     decoder->Convert(&status, *bitmap);
    75     User::WaitForRequest(status);
    76     User::LeaveIfError(status.Int());
    77 
    78     CleanupStack::Pop(bitmap);
    79     CleanupStack::PopAndDestroy(decoder);
    80     CleanupStack::PopAndDestroy(&fs);
    81     return bitmap;
    82     }
    83 
    84 CTWindow::CTWindow(const TPoint& aStartingPoint, const TSize& aWindowSize) : 
    85         iLoaded(EFalse), iSize(aWindowSize), iPosition(aStartingPoint) 
    86     {
    87     iScreenSize = GetDisplaySizeInPixels();
    88     }
    89 
    90 void CTWindow::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent)
    91 	{
    92 	// Create a window with the window group as a parent
    93 	iWindow = RWindow(aWs);
    94 	// it's common to use the address of the owning object as an unique window handle 
    95 	User::LeaveIfError(iWindow.Construct(aParent, reinterpret_cast<TUint32>(this)));
    96 	iWindow.SetPosition(iPosition);
    97 	iWindow.SetSize(iSize);
    98 		
    99 	// Activate window and set it invisible
   100 	iWindow.Activate();
   101 	iWindow.SetVisible(EFalse);	
   102 	}
   103 
   104 CTWindow::~CTWindow()
   105     {
   106     iDirtyRegion.Close();
   107     iWindow.Close();
   108     }
   109 
   110 void CTWindow::LoadL(CSurfaceUtility* /*aUtility*/, TPtrC /*aFileName*/)
   111 	{
   112 	// empty
   113 	}
   114 
   115 void CTWindow::RenderL()
   116 	{	
   117 	iWindow.SetVisible(ETrue);	
   118 	iDirtyRegion.Clear();
   119     iDirtyRegion.AddRect(TRect(TPoint(0, 0), iScreenSize));
   120     iDirtyRegion.ClipRect(TRect(iPosition, iSize));
   121 	}
   122 
   123 void CTWindow::Move(TInt aX, TInt aY)
   124     {
   125     iPosition.iX += aX;
   126     iPosition.iY += aY;
   127     iWindow.SetPosition(iPosition);
   128     }
   129 
   130 TPoint CTWindow::CurrentPosition()
   131     {
   132     return iPosition;
   133     }
   134 
   135 void CTWindow::SetPosition(TInt aX, TInt aY)
   136     {
   137     iPosition.SetXY(aX, aY);
   138     }
   139 
   140 void CTWindow::SetVisible(TBool aIsVisible)
   141     {
   142     iWindow.SetVisible(aIsVisible);
   143     }
   144 
   145 const RRegion& CTWindow::DirtyRegion() const
   146     {
   147     return iDirtyRegion;
   148     }
   149 
   150 TInt CTWindow::SetBackgroundSurface(const TSurfaceId& aSurface)
   151     {
   152     return iWindow.SetBackgroundSurface(aSurface);
   153     }
   154 
   155 TSize CTWindow::Size()
   156     {
   157     return iWindow.Size();
   158     }