lafagnosticuifoundation/cone/tef/TConeInvalidate.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2005-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 // Off-screen bitmap Gc test to observe correct redraw behaviour with respect to sub-rect invalidation and redraw capability
       
    15 // makes use of the introduced CCoeControl::DrawNow(TRect &) function and CWindowGc derivable class.
       
    16 // Test intended for OS v9.1 and onward.
       
    17 // The screen display, from left to right is displayed as follows:
       
    18 // a) The standard control as a sub-divided hierachical component with background
       
    19 // b) Offscreen bitmap #1 overlayed (blended) onto background
       
    20 // c) Offscreen bitmap #2 overlayed (blended) onto background
       
    21 // The original control is set into the offscreen Gcs as a chequer board where "black squares" are drawn to Gc #1 and 
       
    22 // "white squares" are drawn to Gc #2.
       
    23 // Note: During the test a blank rectangle is displayed in the DrawNow(TRect&) position on the original control,
       
    24 // this is the windows server screen invalidate and cannot be overridden by test code. 
       
    25 // Specifically this code performs the following tests:
       
    26 // 1) Rectangle refresh drawing down a hierarchical composition of child controls with varied window ownership properties 
       
    27 // (including background redraw). This is to ensure the integrity of the subrect as the draw code passes down through the 
       
    28 // control hierarchy.
       
    29 // 2) Offscreen drawing to multiple Gcs with respect to test 1); the offscreen Gc uses RDrawableWindow::GetDrawRect to 
       
    30 // obtain current window the draw region. See TTransGC.cpp for offscreen bitmap Gc functionality.
       
    31 // 3) The correct drawing of background regions with respect to each window, the behaviour of which is in part specified by 
       
    32 // the Draw client
       
    33 // The chequer pattern will be drawn within the DRAW_SIZE region on the second two controls (offscreen Gc maps). 
       
    34 // Note: the second half of the tests will show "black" square regions because each square is a true window owner.
       
    35 // 
       
    36 //
       
    37 
       
    38 /**
       
    39  @file
       
    40  @internalComponent - Internal Symbian test code 
       
    41  @SYMTestCaseID App-Framework/Cone/TConeInvalidate
       
    42  @SYMPREQ 915
       
    43  @SYMTestCaseDesc
       
    44  @SYMTestPriority Medium
       
    45  @SYMTestStatus Implemented
       
    46  @SYMTestActions 
       
    47  @SYMTestExpectedResults
       
    48 */
       
    49 
       
    50 #include <coeaui.h>
       
    51 #include <coemain.h>
       
    52 #include <coedef.h>
       
    53 #include <coesndpy.h>
       
    54 #include <basched.h>
       
    55 #include <bassnd.h>
       
    56 #include <coeccntx.h>
       
    57 #include <ecom/ecom.h>
       
    58 #include "TConeInvalidate.h"
       
    59 #include "TTransGc.h"
       
    60 
       
    61 //Variable to offset animation start frames
       
    62 #define KNumAnimFrames 32
       
    63 #define KNumTestSteps  16
       
    64 #define KAlphaOpaque   255
       
    65 TInt g_FrameStart = 0;
       
    66 
       
    67 //Every background will use the same image
       
    68 CFbsBitmap* CTestRectGc::iBmpBackground = 0;
       
    69 
       
    70 /** The COffScreenBitmapGc class handles all variables and functions to maintain an offscreen bitmap for drawing
       
    71     in 16M alpha mode. */
       
    72 COffScreenBitmapGc::COffScreenBitmapGc()
       
    73 	{
       
    74 		
       
    75 	}
       
    76 
       
    77 COffScreenBitmapGc::~COffScreenBitmapGc()
       
    78 	{
       
    79     delete iGraphContext;
       
    80     delete iMainFbsBitGc;    
       
    81     delete iBitmapDevice2;
       
    82     delete iBitmapView;	
       
    83 	}
       
    84 
       
    85 COffScreenBitmapGc* COffScreenBitmapGc::NewL(const TSize &aSize)
       
    86 	{
       
    87 	COffScreenBitmapGc *pGC;
       
    88 	
       
    89 	pGC = new (ELeave) COffScreenBitmapGc();
       
    90 	
       
    91 	const CCoeEnv* env = CCoeEnv::Static();
       
    92 
       
    93 	
       
    94     CWsScreenDevice* screenDevice=env->ScreenDevice();
       
    95     
       
    96     TDisplayMode dispMode = screenDevice->DisplayMode();
       
    97     
       
    98     //Override display mode so that we have an alpha channel in the target bitmap;
       
    99     dispMode = EColor16MA;
       
   100   
       
   101 	//Allocate windows server bitmap
       
   102     pGC->iBitmapView = new (ELeave) CWsBitmap(env->WsSession());
       
   103   
       
   104     User::LeaveIfError(pGC->iBitmapView->Create(aSize, dispMode));
       
   105 	
       
   106 	//Create a device for the bitmap
       
   107 	pGC->iBitmapDevice2 = CFbsBitmapDevice::NewL(pGC->iBitmapView);
       
   108 	
       
   109 	//Graphic Context to draw to 
       
   110 	pGC->iMainFbsBitGc=CFbsBitGc::NewL();	
       
   111 	pGC->iMainFbsBitGc->Activate(pGC->iBitmapDevice2);
       
   112 	    
       
   113 	pGC->iGraphContext = CTransGc::NewL(*screenDevice,*pGC->iMainFbsBitGc);	// takes place of iMainFbsBitGc (not passing ownership of context here !)
       
   114 	
       
   115 	return pGC;
       
   116 	}
       
   117 
       
   118 CTransGc *COffScreenBitmapGc::OffScreenGc()
       
   119 	{
       
   120 	return iGraphContext;
       
   121 	}
       
   122  
       
   123   
       
   124 CWsBitmap *COffScreenBitmapGc::GetBitmap()
       
   125 	{
       
   126 	return iBitmapView;
       
   127 	}
       
   128 
       
   129 //-----------------------------------------------------
       
   130 void CTestRectGc::ConstructL(TPoint aPt, TSize aSize, TRgb aPenColor, TRgb aBrushColor, CGraphicsContext::TBrushStyle aBrushStyle)
       
   131     {    
       
   132     SetPenColor(aPenColor);
       
   133     SetBrushColor(aBrushColor);
       
   134     
       
   135     SetBrushStyle(aBrushStyle);
       
   136     SetDrawType(EDrawRect);
       
   137     SetExtent(aPt, aSize);
       
   138    
       
   139    	iFrameNo = g_FrameStart+=5; //Offset frame start for next control
       
   140    	g_FrameStart %= KNumAnimFrames;			
       
   141    }
       
   142 
       
   143 
       
   144 
       
   145 CTestRectGc::~CTestRectGc()
       
   146     {
       
   147     }
       
   148 
       
   149 
       
   150 //Basic colour setting functions
       
   151 void CTestRectGc::SetPenColor(const TRgb &aPenColor)
       
   152     {
       
   153     	iPenColor = aPenColor;
       
   154     }
       
   155 void CTestRectGc::SetBrushColor(const TRgb &aBrushColor)
       
   156     {
       
   157     	iBrushColor = aBrushColor;
       
   158     }
       
   159 void CTestRectGc::SetBrushStyle(const CGraphicsContext::TBrushStyle aBrushStyle)
       
   160     {
       
   161     	iBrushStyle = aBrushStyle;
       
   162     }
       
   163 void CTestRectGc::SetDrawType(const TDrawType DrawType)
       
   164     {
       
   165     	iDrawType = DrawType;
       
   166     }
       
   167 void CTestRectGc::NextFrame() 
       
   168 	{		
       
   169 		iFrameNo = (iFrameNo+1) & 0x1f; 				
       
   170 	}
       
   171 		
       
   172 //Main control drawing function		
       
   173 void CTestRectGc::Draw(const TRect& aRect) const
       
   174     {
       
   175     
       
   176     CWindowGc& gc=SystemGc();
       
   177 
       
   178 	TRect rc = Rect();
       
   179 
       
   180 	gc.SetClippingRect(aRect);	
       
   181     
       
   182 	switch(iDrawType)
       
   183 		{
       
   184 		case EDrawRect:		
       
   185 		
       
   186 		  	gc.SetPenColor(TRgb(0,0,0,KAlphaOpaque));
       
   187 		    gc.SetBrushColor(TRgb(0,0,0,KAlphaOpaque));
       
   188 			gc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
   189 			gc.DrawRect(rc); 			
       
   190 			break;    
       
   191 		
       
   192 		case EDrawEllipse:		
       
   193 			{
       
   194 					
       
   195 			//Frame index is a ping-pong animation 0->15->0
       
   196 			TInt FrameIndex = (iFrameNo&0x10)? 0xf - (iFrameNo & 0xf) : iFrameNo & 0xf;
       
   197 			
       
   198 			//The shade of red is an offset multiple of the frame number (0-NUM_ANIM_FRAMES-1).
       
   199 			TRgb col(0xff&(128+(iFrameNo<<3)), 0, 0);		    	
       
   200 			
       
   201 			//The size of the ellipse ranges from 0->height->0 over the NUM_ANIM_FRAMES period
       
   202 			TInt BoxSize = (FrameIndex * ((rc.Height() << 15) / 0x10)) >> 16;
       
   203 			rc.Shrink(0, BoxSize);
       
   204 
       
   205 		  	gc.SetPenColor(col);
       
   206 		    gc.SetBrushColor(col);
       
   207 			gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   208 			
       
   209 			gc.DrawEllipse(rc);  
       
   210 			break;
       
   211 			}		
       
   212 		default: 			
       
   213 		
       
   214 			break;	//Do nothing, blank but not erased
       
   215 		}
       
   216 
       
   217 	gc.CancelClippingRect();		    			
       
   218 	
       
   219     }
       
   220 
       
   221 
       
   222 //Background drawing function
       
   223 void CTestRectGc::Draw(CWindowGc& aGc, const CCoeControl& aControl, const TRect& aRect) const
       
   224 	{		
       
   225 		if (iBmpBackground) 
       
   226 		{
       
   227 						
       
   228 			TPoint a = PositionRelativeToScreen();
       
   229 			TPoint b = aControl.PositionRelativeToScreen();
       
   230 
       
   231 			//The source rect of the background is the relationship between this control and the control being drawn (child)
       
   232 			//plus the subrect (aRect) to be drawn.
       
   233 			TRect SourceRect(b-a+aRect.iTl, aRect.Size());
       
   234 
       
   235 			aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   236 			aGc.BitBlt(aRect.iTl, iBmpBackground, SourceRect);			
       
   237 			aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   238 		}
       
   239 		else
       
   240 		{
       
   241 			TRect rc;
       
   242 			aGc.SetClippingRect(aRect);
       
   243 			aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   244     		aGc.SetBrushColor(iBrushColor);
       
   245     		aGc.SetBrushStyle(iBrushStyle);
       
   246 			aGc.DrawRect(rc);
       
   247 			aGc.CancelClippingRect();
       
   248 
       
   249 		}		
       
   250 	}
       
   251 		   
       
   252 /** Create a child control.
       
   253     if the LSB of aOwners is true, then this control is window owning.
       
   254     Recursively called aChildren times  */
       
   255 
       
   256 void CComponentControl::CreateChildControlL(TInt aChildren, TInt aOwners, TPoint aPt, TSize aSize, TRgb aPenColor, TRgb aBrushColor, CGraphicsContext::TBrushStyle aBrushStyle)
       
   257 	{
       
   258 	    	CTestRectGc *pControl;
       
   259 	    	
       
   260 	    	if (aChildren)
       
   261 		    	{
       
   262 				pControl = new (ELeave) CComponentControl();
       
   263 		    	}    		
       
   264 	    	else
       
   265 		    	{
       
   266 				pControl = new (ELeave) CTestRectGc();    
       
   267 		    	}
       
   268 		    		    			    				
       
   269 			if (aOwners&1)
       
   270 				{			
       
   271 				pControl->CreateWindowL(this);	
       
   272 				}
       
   273 			else
       
   274 				{
       
   275 				pControl->SetContainerWindowL(*this);
       
   276 				pControl->SetParent(this);	  	
       
   277 				}
       
   278 
       
   279 			if (aChildren)
       
   280 		    	{
       
   281 	    		((CComponentControl*)pControl)->ConstructL(aChildren-1, aOwners, aPt, aSize, KRgbBlack, KRgbRed, CGraphicsContext::ESolidBrush);     		
       
   282 		    	}    		
       
   283 	    	else
       
   284 		    	{
       
   285 				pControl->ConstructL(aPt, aSize, aPenColor, aBrushColor, aBrushStyle);				
       
   286 		    	}
       
   287 	    	
       
   288 	    	Components().AppendLC(pControl);
       
   289 				
       
   290 		  	pControl->SetDrawType(EDrawEllipse);				
       
   291 		  		   			
       
   292 			CleanupStack::Pop(pControl);    					
       
   293 	}
       
   294 
       
   295 /**  Construct a control which is recursively sub-divided into four more windows.
       
   296      If the LSB of aOwners is true, then the parent control (this) is a window owning control
       
   297      Recursively called aChildren times */
       
   298 
       
   299 void CComponentControl::ConstructL(TInt aChildren, TInt aOwners, TPoint aPt, TSize aSize, TRgb aPenColor, TRgb aBrushColor, CGraphicsContext::TBrushStyle aBrushStyle)
       
   300     {
       
   301     	//Construct the base window of the control
       
   302     	CTestRectGc::ConstructL(aPt, aSize, aPenColor, aBrushColor, aBrushStyle);
       
   303     	InitComponentArrayL();
       
   304 
       
   305 		TSize ChildSize(aSize.iWidth/2, aSize.iHeight/2);
       
   306 		
       
   307 		TPoint Offset;
       
   308 		if (aOwners&1)
       
   309 			Offset.SetXY(0,0);
       
   310 		else
       
   311 			Offset = aPt;
       
   312 			
       
   313 		CreateChildControlL(aChildren, aOwners>>1, Offset, ChildSize, aPenColor, aBrushColor, aBrushStyle);
       
   314 		CreateChildControlL(aChildren, aOwners>>1, Offset+TSize(ChildSize.iWidth, 0), ChildSize, aPenColor, aBrushColor, aBrushStyle);
       
   315 		CreateChildControlL(aChildren, aOwners>>1, Offset+TSize(0, ChildSize.iHeight), ChildSize, aPenColor, aBrushColor, aBrushStyle);
       
   316 		CreateChildControlL(aChildren, aOwners>>1, Offset+TSize(ChildSize.iWidth, ChildSize.iHeight), ChildSize, aPenColor, aBrushColor, aBrushStyle);
       
   317 		    		  		  	  		  	  	
       
   318     }
       
   319     
       
   320 //Destroy component controls within this control
       
   321 CComponentControl::~CComponentControl()
       
   322     {
       
   323     	while (CountComponentControls())
       
   324     	{
       
   325     		CCoeControl *pControl;
       
   326     		pControl = ComponentControl(0);    		
       
   327     		Components().Remove(pControl);  
       
   328     		delete pControl;  		
       
   329     	}    	
       
   330     }
       
   331     
       
   332  void CComponentControl::Draw(const TRect& /*aRect*/) const
       
   333 	 {
       
   334 	// 	CTestRectGc::Draw(aRect);
       
   335 	 	return;
       
   336 	 }
       
   337 
       
   338 //Recursively drill down to each control level and step their frame counters.
       
   339 void CComponentControl::AnimateComponents()
       
   340 	{
       
   341 	for (TInt i=0; i<CountComponentControls(); i++)
       
   342 		{
       
   343 			CTestRectGc* pComponent = (CTestRectGc*)ComponentControl(i);
       
   344 			pComponent->NextFrame();	
       
   345 			if (pComponent->CountComponentControls())				
       
   346 				((CComponentControl*)pComponent)->AnimateComponents();
       
   347 		}
       
   348 	}
       
   349 
       
   350 /** Create the compound control, the owner mask defines window ownership for each hierarchical control level
       
   351     (LSB = top level parent window). */
       
   352 void CTestRectBackground::CreateComponentControlL(TInt aNumChildren, TInt aOwnerMask)
       
   353 {
       
   354 	Components().RemoveById(999);
       
   355 	delete iControl;
       
   356 	
       
   357  	iControl = new (ELeave) CComponentControl();
       
   358 	iControl->CreateWindowL(this);
       
   359 	Components().AppendLC(iControl, 999);
       
   360 	  	
       
   361     iControl->ConstructL(aNumChildren, aOwnerMask, TPoint(10,36),TSize(128,128), KRgbBlack, KRgbRed, CGraphicsContext::ESolidBrush);
       
   362 	CleanupStack::Pop(iControl)	;
       
   363   	iControl->SetParent(this);
       
   364   	iControl->ActivateL();  		
       
   365 }
       
   366 	  
       
   367 void CTestRectBackground::ConstructL()
       
   368     {
       
   369     CreateWindowL();    
       
   370 	CTestRectGc::ConstructL(TPoint(20,20),TSize(600,200), KRgbBlack, KRgbYellow, CGraphicsContext::ESolidBrush);
       
   371 	InitComponentArrayL();
       
   372 
       
   373 	//Create a default control
       
   374     CreateComponentControlL(2, 7);
       
   375     	
       
   376 	//Control to display the offscreen bitmap
       
   377     iControlImage = new (ELeave) CTestRectImageGc();
       
   378     iControlImage->CreateWindowL(this);
       
   379     iControlImage->DrawableWindow()->SetRequiredDisplayMode(EColor16MA); 
       
   380     iControlImage->ConstructL(TPoint(200,36),TSize(128,128), KRgbRed, KRgbGreen, CGraphicsContext::ESolidBrush); 
       
   381     iControlImage->ActivateL();
       
   382 
       
   383 	//Second control to display blended overlay
       
   384     iControlImage2 = new (ELeave) CTestRectImageGc();
       
   385     iControlImage2->CreateWindowL(this); 
       
   386     iControlImage2->DrawableWindow()->SetRequiredDisplayMode(EColor16MA); 
       
   387     iControlImage2->ConstructL(TPoint(400,36),TSize(128,128), KRgbRed, KRgbGreen, CGraphicsContext::ESolidBrush); 
       
   388     iControlImage2->ActivateL();
       
   389 
       
   390 	//Create an offscreen bitmap     
       
   391     iOffScreen = COffScreenBitmapGc::NewL(TSize(128,128));	
       
   392 	
       
   393 	//Create a second offscreen bitmap     
       
   394     iOffScreen2 = COffScreenBitmapGc::NewL(TSize(128,128));	
       
   395 	
       
   396 	//Set up the control images to display the two offscreen maps
       
   397 	iControlImage->SetBitmap(iOffScreen->GetBitmap());	
       
   398 	iControlImage2->SetBitmap(iOffScreen2->GetBitmap());	
       
   399     
       
   400     iBmpBackground = new (ELeave) CFbsBitmap();
       
   401     User::LeaveIfError(iBmpBackground->Load(_L("z:\\conetest\\city.mbm")));
       
   402 
       
   403 	//Set up the Gc origin so that the offscreen bitmaps can be tiled in the same way as the screen drawn control
       
   404 	TPoint ControlPos = iControl->PositionRelativeToScreen();
       
   405 	iOffScreen->OffScreenGc()->SetWindowOrigin(ControlPos);
       
   406 	iOffScreen2->OffScreenGc()->SetWindowOrigin(ControlPos);
       
   407 	
       
   408     ActivateL();
       
   409     
       
   410     }
       
   411 
       
   412 	
       
   413 
       
   414 
       
   415 CTestRectBackground::~CTestRectBackground()
       
   416     {
       
   417     Components().RemoveById(999);
       
   418 	delete iControl;
       
   419 
       
   420 	delete iControlImage;
       
   421     delete iControlImage2;
       
   422 
       
   423     delete iBmpBackground;     
       
   424 
       
   425 	delete iOffScreen;
       
   426 	delete iOffScreen2;
       
   427 	
       
   428 	delete iContext;
       
   429     }
       
   430 
       
   431 
       
   432 void CTestRectBackground::Draw(const TRect& aRect) const
       
   433     {	
       
   434     	CTestRectGc::Draw(aRect);    	   
       
   435     }
       
   436 
       
   437 
       
   438 
       
   439 void CTestRectImageGc::Draw(const TRect& aRect) const
       
   440 	{
       
   441 
       
   442     CWindowGc& gc=SystemGc();
       
   443 
       
   444 	TRect rc = Rect();
       
   445 	gc.SetClippingRect(aRect);
       
   446 	if(iBmp)
       
   447 		{
       
   448     	gc.BitBlt(rc.iTl, iBmp);
       
   449 		}		
       
   450 	}
       
   451 	
       
   452 CTConeInvalidateAppUi::CTConeInvalidateAppUi(CTmsTestStep* aStep) :
       
   453 CTestCoeAppUi(aStep)
       
   454 {}
       
   455 
       
   456 CTConeInvalidateAppUi::~CTConeInvalidateAppUi()
       
   457 	{
       
   458 	RemoveFromStack(iViewControl);
       
   459 	delete iViewControl;
       
   460 	}
       
   461 
       
   462 
       
   463 //Standard Implementation	
       
   464 void CTConeInvalidateAppUi::ConstructL()
       
   465 	{
       
   466 	CTestCoeAppUi::ConstructL();
       
   467 	
       
   468     iViewControl=new(ELeave) CTestRectBackground;
       
   469     iViewControl->ConstructL();
       
   470     AddToStackL(iViewControl);
       
   471 	AutoTestManager().StartAutoTest();	
       
   472 	}
       
   473 
       
   474 //Standard Implementation	
       
   475 TKeyResponse CTConeInvalidateAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   476     {
       
   477 	TKeyResponse ret=EKeyWasNotConsumed;
       
   478     if (aType==EEventKey && aKeyEvent.iCode==CTRL('e'))
       
   479 		{
       
   480 		CBaActiveScheduler::Exit();
       
   481 		ret=EKeyWasConsumed;
       
   482 		}
       
   483 	return ret;
       
   484     }
       
   485 
       
   486 
       
   487 void CTConeInvalidateAppUi::RunTestStepL(TInt aStepNum)
       
   488 	{
       
   489 		#define DRAW_SIZE   48
       
   490 		#define DRAW_BORDER 8
       
   491 		#define PARENT_HALF_WIDTH 64
       
   492 		
       
   493 		//Clear the offscreen bitmap to solid black, so that at each iteration we can see what is drawn during that frame.
       
   494 		CTransGc *pOffGc = ((CTransGc*)iViewControl->iOffScreen->OffScreenGc());
       
   495 		pOffGc->SetOrigin(TPoint(0,0));
       
   496 		pOffGc->SetAlphaLevel(KAlphaOpaque);
       
   497 		pOffGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   498 		pOffGc->SetBrushColor(TRgb(0,0,0,0));
       
   499 		pOffGc->Clear();		
       
   500 
       
   501 		//1/4 transparent (or 3/4 opaque).
       
   502 		pOffGc->SetAlphaLevel(192);
       
   503 
       
   504 		//Clear the 2nd offscreen bitmap 
       
   505 		pOffGc = ((CTransGc*)iViewControl->iOffScreen2->OffScreenGc());
       
   506 		pOffGc->SetOrigin(TPoint(0,0));
       
   507 		pOffGc->SetAlphaLevel(KAlphaOpaque);
       
   508 		pOffGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   509 		pOffGc->SetBrushColor(TRgb(0,0,0,0));
       
   510 		pOffGc->Clear();		
       
   511 		//1/4 transparent (or 3/4 opaque).
       
   512 		pOffGc->SetAlphaLevel(192);
       
   513 
       
   514 		TPoint drawOffset;		
       
   515 		
       
   516 		TInt Phase = aStepNum - 1;
       
   517 				
       
   518 		if (Phase<KNumTestSteps)
       
   519 		{			
       
   520 			//Create the control and setup its parameters. The top 2 bits of Phase define window ownership combination for 
       
   521 			//the 2 sub levels of the animated control. 
       
   522 			TInt OwnerMask = (Phase>>2);
       
   523 			//The LSB is set to 1 (the parent which is always window owning). 
       
   524 			iViewControl->CreateComponentControlL(1, OwnerMask<<1|1);
       
   525 			
       
   526 			//Set backgrounds for the original control and the overlayed controls.
       
   527 	    	iViewControl->iControl->SetBackground(iViewControl->iControl);
       
   528 	    	iViewControl->iControlImage->SetBackground(iViewControl->iControlImage);
       
   529 	    	iViewControl->iControlImage2->SetBackground(iViewControl->iControlImage2);
       
   530 
       
   531 			//The lower two bits of Phase define the redraw rectangle position in the sequence (tl, tr, br, bl) and repeats this cycle.		
       
   532 			
       
   533 			TInt Region = Phase & 3;
       
   534 																						
       
   535 			switch (Region)
       
   536 				{
       
   537 				case 0: drawOffset = TPoint(DRAW_BORDER,    			   DRAW_BORDER); 					break;
       
   538 				case 1: drawOffset = TPoint(PARENT_HALF_WIDTH+DRAW_BORDER, DRAW_BORDER);					break;
       
   539 				case 2: drawOffset = TPoint(PARENT_HALF_WIDTH+DRAW_BORDER, PARENT_HALF_WIDTH+DRAW_BORDER);	break;
       
   540 				case 3: drawOffset = TPoint(DRAW_BORDER,    			   PARENT_HALF_WIDTH+DRAW_BORDER);	break;
       
   541 				default : break;
       
   542 				}
       
   543 	
       
   544 	
       
   545 			INFO_PRINTF6(_L("Invalidate rect: Step=%2d, OwnerMask=%1d%1d%1d, Region=%1d"), aStepNum, OwnerMask>>1&1, OwnerMask&1, 1, Region);
       
   546 
       
   547 			//Set up the redraw rectangle for this test run																		
       
   548 			TRect redrawRect(drawOffset, TSize(DRAW_SIZE,DRAW_SIZE));
       
   549 			
       
   550 			//Draw the main control, before we set any special Gcs
       
   551 			iViewControl->iControl->DrawNow();
       
   552 								
       
   553 			//Now set each control to an offscreen Gc in "chequer board fashion"
       
   554 			
       
   555 			for (TInt j=0; j<4; j++)
       
   556 				for (TInt k=0; k<4; k++)
       
   557 				{
       
   558 					CCoeControl *pControl = iViewControl->iControl-> ComponentControl(j)->
       
   559 																   ComponentControl(k);
       
   560 												
       
   561 					if ((k==0)||(k==3)) //is the chequer pattern
       
   562 						pControl->SetGc(iViewControl->iOffScreen->OffScreenGc());
       
   563 					else																												
       
   564 						pControl->SetGc(iViewControl->iOffScreen2->OffScreenGc());														
       
   565 					
       
   566 
       
   567 				}
       
   568 
       
   569 			
       
   570 			//and set the control without a background, for the subrect redraw
       
   571 			iViewControl->iControl->SetBackground(NULL);			
       
   572 																
       
   573 			for (TInt i=0; i<50; i++) //Animation cycle whilst the rectangular region is being updated
       
   574 				{
       
   575 				
       
   576 				//Reset the Gcs' window cache variable, required every redraw cycle so the Gc knows when a clear is required
       
   577 				((CTransGc*)iViewControl->iOffScreen->OffScreenGc())->iWin = NULL;
       
   578 				((CTransGc*)iViewControl->iOffScreen2->OffScreenGc())->iWin = NULL;
       
   579 				
       
   580 				//Animate the controls
       
   581 				iViewControl->iControl->AnimateComponents();		
       
   582 
       
   583 				//Instruct the control the redraw the desired rectangle
       
   584 				iViewControl->iControl->DrawNow(redrawRect);						
       
   585 
       
   586 				//Draw the whole offscreen image so that we can check the correct part of the rectangle was drawn
       
   587 				iViewControl->iControlImage->DrawNow();
       
   588 				
       
   589 				//Draw the offscreen image blended over background.
       
   590 				iViewControl->iControlImage2->DrawNow();
       
   591 				
       
   592 				User::After(TTimeIntervalMicroSeconds32(1000));			
       
   593 				}
       
   594 		}
       
   595 		else
       
   596 		{			
       
   597 			AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
   598 		}										
       
   599 	}
       
   600 
       
   601 //----------
       
   602 void CTConeInvalidateStep::ConstructAppL(CCoeEnv* aCoe)
       
   603 	{ // runs inside a TRAP harness
       
   604 	aCoe->ConstructL();
       
   605 	CTConeInvalidateAppUi* appUi= new (ELeave) CTConeInvalidateAppUi(this);
       
   606 	aCoe->SetAppUi(appUi);
       
   607 	appUi->ConstructL();
       
   608 	}
       
   609 
       
   610 CTConeInvalidateStep::CTConeInvalidateStep()
       
   611 	{
       
   612 	SetTestStepName(KTConeInvalidateStep);
       
   613 	}
       
   614 
       
   615 CTConeInvalidateStep::~CTConeInvalidateStep()
       
   616 	{}
       
   617 
       
   618 
       
   619 TVerdict CTConeInvalidateStep::doTestStepL() // main function called by E32
       
   620 	{
       
   621 	INFO_PRINTF1(_L("Test Started"));
       
   622 	
       
   623 	PreallocateHALBuffer();
       
   624 
       
   625 	__UHEAP_MARK;
       
   626 	SetTestStepID(_L("UIF-Cone-TConeInvalidate"));
       
   627 	CCoeEnv* coe=new(ELeave) CCoeEnv;
       
   628 	TRAPD(err,ConstructAppL(coe));
       
   629 
       
   630 	if (!err)
       
   631 		coe->ExecuteD();
       
   632 	else
       
   633 		{
       
   634 		SetTestStepResult(EFail);
       
   635 		delete coe;
       
   636 		}
       
   637 
       
   638 	REComSession::FinalClose();	
       
   639 
       
   640 	RecordTestResultL();
       
   641 	CloseTMSGraphicsStep();
       
   642 	__UHEAP_MARKEND;
       
   643 
       
   644 	INFO_PRINTF1(_L("Test Finished"));
       
   645 	return TestStepResult();
       
   646 	}