Update contrib.
     1 // Copyright (c) 2007-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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    24 #include <iniparser.h>
 
    26 #include "t_pseudoapppopupwindow.h"
 
    27 #include "t_pseudoapputils.h"
 
    28 #include "t_winutils.h"			//CTestBitmap
 
    30 GLDEF_C TInt E32Main()
 
    32 	RDebug::Print(_L("T_PseudoAppPopupWindow::E32Main - entry"));
 
    34 //	__UHEAP_MARK; // mark heap state
 
    36 	CTrapCleanup* TheTrapCleanup = CTrapCleanup::New();
 
    38 	TRAPD(err, DisplayPopupWindowL());
 
    41 		User::Panic(KTPopupWindowAppPanic,err);
 
    44     delete TheTrapCleanup;
 
    46 //	__UHEAP_MARKEND; // check no memory leak
 
    48 	User::After(20000000);
 
    49 	RDebug::Print(_L("T_PseudoAppPopupWindow::E32Main - exit"));
 
    53 LOCAL_C void DisplayPopupWindowL()
 
    55 	TPtrC multiBitmapPopupFile;
 
    57 	TPoint windowPosition;
 
    62 	//Create CIniData class for reading in values form ini files
 
    63 	CIniData* utils = CIniData::NewL(KWServPseudoAppConfigFile);
 
    64 	CleanupStack::PushL(utils);
 
    66 	ReadPopupConfig(windowSize, windowPosition, multiBitmapPopupFile, transparency, screenNo, aMode, utils);
 
    68 	RDebug::Print(_L("Create Window server session"));
 
    70 	User::LeaveIfError(session.Connect());
 
    72 	RDebug::Print(_L("Create CWsScreenDevice\n"));
 
    73 	CWsScreenDevice screenDevice(session);
 
    74 	User::LeaveIfError(screenDevice.Construct(screenNo));
 
    76 	RDebug::Print(_L("Create RWindowGroup\n"));
 
    77 	RWindowGroup group(session);
 
    78 	User::LeaveIfError(group.Construct(8970+screenNo,ETrue));
 
    80 	RDebug::Print(_L("Create Window\n"));
 
    81 	RWindow window(session);
 
    82 	User::LeaveIfError(window.Construct((RWindowTreeNode)group,(TUint32)&window));
 
    84 	DeterminePixelValues(windowSize, windowPosition, screenDevice);
 
    86 	window.SetExtent(windowPosition, windowSize);
 
    88 	TInt ret = window.SetRequiredDisplayMode(aMode);
 
    90 	RDebug::Print(_L("Window display mode set to %d\n"), ret);
 
    92 	RDebug::Print(_L("Create CWindowGc\n"));
 
    93 	CWindowGc windowGc(&screenDevice);
 
    94 	User::LeaveIfError(windowGc.Construct());
 
    96 	//Make the window transparent
 
    97 	CTestBitmap* bitmap = CTestBitmap::NewL(windowSize, EGray256);
 
    98 	CleanupStack::PushL(bitmap);
 
   100 	bitmap->Gc().SetBrushColor(TRgb::Gray256(128));
 
   101 	bitmap->Gc().SetBrushStyle(CGraphicsContext::ESolidBrush);
 
   102 	bitmap->Gc().SetPenStyle(CGraphicsContext::ENullPen);
 
   103 	bitmap->Gc().DrawRect(windowSize);
 
   105 	window.SetTransparencyBitmap(bitmap->Bitmap());
 
   106 	window.SetVisible(ETrue);
 
   109 	windowGc.Activate(window);
 
   111 	window.BeginRedraw();
 
   114 	CTestBitmap* bitmapSource = CTestBitmap::NewL(windowSize, aMode);
 
   115 	CleanupStack::PushL(bitmapSource);
 
   117 	User::LeaveIfError(bitmapSource->Bitmap().Load(multiBitmapPopupFile, 0));
 
   121 		CTestBitmap* bitmapSourceAlpha;
 
   122 		CTestBitmap* bitmapDest;
 
   123 		CTestBitmap* bitmapDestAlpha;
 
   125 		bitmapSourceAlpha = CTestBitmap::NewL(windowSize, EGray256);
 
   126 		CleanupStack::PushL(bitmapSourceAlpha);
 
   128 		User::LeaveIfError(bitmapSourceAlpha->Bitmap().Load(multiBitmapPopupFile, 1));
 
   130 		bitmapDest = CTestBitmap::NewL(windowSize, aMode);
 
   131 		CleanupStack::PushL(bitmapDest);
 
   133 		bitmapDest->Bitmap().SetSizeInTwips(bitmapSource->Bitmap().SizeInTwips());
 
   134 		bitmapDest->Gc().DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSource->Bitmap()));
 
   136 		bitmapDestAlpha = CTestBitmap::NewL(windowSize, EGray256);
 
   137 		CleanupStack::PushL(bitmapDestAlpha);
 
   139 		bitmapDestAlpha->Bitmap().SetSizeInTwips(bitmapSourceAlpha->Bitmap().SizeInTwips());
 
   140 		bitmapDestAlpha->Gc().DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSourceAlpha->Bitmap()));
 
   142 		TInt ret = windowGc.AlphaBlendBitmaps(TPoint(0,0), &(bitmapDest->Bitmap()), TRect(TPoint(0,0), windowSize), &(bitmapDestAlpha->Bitmap()), TPoint(0,0));
 
   146 			RDebug::Print(_L("Transparent popup window drawing error\n"));
 
   150 			RDebug::Print(_L("Transparent popup window drawn correctly\n"));
 
   153 		CleanupStack::PopAndDestroy(3); //bitmapSourceAlpha, bitmapDest, bitmapDestAlpha
 
   158 		window.SetTransparencyFactor(TRgb(0xFFFFFFFF));
 
   159 		windowGc.DrawBitmap(TRect(TPoint(0,0), windowSize), &(bitmapSource->Bitmap()));
 
   164 	windowGc.Deactivate();
 
   167 	CleanupStack::PopAndDestroy(3);	//utils, bitmap, bitmapSource
 
   170 LOCAL_C void ReadPopupConfig(TSize& aWindowSize, TPoint& aWindowPosition, TPtrC& aBitmapFile, TInt& aTransparency,
 
   171                              TInt& aScreenNo, TDisplayMode& aMode, CIniData* aUtils)
 
   173 	TInt maxNumberOfScreens;
 
   175 	TPtrC windowPosition;
 
   176 	TInt popupOccurances;
 
   178 	TBuf<KMaxUiBitmapNameLength>	tempStore;
 
   181 	READ_INI1(max_number_of_screens, maxNumberOfScreens, aUtils);
 
   183 	for(i=0; i<maxNumberOfScreens; i++)
 
   185 		TBuf<KMaxUiBitmapNameLength>	tempStore;
 
   187 		tempStore.Format(KScreenWindowPopup, i);
 
   188 		READ_INI1A(tempStore, occurances, popupOccurances, aUtils);
 
   190 		tempStore.Format(KScreenWindowPopup, i);
 
   194 			RDebug::Print(_L("Popup window enabled for screen %d"), i);
 
   198 			READ_INI1A(tempStore, multi_bitmap_popup_file, aBitmapFile, aUtils);
 
   200 			READ_INI1A(tempStore, window_size, windowSize, aUtils);
 
   201 			TImportScreenConfig::ExtractSize(windowSize, aWindowSize);
 
   203 			READ_INI1A(tempStore, window_position, windowPosition, aUtils);
 
   204 			TImportScreenConfig::ExtractPoint(windowPosition, aWindowPosition);
 
   206 			READ_INI2A(tempStore, transparency,   True, False, aTransparency,  ETrue, EFalse, aUtils);
 
   207 			READ_INI2(screen_mode, EColor16MA, EColor64K, screenMode, EColor16MA, EColor64K, aUtils);
 
   209 			aMode = static_cast<TDisplayMode>(screenMode);
 
   211 			//The popup is enabled for one screen per instance of the exe
 
   216 			RDebug::Print(_L("No popup window enabled for screen %d"), i);
 
   222 LOCAL_C void DeterminePixelValues(TSize& aWindowSize, TPoint& aWindowPosition, 	CWsScreenDevice& aScreenDevice)
 
   224 	TSize screenSize = aScreenDevice.SizeInPixels();
 
   226 	//Convert surface size percentages to pixel sizes
 
   227 	if(aWindowSize.iWidth <= 0)
 
   229 		RDebug::Print(_L("popup_width is zero or less, quitting\n"));
 
   234 		aWindowSize.iWidth = (aWindowSize.iWidth * screenSize.iWidth)/100;
 
   237 	if(aWindowSize.iHeight <= 0)
 
   239 		RDebug::Print(_L("popup_height is zero or less, quitting\n"));
 
   244 		aWindowSize.iHeight = (aWindowSize.iHeight * screenSize.iHeight)/100;
 
   247 	//Convert surface position percentages to pixel sizes
 
   248 	aWindowPosition.iX = (aWindowPosition.iX * screenSize.iWidth)/100;
 
   249 	aWindowPosition.iY = (aWindowPosition.iY * screenSize.iHeight)/100;