1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoapppopupwindow.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,250 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include <e32debug.h>
1.26 +#include <w32std.h>
1.27 +#include <iniparser.h>
1.28 +
1.29 +#include "t_pseudoapppopupwindow.h"
1.30 +#include "t_pseudoapputils.h"
1.31 +#include "t_winutils.h" //CTestBitmap
1.32 +
1.33 +GLDEF_C TInt E32Main()
1.34 + {
1.35 + RDebug::Print(_L("T_PseudoAppPopupWindow::E32Main - entry"));
1.36 +
1.37 +// __UHEAP_MARK; // mark heap state
1.38 +
1.39 + CTrapCleanup* TheTrapCleanup = CTrapCleanup::New();
1.40 +
1.41 + TRAPD(err, DisplayPopupWindowL());
1.42 + if (err)
1.43 + {
1.44 + User::Panic(KTPopupWindowAppPanic,err);
1.45 + }
1.46 +
1.47 + delete TheTrapCleanup;
1.48 +
1.49 +// __UHEAP_MARKEND; // check no memory leak
1.50 +
1.51 + User::After(20000000);
1.52 + RDebug::Print(_L("T_PseudoAppPopupWindow::E32Main - exit"));
1.53 + return KErrNone;
1.54 + }
1.55 +
1.56 +LOCAL_C void DisplayPopupWindowL()
1.57 + {
1.58 + TPtrC multiBitmapPopupFile;
1.59 + TSize windowSize;
1.60 + TPoint windowPosition;
1.61 + TInt transparency;
1.62 + TInt screenNo;
1.63 + TDisplayMode aMode;
1.64 +
1.65 + //Create CIniData class for reading in values form ini files
1.66 + CIniData* utils = CIniData::NewL(KWServPseudoAppConfigFile);
1.67 + CleanupStack::PushL(utils);
1.68 +
1.69 + ReadPopupConfig(windowSize, windowPosition, multiBitmapPopupFile, transparency, screenNo, aMode, utils);
1.70 +
1.71 + RDebug::Print(_L("Create Window server session"));
1.72 + RWsSession session;
1.73 + User::LeaveIfError(session.Connect());
1.74 +
1.75 + RDebug::Print(_L("Create CWsScreenDevice\n"));
1.76 + CWsScreenDevice screenDevice(session);
1.77 + User::LeaveIfError(screenDevice.Construct(screenNo));
1.78 +
1.79 + RDebug::Print(_L("Create RWindowGroup\n"));
1.80 + RWindowGroup group(session);
1.81 + User::LeaveIfError(group.Construct(8970+screenNo,ETrue));
1.82 +
1.83 + RDebug::Print(_L("Create Window\n"));
1.84 + RWindow window(session);
1.85 + User::LeaveIfError(window.Construct((RWindowTreeNode)group,(TUint32)&window));
1.86 +
1.87 + DeterminePixelValues(windowSize, windowPosition, screenDevice);
1.88 +
1.89 + window.SetExtent(windowPosition, windowSize);
1.90 +
1.91 + TInt ret = window.SetRequiredDisplayMode(aMode);
1.92 +
1.93 + RDebug::Print(_L("Window display mode set to %d\n"), ret);
1.94 +
1.95 + RDebug::Print(_L("Create CWindowGc\n"));
1.96 + CWindowGc windowGc(&screenDevice);
1.97 + User::LeaveIfError(windowGc.Construct());
1.98 +
1.99 + //Make the window transparent
1.100 + CTestBitmap* bitmap = CTestBitmap::NewL(windowSize, EGray256);
1.101 + CleanupStack::PushL(bitmap);
1.102 +
1.103 + bitmap->Gc().SetBrushColor(TRgb::Gray256(128));
1.104 + bitmap->Gc().SetBrushStyle(CGraphicsContext::ESolidBrush);
1.105 + bitmap->Gc().SetPenStyle(CGraphicsContext::ENullPen);
1.106 + bitmap->Gc().DrawRect(windowSize);
1.107 +
1.108 + window.SetTransparencyBitmap(bitmap->Bitmap());
1.109 + window.SetVisible(ETrue);
1.110 + window.Activate();
1.111 +
1.112 + windowGc.Activate(window);
1.113 + window.Invalidate();
1.114 + window.BeginRedraw();
1.115 +
1.116 + //Load popup bitmap
1.117 + CTestBitmap* bitmapSource = CTestBitmap::NewL(windowSize, aMode);
1.118 + CleanupStack::PushL(bitmapSource);
1.119 +
1.120 + User::LeaveIfError(bitmapSource->Bitmap().Load(multiBitmapPopupFile, 0));
1.121 +
1.122 + if(transparency)
1.123 + {
1.124 + CTestBitmap* bitmapSourceAlpha;
1.125 + CTestBitmap* bitmapDest;
1.126 + CTestBitmap* bitmapDestAlpha;
1.127 +
1.128 + bitmapSourceAlpha = CTestBitmap::NewL(windowSize, EGray256);
1.129 + CleanupStack::PushL(bitmapSourceAlpha);
1.130 +
1.131 + User::LeaveIfError(bitmapSourceAlpha->Bitmap().Load(multiBitmapPopupFile, 1));
1.132 +
1.133 + bitmapDest = CTestBitmap::NewL(windowSize, aMode);
1.134 + CleanupStack::PushL(bitmapDest);
1.135 +
1.136 + bitmapDest->Bitmap().SetSizeInTwips(bitmapSource->Bitmap().SizeInTwips());
1.137 + bitmapDest->Gc().DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSource->Bitmap()));
1.138 +
1.139 + bitmapDestAlpha = CTestBitmap::NewL(windowSize, EGray256);
1.140 + CleanupStack::PushL(bitmapDestAlpha);
1.141 +
1.142 + bitmapDestAlpha->Bitmap().SetSizeInTwips(bitmapSourceAlpha->Bitmap().SizeInTwips());
1.143 + bitmapDestAlpha->Gc().DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSourceAlpha->Bitmap()));
1.144 +
1.145 + TInt ret = windowGc.AlphaBlendBitmaps(TPoint(0,0), &(bitmapDest->Bitmap()), TRect(TPoint(0,0), windowSize), &(bitmapDestAlpha->Bitmap()), TPoint(0,0));
1.146 +
1.147 + if(ret != KErrNone)
1.148 + {
1.149 + RDebug::Print(_L("Transparent popup window drawing error\n"));
1.150 + }
1.151 + else
1.152 + {
1.153 + RDebug::Print(_L("Transparent popup window drawn correctly\n"));
1.154 + }
1.155 +
1.156 + CleanupStack::PopAndDestroy(3); //bitmapSourceAlpha, bitmapDest, bitmapDestAlpha
1.157 + }
1.158 + else
1.159 + {
1.160 + //Make window opaque
1.161 + window.SetTransparencyFactor(TRgb(0xFFFFFFFF));
1.162 + windowGc.DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSource->Bitmap()));
1.163 + }
1.164 +
1.165 + window.EndRedraw();
1.166 + session.Flush();
1.167 + windowGc.Deactivate();
1.168 + User::After(100000);
1.169 +
1.170 + CleanupStack::PopAndDestroy(3); //utils, bitmap, bitmapSource
1.171 + }
1.172 +
1.173 +LOCAL_C void ReadPopupConfig(TSize& aWindowSize, TPoint& aWindowPosition, TPtrC& aBitmapFile, TInt& aTransparency,
1.174 + TInt& aScreenNo, TDisplayMode& aMode, CIniData* aUtils)
1.175 + {
1.176 + TInt maxNumberOfScreens;
1.177 + TPtrC windowSize;
1.178 + TPtrC windowPosition;
1.179 + TInt popupOccurances;
1.180 +
1.181 + TBuf<KMaxUiBitmapNameLength> tempStore;
1.182 + TInt i;
1.183 +
1.184 + READ_INI1(max_number_of_screens, maxNumberOfScreens, aUtils);
1.185 +
1.186 + for(i=0; i<maxNumberOfScreens; i++)
1.187 + {
1.188 + TBuf<KMaxUiBitmapNameLength> tempStore;
1.189 +
1.190 + tempStore.Format(KScreenWindowPopup, i);
1.191 + READ_INI1A(tempStore, occurances, popupOccurances, aUtils);
1.192 +
1.193 + tempStore.Format(KScreenWindowPopup, i);
1.194 +
1.195 + if(popupOccurances)
1.196 + {
1.197 + RDebug::Print(_L("Popup window enabled for screen %d"), i);
1.198 + aScreenNo = i;
1.199 + TInt screenMode;
1.200 +
1.201 + READ_INI1A(tempStore, multi_bitmap_popup_file, aBitmapFile, aUtils);
1.202 +
1.203 + READ_INI1A(tempStore, window_size, windowSize, aUtils);
1.204 + TImportScreenConfig::ExtractSize(windowSize, aWindowSize);
1.205 +
1.206 + READ_INI1A(tempStore, window_position, windowPosition, aUtils);
1.207 + TImportScreenConfig::ExtractPoint(windowPosition, aWindowPosition);
1.208 +
1.209 + READ_INI2A(tempStore, transparency, True, False, aTransparency, ETrue, EFalse, aUtils);
1.210 + READ_INI2(screen_mode, EColor16MA, EColor64K, screenMode, EColor16MA, EColor64K, aUtils);
1.211 +
1.212 + aMode = static_cast<TDisplayMode>(screenMode);
1.213 +
1.214 + //The popup is enabled for one screen per instance of the exe
1.215 + return;
1.216 + }
1.217 + else
1.218 + {
1.219 + RDebug::Print(_L("No popup window enabled for screen %d"), i);
1.220 + }
1.221 + }
1.222 + }
1.223 +
1.224 +
1.225 +LOCAL_C void DeterminePixelValues(TSize& aWindowSize, TPoint& aWindowPosition, CWsScreenDevice& aScreenDevice)
1.226 + {
1.227 + TSize screenSize = aScreenDevice.SizeInPixels();
1.228 +
1.229 + //Convert surface size percentages to pixel sizes
1.230 + if(aWindowSize.iWidth <= 0)
1.231 + {
1.232 + RDebug::Print(_L("popup_width is zero or less, quitting\n"));
1.233 + User::Exit(0);
1.234 + }
1.235 + else
1.236 + {
1.237 + aWindowSize.iWidth = (aWindowSize.iWidth * screenSize.iWidth)/100;
1.238 + }
1.239 +
1.240 + if(aWindowSize.iHeight <= 0)
1.241 + {
1.242 + RDebug::Print(_L("popup_height is zero or less, quitting\n"));
1.243 + User::Exit(0);
1.244 + }
1.245 + else
1.246 + {
1.247 + aWindowSize.iHeight = (aWindowSize.iHeight * screenSize.iHeight)/100;
1.248 + }
1.249 +
1.250 + //Convert surface position percentages to pixel sizes
1.251 + aWindowPosition.iX = (aWindowPosition.iX * screenSize.iWidth)/100;
1.252 + aWindowPosition.iY = (aWindowPosition.iY * screenSize.iHeight)/100;
1.253 + }