sl@0: // Copyright (c) 2007-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
sl@0: */
sl@0: 
sl@0: #include <e32debug.h>
sl@0: #include <w32std.h>
sl@0: #include <iniparser.h>
sl@0: 
sl@0: #include "t_pseudoapppopupwindow.h"
sl@0: #include "t_pseudoapputils.h"
sl@0: #include "t_winutils.h"			//CTestBitmap
sl@0: 
sl@0: GLDEF_C TInt E32Main()
sl@0: 	{
sl@0: 	RDebug::Print(_L("T_PseudoAppPopupWindow::E32Main - entry"));
sl@0: 
sl@0: //	__UHEAP_MARK; // mark heap state
sl@0: 
sl@0: 	CTrapCleanup* TheTrapCleanup = CTrapCleanup::New();
sl@0: 
sl@0: 	TRAPD(err, DisplayPopupWindowL());
sl@0: 	if (err)
sl@0: 		{
sl@0: 		User::Panic(KTPopupWindowAppPanic,err);
sl@0: 		}
sl@0: 
sl@0:     delete TheTrapCleanup;
sl@0: 
sl@0: //	__UHEAP_MARKEND; // check no memory leak
sl@0: 
sl@0: 	User::After(20000000);
sl@0: 	RDebug::Print(_L("T_PseudoAppPopupWindow::E32Main - exit"));
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: LOCAL_C void DisplayPopupWindowL()
sl@0: 	{
sl@0: 	TPtrC multiBitmapPopupFile;
sl@0: 	TSize windowSize;
sl@0: 	TPoint windowPosition;
sl@0: 	TInt transparency;
sl@0: 	TInt screenNo;
sl@0: 	TDisplayMode aMode;
sl@0: 
sl@0: 	//Create CIniData class for reading in values form ini files
sl@0: 	CIniData* utils = CIniData::NewL(KWServPseudoAppConfigFile);
sl@0: 	CleanupStack::PushL(utils);
sl@0: 
sl@0: 	ReadPopupConfig(windowSize, windowPosition, multiBitmapPopupFile, transparency, screenNo, aMode, utils);
sl@0: 
sl@0: 	RDebug::Print(_L("Create Window server session"));
sl@0: 	RWsSession session;
sl@0: 	User::LeaveIfError(session.Connect());
sl@0: 
sl@0: 	RDebug::Print(_L("Create CWsScreenDevice\n"));
sl@0: 	CWsScreenDevice screenDevice(session);
sl@0: 	User::LeaveIfError(screenDevice.Construct(screenNo));
sl@0: 
sl@0: 	RDebug::Print(_L("Create RWindowGroup\n"));
sl@0: 	RWindowGroup group(session);
sl@0: 	User::LeaveIfError(group.Construct(8970+screenNo,ETrue));
sl@0: 
sl@0: 	RDebug::Print(_L("Create Window\n"));
sl@0: 	RWindow window(session);
sl@0: 	User::LeaveIfError(window.Construct((RWindowTreeNode)group,(TUint32)&window));
sl@0: 
sl@0: 	DeterminePixelValues(windowSize, windowPosition, screenDevice);
sl@0: 
sl@0: 	window.SetExtent(windowPosition, windowSize);
sl@0: 
sl@0: 	TInt ret = window.SetRequiredDisplayMode(aMode);
sl@0: 
sl@0: 	RDebug::Print(_L("Window display mode set to %d\n"), ret);
sl@0: 
sl@0: 	RDebug::Print(_L("Create CWindowGc\n"));
sl@0: 	CWindowGc windowGc(&screenDevice);
sl@0: 	User::LeaveIfError(windowGc.Construct());
sl@0: 
sl@0: 	//Make the window transparent
sl@0: 	CTestBitmap* bitmap = CTestBitmap::NewL(windowSize, EGray256);
sl@0: 	CleanupStack::PushL(bitmap);
sl@0: 
sl@0: 	bitmap->Gc().SetBrushColor(TRgb::Gray256(128));
sl@0: 	bitmap->Gc().SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0: 	bitmap->Gc().SetPenStyle(CGraphicsContext::ENullPen);
sl@0: 	bitmap->Gc().DrawRect(windowSize);
sl@0: 
sl@0: 	window.SetTransparencyBitmap(bitmap->Bitmap());
sl@0: 	window.SetVisible(ETrue);
sl@0: 	window.Activate();
sl@0: 
sl@0: 	windowGc.Activate(window);
sl@0: 	window.Invalidate();
sl@0: 	window.BeginRedraw();
sl@0: 
sl@0: 	//Load popup bitmap
sl@0: 	CTestBitmap* bitmapSource = CTestBitmap::NewL(windowSize, aMode);
sl@0: 	CleanupStack::PushL(bitmapSource);
sl@0: 
sl@0: 	User::LeaveIfError(bitmapSource->Bitmap().Load(multiBitmapPopupFile, 0));
sl@0: 
sl@0: 	if(transparency)
sl@0: 		{
sl@0: 		CTestBitmap* bitmapSourceAlpha;
sl@0: 		CTestBitmap* bitmapDest;
sl@0: 		CTestBitmap* bitmapDestAlpha;
sl@0: 
sl@0: 		bitmapSourceAlpha = CTestBitmap::NewL(windowSize, EGray256);
sl@0: 		CleanupStack::PushL(bitmapSourceAlpha);
sl@0: 
sl@0: 		User::LeaveIfError(bitmapSourceAlpha->Bitmap().Load(multiBitmapPopupFile, 1));
sl@0: 
sl@0: 		bitmapDest = CTestBitmap::NewL(windowSize, aMode);
sl@0: 		CleanupStack::PushL(bitmapDest);
sl@0: 
sl@0: 		bitmapDest->Bitmap().SetSizeInTwips(bitmapSource->Bitmap().SizeInTwips());
sl@0: 		bitmapDest->Gc().DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSource->Bitmap()));
sl@0: 
sl@0: 		bitmapDestAlpha = CTestBitmap::NewL(windowSize, EGray256);
sl@0: 		CleanupStack::PushL(bitmapDestAlpha);
sl@0: 
sl@0: 		bitmapDestAlpha->Bitmap().SetSizeInTwips(bitmapSourceAlpha->Bitmap().SizeInTwips());
sl@0: 		bitmapDestAlpha->Gc().DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSourceAlpha->Bitmap()));
sl@0: 
sl@0: 		TInt ret = windowGc.AlphaBlendBitmaps(TPoint(0,0), &(bitmapDest->Bitmap()), TRect(TPoint(0,0), windowSize), &(bitmapDestAlpha->Bitmap()), TPoint(0,0));
sl@0: 
sl@0: 		if(ret != KErrNone)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Transparent popup window drawing error\n"));
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			RDebug::Print(_L("Transparent popup window drawn correctly\n"));
sl@0: 			}
sl@0: 
sl@0: 		CleanupStack::PopAndDestroy(3); //bitmapSourceAlpha, bitmapDest, bitmapDestAlpha
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		//Make window opaque
sl@0: 		window.SetTransparencyFactor(TRgb(0xFFFFFFFF));
sl@0: 		windowGc.DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSource->Bitmap()));
sl@0: 		}
sl@0: 
sl@0: 	window.EndRedraw();
sl@0: 	session.Flush();
sl@0: 	windowGc.Deactivate();
sl@0: 	User::After(100000);
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(3);	//utils, bitmap, bitmapSource
sl@0: 	}
sl@0: 
sl@0: LOCAL_C void ReadPopupConfig(TSize& aWindowSize, TPoint& aWindowPosition, TPtrC& aBitmapFile, TInt& aTransparency,
sl@0:                              TInt& aScreenNo, TDisplayMode& aMode, CIniData* aUtils)
sl@0: 	{
sl@0: 	TInt maxNumberOfScreens;
sl@0: 	TPtrC windowSize;
sl@0: 	TPtrC windowPosition;
sl@0: 	TInt popupOccurances;
sl@0: 
sl@0: 	TBuf<KMaxUiBitmapNameLength>	tempStore;
sl@0: 	TInt i;
sl@0: 
sl@0: 	READ_INI1(max_number_of_screens, maxNumberOfScreens, aUtils);
sl@0: 
sl@0: 	for(i=0; i<maxNumberOfScreens; i++)
sl@0: 		{
sl@0: 		TBuf<KMaxUiBitmapNameLength>	tempStore;
sl@0: 
sl@0: 		tempStore.Format(KScreenWindowPopup, i);
sl@0: 		READ_INI1A(tempStore, occurances, popupOccurances, aUtils);
sl@0: 
sl@0: 		tempStore.Format(KScreenWindowPopup, i);
sl@0: 
sl@0: 		if(popupOccurances)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Popup window enabled for screen %d"), i);
sl@0: 			aScreenNo = i;
sl@0: 			TInt screenMode;
sl@0: 
sl@0: 			READ_INI1A(tempStore, multi_bitmap_popup_file, aBitmapFile, aUtils);
sl@0: 
sl@0: 			READ_INI1A(tempStore, window_size, windowSize, aUtils);
sl@0: 			TImportScreenConfig::ExtractSize(windowSize, aWindowSize);
sl@0: 
sl@0: 			READ_INI1A(tempStore, window_position, windowPosition, aUtils);
sl@0: 			TImportScreenConfig::ExtractPoint(windowPosition, aWindowPosition);
sl@0: 
sl@0: 			READ_INI2A(tempStore, transparency,   True, False, aTransparency,  ETrue, EFalse, aUtils);
sl@0: 			READ_INI2(screen_mode, EColor16MA, EColor64K, screenMode, EColor16MA, EColor64K, aUtils);
sl@0: 
sl@0: 			aMode = static_cast<TDisplayMode>(screenMode);
sl@0: 
sl@0: 			//The popup is enabled for one screen per instance of the exe
sl@0: 			return;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			RDebug::Print(_L("No popup window enabled for screen %d"), i);
sl@0: 			}
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: 
sl@0: LOCAL_C void DeterminePixelValues(TSize& aWindowSize, TPoint& aWindowPosition, 	CWsScreenDevice& aScreenDevice)
sl@0: 	{
sl@0: 	TSize screenSize = aScreenDevice.SizeInPixels();
sl@0: 
sl@0: 	//Convert surface size percentages to pixel sizes
sl@0: 	if(aWindowSize.iWidth <= 0)
sl@0: 		{
sl@0: 		RDebug::Print(_L("popup_width is zero or less, quitting\n"));
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		aWindowSize.iWidth = (aWindowSize.iWidth * screenSize.iWidth)/100;
sl@0: 		}
sl@0: 
sl@0: 	if(aWindowSize.iHeight <= 0)
sl@0: 		{
sl@0: 		RDebug::Print(_L("popup_height is zero or less, quitting\n"));
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		aWindowSize.iHeight = (aWindowSize.iHeight * screenSize.iHeight)/100;
sl@0: 		}
sl@0: 
sl@0: 	//Convert surface position percentages to pixel sizes
sl@0: 	aWindowPosition.iX = (aWindowPosition.iX * screenSize.iWidth)/100;
sl@0: 	aWindowPosition.iY = (aWindowPosition.iY * screenSize.iHeight)/100;
sl@0: 	}