lafagnosticuifoundation/cone/tef/TConeTransition.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 // Test exercises switchable graphics contexts, hit regions for 
       
    15 // pointer events, support in public API for separate drawing of
       
    16 // foreground and background.\n
       
    17 // Test intend for 9.1 and onward.\n
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file 
       
    23  @internalComponent 
       
    24 */
       
    25 #include <coeaui.h>
       
    26 #include <coemain.h>
       
    27 #include <coedef.h>
       
    28 #include <coesndpy.h>
       
    29 #include <basched.h>
       
    30 #include <bassnd.h>
       
    31 #include <ecom/ecom.h>
       
    32 #include "TConeTransition.h"
       
    33 #include <gulgcmap.h>
       
    34 
       
    35 
       
    36 /**
       
    37   Second Phase constructor for CTestControlGc Class.\n
       
    38   Sets the control name,pen colour and brush colour settings.\n
       
    39   Also sets Supress output option is enabled or not.\n
       
    40   Activates the control.\n
       
    41 */
       
    42 void CTestControlGc::ConstructL(TPoint aPt, TSize aSize, TRgb aPenColor, TRgb aBrushColor, const TDesC &aControlName)
       
    43     {
       
    44     iControlName=aControlName;
       
    45     iPenColor = aPenColor;
       
    46     iBrushColor = aBrushColor;
       
    47     iSupressOutput = EFalse;
       
    48     SetExtent(aPt, aSize);
       
    49     
       
    50     ActivateL();
       
    51     }
       
    52 
       
    53 /**
       
    54   Destructor for CTestControlGc Class.\n
       
    55 */
       
    56 CTestControlGc::~CTestControlGc()
       
    57     {
       
    58     }
       
    59 /**
       
    60   This function is called whenever a control gains or loses focus,
       
    61   as a result of a call to SetFocus().\n
       
    62   A typical use of FocusChanged() is to change the appearance of the control to 
       
    63   indicate whether or not it has focus, for example by drawing a focus rectangle around it.\n
       
    64  
       
    65 */
       
    66 void CTestControlGc::FocusChanged(TDrawNow aDrawNow)
       
    67 	{
       
    68     if (aDrawNow)
       
    69         {
       
    70         ActivateGc();
       
    71         DeactivateGc();
       
    72         }
       
    73     }
       
    74 /**
       
    75   Draw Function for the CTestControlGc Class.\n
       
    76   Checks if the drawing to control is supressed.\n
       
    77   If Yes, the function return.\n
       
    78   Else  sets the pen and brush settings and Draws.\n
       
    79 */
       
    80 void CTestControlGc::Draw(const TRect& /*aRect*/) const
       
    81     {
       
    82     if(iSupressOutput)
       
    83     	return;
       
    84     
       
    85     CWindowGc& gc=SystemGc();
       
    86 
       
    87 	TRect rc = Rect();
       
    88 	gc.Clear(rc);
       
    89 	
       
    90     gc.SetPenColor(iPenColor);
       
    91     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
    92     gc.SetBrushColor(iBrushColor);
       
    93     
       
    94     rc.Shrink(1,1);
       
    95     gc.DrawRect(rc);
       
    96     rc.Shrink(1,1);
       
    97     gc.DrawRect(rc);
       
    98 	
       
    99     }
       
   100 /**
       
   101   Handler for pointer events received by the control.\n
       
   102   Gets a pointer to the Application Ui Object.\n
       
   103   Later checks if the events are handled by the expected controls.\n 
       
   104 */
       
   105 void CTestControlGc::HandlePointerEventL(const TPointerEvent& )
       
   106 	{
       
   107 	User::InfoPrint(iControlName);
       
   108 	
       
   109 	CTConeTransitionAppUi* theAppUi = static_cast<CTConeTransitionAppUi*> ((CCoeEnv::Static())->AppUi());
       
   110 	theAppUi->INFO_PRINTF2(_L("HandlePointerEventL, %S"), &iControlName);
       
   111 	theAppUi->TEST(iControlName.Compare(theAppUi->iExpectedControlName) == 0);
       
   112 	theAppUi->iExpectedControlName = _L("");
       
   113 	}
       
   114 
       
   115 
       
   116 /**
       
   117   Destructor for CTestControlGcTriangle Class.\n
       
   118 */
       
   119 CTestControlGcTriangle::~CTestControlGcTriangle()
       
   120 	{
       
   121 	if(iPoints)
       
   122 		{
       
   123 		iPoints->Reset();
       
   124 		delete iPoints;
       
   125 		}
       
   126 	}
       
   127 	
       
   128 /** Construct triangle control.
       
   129 
       
   130 	@param TPoint aPt Left top position of control
       
   131 	@param TSize aSize The size of the control, in pixels.
       
   132 	@param TRgb aPenColor An RGB colour for the pen
       
   133 	@param TRgb An RGB colour for the brush
       
   134 	@param const TDesC &aControlName Control name
       
   135 */
       
   136 void CTestControlGcTriangle::ConstructL(TPoint aPt, TSize aSize, TBool aTop, 
       
   137 			TRgb aPenColor, TRgb aBrushColor, const TDesC &aControlName)
       
   138 	{
       
   139 	CTestControlGc::ConstructL(aPt, aSize, aPenColor, aBrushColor, aControlName);
       
   140 	TRect rc = Rect();
       
   141 	
       
   142 	iPoints = new (ELeave) CArrayFixFlat<TPoint>(3);
       
   143 	if(aTop)
       
   144 		{
       
   145 		iPoints->AppendL(TPoint(rc.iBr.iX, rc.iBr.iY));		
       
   146 		iPoints->AppendL(TPoint(rc.iBr.iX, rc.iTl.iY));		
       
   147 		iPoints->AppendL(TPoint(rc.iTl.iX, rc.iTl.iY));		
       
   148 		}
       
   149 	else
       
   150 		{
       
   151 		iPoints->AppendL(TPoint(rc.iTl.iX, rc.iTl.iY));		
       
   152 		iPoints->AppendL(TPoint(rc.iTl.iX, rc.iBr.iY));		
       
   153 		iPoints->AppendL(TPoint(rc.iBr.iX, rc.iBr.iY));		
       
   154 		}
       
   155 	SetHitTest(this);	
       
   156 	}
       
   157 /**
       
   158   Draw function for the CTestControlGcTriangle Class.\n 
       
   159   Checks if output to the control is supressed.\n
       
   160   If not, obtains a pointer to the Graphics context.\n
       
   161   Sets the pen and brush settings and draws using DrawPolygon.\n
       
   162 */
       
   163 void CTestControlGcTriangle::Draw(const TRect& /*aRect*/) const
       
   164     {
       
   165     if(iSupressOutput)
       
   166     	return;
       
   167    
       
   168     CWindowGc& gc=SystemGc();
       
   169 	TRect rc = Rect();
       
   170 
       
   171     gc.SetPenColor(iPenColor);
       
   172     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   173     gc.SetBrushColor(iBrushColor);
       
   174  	
       
   175  	gc.DrawPolygon(iPoints);
       
   176     }
       
   177 
       
   178 /** Overridden function, defined in MCoeControlHitTest as pure virtual
       
   179 
       
   180 @param const TPoint& aPoint Point coordinate in pixel
       
   181 @param const CCoeControl& aControl reference to a control
       
   182 */    
       
   183 TBool CTestControlGcTriangle::HitRegionContains(const TPoint& aPoint, const CCoeControl& aControl) const
       
   184 	{
       
   185 	TBool theIsInside = IsInside(aPoint);
       
   186 	CTConeTransitionAppUi* theAppUi = static_cast<CTConeTransitionAppUi*> ((CCoeEnv::Static())->AppUi());
       
   187 	theAppUi->INFO_PRINTF2(_L("HitRegionContains function for %S has been called"), &iControlName);
       
   188 	if(theIsInside)
       
   189 		{
       
   190 		theAppUi->TEST(this == &aControl);
       
   191 		theAppUi->TEST(theAppUi->iExpectedControlName == iControlName);
       
   192 		theAppUi->INFO_PRINTF2(_L("The region has been dectected as inside control %S"), &iControlName);
       
   193 		return ETrue;
       
   194 		}
       
   195 	
       
   196 	return EFalse;
       
   197 	}
       
   198 
       
   199 /** 
       
   200   Check if point is inside a triangle
       
   201 */
       
   202 TBool CTestControlGcTriangle::IsInside(const TPoint& pt) const
       
   203   {
       
   204   TReal b0, b1, b2, b3;
       
   205     // first check bounding box
       
   206   TRect rc = Rect();  
       
   207   if(rc.Contains(pt)) 
       
   208   	{
       
   209       // if inside, check triangle
       
   210     b0 =  ((*iPoints)[1].iX - (*iPoints)[0].iX) * ((*iPoints)[2].iY - (*iPoints)[0].iY) - 
       
   211     			((*iPoints)[2].iX - (*iPoints)[0].iX) * ((*iPoints)[1].iY - (*iPoints)[0].iY);
       
   212     b1 = (((*iPoints)[1].iX - pt.iX) * ((*iPoints)[2].iY - pt.iY) - ((*iPoints)[2].iX - pt.iX) * ((*iPoints)[1].iY - pt.iY)) / (TReal)b0;
       
   213     b2 = (((*iPoints)[2].iX - pt.iX) * ((*iPoints)[0].iY - pt.iY) - ((*iPoints)[0].iX - pt.iX) * ((*iPoints)[2].iY - pt.iY)) / (TReal)b0;
       
   214     b3 = (((*iPoints)[0].iX - pt.iX) * ((*iPoints)[1].iY - pt.iY) - ((*iPoints)[1].iX - pt.iX) * ((*iPoints)[0].iY - pt.iY)) / (TReal)b0;
       
   215 
       
   216     if((b1 > 0) && (b2 > 0) && (b3 > 0)) 
       
   217     	{
       
   218         return ETrue;
       
   219     	} 
       
   220     else 
       
   221     	{
       
   222         return EFalse;
       
   223     	}
       
   224     } 
       
   225     return EFalse;
       
   226   }
       
   227    
       
   228 
       
   229 /**
       
   230   Second phase constructor for CTestControlBackground object.\n
       
   231   Creates  has 3 component controls.\n
       
   232   Creates a fourth control with a bitmap object.\n
       
   233   Gets a pointer to Screen Device and creates a bitmapped graphics context.\n
       
   234   A mapping is created between the screen device and bitmapped Gc using CWindowToBitMappingGc.\n
       
   235   This mapping is used to convert the drawing to bitmap onto the screen.\n
       
   236   A Fbs Bitmap is created which is used to draw the background of the component controls.\n
       
   237 */
       
   238 void CTestControlBackground::ConstructL()
       
   239     {
       
   240     CreateWindowL();
       
   241     SetExtent(TPoint(20,20),TSize(600,200));
       
   242     
       
   243     iControl = new (ELeave) CTestControlGc();
       
   244     iControl ->ConstructL(TPoint(10,10),TSize(60,40), KRgbBlue, KRgbMagenta, _L("Control 1")); 
       
   245 
       
   246 	//top triangle
       
   247     iControl2 = new (ELeave) CTestControlGcTriangle();
       
   248     iControl2 ->ConstructL(TPoint(10,70),TSize(60,40), ETrue, KRgbBlue, KRgbRed, _L("Control 2")); 
       
   249 	
       
   250 	//bottom triangle
       
   251     iControl3 = new (ELeave) CTestControlGcTriangle();
       
   252     iControl3 ->ConstructL(TPoint(10,70),TSize(60,40), EFalse, KRgbBlue, KRgbYellow, _L("Control 3")); 
       
   253 
       
   254     iControlImage = new (ELeave) CTestControlImageGc();
       
   255     iControlImage ->ConstructL(TPoint(250,40),TSize(60,40), KRgbWhite, KRgbWhite, _L("Background Control")); 
       
   256     
       
   257     CWsScreenDevice* screenDevice=CCoeEnv::Static()->ScreenDevice();
       
   258     TDisplayMode dispMode = screenDevice -> DisplayMode();
       
   259 
       
   260 
       
   261 	iMainFbsBitGc=CFbsBitGc::NewL();	// for the main bitmap
       
   262 	const CCoeEnv* env = CCoeEnv::Static();
       
   263 
       
   264     iBitmapView = new (ELeave) CWsBitmap(env->WsSession());
       
   265     User::LeaveIfError(iBitmapView->Create(TSize(300,150), dispMode));
       
   266 	
       
   267 	iBitmapDevice2 = CFbsBitmapDevice::NewL(iBitmapView);
       
   268     
       
   269 	iGraphContext = CWindowToBitmapMappingGc::NewL(*screenDevice,*iMainFbsBitGc);	// takes place of iMainFbsBitGc (not passing ownership of context here !)
       
   270 
       
   271 	iMainFbsBitGc->Activate(iBitmapDevice2);
       
   272 	iControlImage->SetBitmap(iBitmapView);
       
   273     
       
   274     iBmpBackground = new (ELeave) CFbsBitmap();
       
   275     User::LeaveIfError(iBmpBackground->Load(_L("z:\\conetest\\city.mbm")));
       
   276     
       
   277     ActivateL();
       
   278     }
       
   279 /**
       
   280   Returns the number of component controls contained by iViewControl object.\n
       
   281   
       
   282   @return 4.\n
       
   283  
       
   284 */
       
   285 TInt CTestControlBackground::CountComponentControls() const
       
   286 	{
       
   287 	return 4;
       
   288 	}
       
   289 /**
       
   290   Returns the component control at the index aIndex.\n
       
   291   
       
   292   @return CCoeControl*, the component control pointer at index aIndex.\n
       
   293 */	
       
   294 CCoeControl* CTestControlBackground::ComponentControl(TInt aIndex) const
       
   295 	{
       
   296 	if(aIndex == 0)
       
   297 		return iControl;
       
   298 	if(aIndex == 1)
       
   299 		return iControl2;
       
   300 	if(aIndex == 2)
       
   301 		return iControl3;
       
   302 	else if(aIndex == 3)
       
   303 		return iControlImage;
       
   304 	return NULL;
       
   305 	}
       
   306 
       
   307 /**
       
   308   Destructor for CTestControlBackground Class.\n 
       
   309   Destroys the component controls and all other member objects.\n
       
   310 */
       
   311 CTestControlBackground::~CTestControlBackground()
       
   312     {
       
   313     delete iControl;
       
   314     delete iControlImage;
       
   315     delete iControl2;
       
   316     delete iControl3;
       
   317     delete iGraphContext;
       
   318     delete iMainFbsBitGc;
       
   319     
       
   320     delete iBitmapDevice2;
       
   321     delete iBitmapView;
       
   322     delete iBmpBackground; 
       
   323     }
       
   324 /**
       
   325   This function is called whenever a control gains or loses focus,
       
   326   as a result of a call to SetFocus().\n
       
   327   A typical use of FocusChanged() is to change the appearance of the control to 
       
   328   indicate whether or not it has focus, for example by drawing a focus rectangle around it.\n
       
   329  
       
   330 */
       
   331 void CTestControlBackground::FocusChanged(TDrawNow aDrawNow)
       
   332 	{
       
   333     if (aDrawNow)
       
   334         {
       
   335         ActivateGc();
       
   336         DrawBorder();
       
   337         DeactivateGc();
       
   338         }
       
   339     }
       
   340 /**
       
   341   Draws the border for the control.\n
       
   342   Gets a pointer to Graphic context and sets the pen colour depending
       
   343   on whether the control is in focus or not.\n
       
   344   Draws a border using DrawRect function of the graphic context.\n
       
   345 */
       
   346 void CTestControlBackground::DrawBorder() const
       
   347     {
       
   348     CWindowGc& gc=SystemGc();
       
   349     TRect rect=Rect();
       
   350 
       
   351     gc.DrawRect(rect);
       
   352     
       
   353     if (!IsFocused())
       
   354         gc.SetPenColor(KRgbWhite);
       
   355     rect.Shrink(1,1);
       
   356     gc.DrawRect(rect);
       
   357     rect.Shrink(1,1);
       
   358     gc.DrawRect(rect);
       
   359 	}
       
   360 
       
   361 /**
       
   362   Draw a control, called by window server.\n
       
   363   This function is used for window server-initiated redrawing of controls, 
       
   364   and for some application-initiated drawing.\n
       
   365   It should be implemented by each control, but is only called from within 
       
   366   CCoeControl's member functions, and not from the derived class.\n
       
   367 */
       
   368 void CTestControlBackground::Draw(const TRect& /*aRect*/) const
       
   369     {
       
   370     CWindowGc& gc=SystemGc();
       
   371 	TRect rc = Rect();
       
   372 	gc.SetBrushColor(KRgbWhite);
       
   373 	gc.Clear(rc);
       
   374 	DrawBorder();
       
   375     }
       
   376 
       
   377 /** 
       
   378   The function replaces Gc from standard window Gc to offscreen bitmap.\n
       
   379   Sets Object of type CWindowToBitmapMappingGc as the Graphic Context.\n
       
   380  
       
   381   @return Error code, KErrNone if no error.\n
       
   382 */
       
   383 TInt CTestControlBackground::SetChildGc()
       
   384 	{
       
   385 	TInt theError = KErrNone;
       
   386 	if(iControl && iGraphContext)
       
   387 		{
       
   388     	theError = iControl->SetGc(iGraphContext);
       
   389 		}
       
   390 	return theError;	
       
   391 	}
       
   392 /** 
       
   393  Restores standard window Gc.\n
       
   394 */
       
   395 void CTestControlBackground::RestoreChildGc()
       
   396 	{
       
   397 	if(iControl)
       
   398 		{
       
   399     	iControl->SetGc(NULL);
       
   400 		}
       
   401 	}
       
   402 /**
       
   403   Draw function for the CTestControlBackground class.\n
       
   404   The function draws to the screen by using bitmap block transfer.\n
       
   405 */
       
   406 void CTestControlBackground::Draw(CWindowGc& aGc, const CCoeControl& /*aControl*/, const TRect& aRect) const
       
   407 	{
       
   408 	TPoint pt = aRect.iTl;
       
   409 
       
   410 	pt = pt - TPoint(5,5);
       
   411 	TRect rc = TRect(iBmpBackground->SizeInPixels());
       
   412 	rc.SetHeight(100);
       
   413 	aGc.BitBlt(pt, iBmpBackground, rc);
       
   414 	} 
       
   415 	   
       
   416 /** 
       
   417   Draw white rectangle to offscreen bitmap 
       
   418 */
       
   419 void CTestControlBackground::ClearOffScreenBitmap()
       
   420 	{
       
   421 	iGraphContext->Clear();
       
   422 	TSize sz = iBitmapView->SizeInPixels();
       
   423 	
       
   424 	iGraphContext->SetPenColor(KRgbWhite);
       
   425     iGraphContext->SetBrushColor(KRgbWhite);
       
   426     TRect rc = TRect(0, 0, sz.iWidth, sz.iHeight);
       
   427 	iGraphContext->DrawRect(rc);
       
   428 	}
       
   429 /**
       
   430   The function sets the iControl as the parent of the control iControl2.\n
       
   431 */
       
   432 void CTestControlBackground::SetControlParent()
       
   433 	{
       
   434 	if(iControl && iControl2)
       
   435 		iControl2->SetParent(iControl);
       
   436 	}
       
   437 
       
   438 /** 
       
   439   Supress/resume output for a given control.\n
       
   440 */
       
   441 void CTestControlBackground::SupressOutput(TInt aNumControl, TBool aSupress)
       
   442 	{
       
   443 	switch(aNumControl)
       
   444 		{
       
   445 			case 0:
       
   446 			if(iControl)
       
   447 				iControl->SupressOutput(aSupress); 
       
   448 			break;	
       
   449 			case 1:
       
   450 			if(iControl2)
       
   451 				iControl2->SupressOutput(aSupress); 
       
   452 			break;
       
   453 			case 2:
       
   454 			if(iControl3)
       
   455 				iControl3->SupressOutput(aSupress); 
       
   456 			break;
       
   457 			default : break;	
       
   458 		}
       
   459 	}
       
   460 
       
   461 /**
       
   462   @SYMTestCaseID UIF-TConeTransition-GeneratePointerEventsOnControl1L
       
   463  
       
   464   @SYMPREQ
       
   465  
       
   466   @SYMTestCaseDesc Generates pointer events for Control 1 and later verifies if they
       
   467   are handled by the handlers of Control2.\n
       
   468  
       
   469   @SYMTestPriority High
       
   470  
       
   471   @SYMTestStatus Implemented
       
   472   
       
   473   @SYMTestActions : Send pointer event to control 1.\n
       
   474  
       
   475   @SYMTestExpectedResults : Control1 should handle the generated pointer events.\n
       
   476  
       
   477   @SYMTestType : CIT 
       
   478 */
       
   479 void CTestControlBackground::GeneratePointerEventsOnControl1L()
       
   480 	{
       
   481 	TRect rc = iControl->Rect();
       
   482 	
       
   483 	CTConeTransitionAppUi* theAppUi = static_cast<CTConeTransitionAppUi*> ((CCoeEnv::Static())->AppUi());
       
   484 	theAppUi->iExpectedControlName = iControl->iControlName;
       
   485 	TPointerEvent thePointer;
       
   486 	thePointer.iType=TPointerEvent::EButton1Down;
       
   487 	thePointer.iModifiers = 0;
       
   488 	thePointer.iPosition=rc.iTl + TPoint(2, 2);
       
   489 	HandlePointerEventL(thePointer);
       
   490 	}
       
   491 /**
       
   492   @SYMTestCaseID UIF-TConeTransition-GeneratePointerEventsOnControl2L
       
   493  
       
   494   @SYMPREQ
       
   495  
       
   496   @SYMTestCaseDesc Generates pointer events for Control 2 and later verifies if they
       
   497   are handled by the handlers of Control2.\n
       
   498  
       
   499   @SYMTestPriority High
       
   500  
       
   501   @SYMTestStatus Implemented
       
   502   
       
   503   @SYMTestActions : Send pointer event to control 2.\n
       
   504   The control has unique triangle hit region but occupied an area 
       
   505   exactly the same as control3.\n
       
   506   
       
   507   @SYMTestExpectedResults : Control2 should handle the generated pointer events.\n
       
   508  
       
   509   @SYMTestType : CIT 
       
   510 */	
       
   511 void CTestControlBackground::GeneratePointerEventsOnControl2L()
       
   512 	{
       
   513 	TRect rc2 = iControl2->Rect();
       
   514 	CTConeTransitionAppUi* theAppUi = static_cast<CTConeTransitionAppUi*> ((CCoeEnv::Static())->AppUi());
       
   515 	theAppUi->iExpectedControlName = iControl2->iControlName;
       
   516 
       
   517 	
       
   518 	TPointerEvent thePointer;
       
   519 	thePointer.iType=TPointerEvent::EButton1Down;
       
   520 	thePointer.iModifiers = 0;
       
   521 	
       
   522 	
       
   523 	thePointer.iPosition=TPoint(rc2.iBr.iX - 2, rc2.iTl.iY + 2);
       
   524 	HandlePointerEventL(thePointer);
       
   525 	}
       
   526 
       
   527 /**
       
   528   @SYMTestCaseID UIF-TConeTransition-GeneratePointerEventsOnControl3L
       
   529  
       
   530   @SYMPREQ
       
   531  
       
   532   @SYMTestCaseDesc Generates pointer events for Control 3 and later verifies if they
       
   533   are handled by the handlers of Control3.\n
       
   534  
       
   535   @SYMTestPriority High
       
   536  
       
   537   @SYMTestStatus Implemented
       
   538   
       
   539   @SYMTestActions : Send pointer event to control 3.\n
       
   540   The control has unique triangle hit region but occupied an area 
       
   541   exactly the same as control3.\n
       
   542   
       
   543   @SYMTestExpectedResults : Control3 should handle the generated pointer events.\n
       
   544  
       
   545   @SYMTestType : CIT 
       
   546 */
       
   547 void CTestControlBackground::GeneratePointerEventsOnControl3L()
       
   548 	{
       
   549 	TRect rc2 = iControl3->Rect();
       
   550 	CTConeTransitionAppUi* theAppUi = static_cast<CTConeTransitionAppUi*> ((CCoeEnv::Static())->AppUi());
       
   551 	theAppUi->iExpectedControlName = iControl3->iControlName;
       
   552 	
       
   553 	TPointerEvent thePointer;
       
   554 	thePointer.iType=TPointerEvent::EButton1Down;
       
   555 	thePointer.iModifiers = 0;
       
   556 	
       
   557 	thePointer.iPosition=TPoint(rc2.iTl.iX + 2, rc2.iBr.iY - 2);
       
   558 	HandlePointerEventL(thePointer);
       
   559 	}
       
   560 /**
       
   561   @SYMTestCaseID UIF-TConeTransition-OffScreenDrawing
       
   562  
       
   563   @SYMPREQ
       
   564  
       
   565   @SYMTestCaseDesc Test drawing on a bitmap instead of directly on the screen.\n
       
   566  
       
   567   @SYMTestPriority High
       
   568  
       
   569   @SYMTestStatus Implemented
       
   570   
       
   571   @SYMTestActions : CTestControlBackground object is set as the background drawing object
       
   572   for control 2 and 3.\n
       
   573   The backgrounds of these controls is drawn by the parent control on invalidation.\n
       
   574   The foreground is drawn by the iGraphContext using Fbs BitMap.\n
       
   575   
       
   576   @SYMTestExpectedResults : The drawing should be successful..\n
       
   577  
       
   578   @SYMTestType : CIT 
       
   579 */	
       
   580 TInt CTestControlBackground::OffScreenDrawing()
       
   581 	{
       
   582 	if(!iControl2 || !iControl3 || !iGraphContext)
       
   583 		return KErrBadHandle;
       
   584 	
       
   585 	iControl2->SetBackground(this);
       
   586 	iControl3->SetBackground(this);
       
   587 	ActivateGc();
       
   588 	
       
   589 	TRect rect = Rect();
       
   590 	Window().Invalidate(rect);
       
   591 	Window().BeginRedraw(rect);
       
   592 
       
   593 	Draw(rect);
       
   594 	iControl2->DrawBackground(iControl2->Rect());
       
   595 	iControl3->DrawBackground(iControl3->Rect());
       
   596 	
       
   597 
       
   598    	TInt theError = iControl2->SetGc(iGraphContext);
       
   599 	if(theError != KErrNone)
       
   600 		return theError;
       
   601 		
       
   602    	theError = iControl3->SetGc(iGraphContext);
       
   603 	if(theError != KErrNone)
       
   604 		{
       
   605 		iControl2->SetGc(NULL);
       
   606 		return theError;
       
   607 		}
       
   608 
       
   609 	//it should draw to offscreen bitmap
       
   610 	iControl2->DrawForeground(iControl2->Rect());
       
   611 	iControl3->DrawForeground(iControl3->Rect());
       
   612 	
       
   613 	//output offscreen bitmap for visual check
       
   614 	iControlImage->Draw(rect);
       
   615 	
       
   616 	Window().EndRedraw();
       
   617 	DeactivateGc();
       
   618 
       
   619 	return theError;
       
   620 	}
       
   621 /**
       
   622   @SYMTestCaseID UIF-TConeTransition-DirectScreenDrawing
       
   623  
       
   624   @SYMPREQ
       
   625  
       
   626   @SYMTestCaseDesc Test drawing directly on the screen.\n
       
   627  
       
   628   @SYMTestPriority High
       
   629  
       
   630   @SYMTestStatus Implemented
       
   631   
       
   632   @SYMTestActions : Background and Foreground drawing directly to screen Gc.\n
       
   633   CTestControlBackground object is set as the background drawer.\n
       
   634   Drawing for background and foreground is done separately for each component control.\n
       
   635   
       
   636   @SYMTestExpectedResults : The drawing should be successful.\n
       
   637  
       
   638   @SYMTestType : CIT 
       
   639 */	
       
   640 TInt CTestControlBackground::DirectScreenDrawing()
       
   641 	{
       
   642 	if(!iControl2 || !iControl3 || !iGraphContext)
       
   643 		return KErrBadHandle;
       
   644 	
       
   645 	iControl2->SetGc(NULL);
       
   646 	iControl3->SetGc(NULL);
       
   647 	ClearOffScreenBitmap();
       
   648 	
       
   649 	ActivateGc();
       
   650 	
       
   651 	TRect rect = Rect();
       
   652 
       
   653 	Window().Invalidate(rect);
       
   654 	Window().BeginRedraw(rect);
       
   655 
       
   656 	Draw(rect);
       
   657 	iControl2->DrawBackground(iControl2->Rect());
       
   658 	iControl3->DrawBackground(iControl3->Rect());
       
   659 
       
   660 	//draw directly to screen
       
   661 	iControl2->DrawForeground(iControl2->Rect());
       
   662 	iControl3->DrawForeground(iControl3->Rect());
       
   663 
       
   664 	iControlImage->Draw(rect);
       
   665 
       
   666 	Window().EndRedraw();
       
   667 	DeactivateGc();
       
   668 	
       
   669 	return KErrNone;
       
   670 	}
       
   671 
       
   672 /**
       
   673   Draw function for the CTestControlImageGc Class.\n
       
   674   
       
   675 */
       
   676 void CTestControlImageGc::Draw(const TRect& /*aRect*/) const
       
   677 	{
       
   678     CWindowGc& gc=SystemGc();
       
   679 
       
   680 	TRect rc = Rect();
       
   681 	gc.Clear(rc);
       
   682 	if(iBmp)
       
   683     	gc.BitBlt(rc.iTl, iBmp);
       
   684 		
       
   685 	}
       
   686 
       
   687 /**
       
   688   Constructor for CTConeTransitionAppUi class.\n
       
   689 */
       
   690 CTConeTransitionAppUi::CTConeTransitionAppUi(CTmsTestStep* aStep) :
       
   691 CTestCoeAppUi(aStep)
       
   692 {}
       
   693 /**
       
   694   Destructor for the CTConeTransitionAppUi class.\n
       
   695   Removes the Control from the control stack.\n
       
   696 */
       
   697 CTConeTransitionAppUi::~CTConeTransitionAppUi()
       
   698 	{
       
   699 	RemoveFromStack(iViewControl);
       
   700 	delete iViewControl;
       
   701 	}
       
   702 
       
   703 /**
       
   704   Second phase constructor for CTConeTransitionAppUi Class.\n
       
   705   Instantiates a container control of type CTestControlBackground.\n
       
   706   Starts the automated execution of test cases using test manager.\n
       
   707 */
       
   708 void CTConeTransitionAppUi::ConstructL()
       
   709 	{
       
   710 	CTestCoeAppUi::ConstructL();
       
   711 	
       
   712     iViewControl=new(ELeave) CTestControlBackground;
       
   713     iViewControl->ConstructL();
       
   714     AddToStackL(iViewControl);
       
   715 
       
   716 	AutoTestManager().StartAutoTest();
       
   717 	}
       
   718 
       
   719 /**
       
   720   Handler for Key Events received by the TConeTransition application.\n
       
   721   Exits the application after receiving Ctrl + E.\n
       
   722   @return TKeyRespone, indicating whether key event is handled or not.\n
       
   723 */	
       
   724 TKeyResponse CTConeTransitionAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   725     {
       
   726 	TKeyResponse ret=EKeyWasNotConsumed;
       
   727     if (aType==EEventKey && aKeyEvent.iCode==CTRL('e'))
       
   728 		{
       
   729 		CBaActiveScheduler::Exit();
       
   730 		ret=EKeyWasConsumed;
       
   731 		}
       
   732 	return ret;
       
   733     }
       
   734 /**
       
   735    Auxiliary Function for all Test Cases.\n
       
   736   
       
   737    The method is an override from CTestCoeAppUi. \n
       
   738    This function is called asynchronously by RunL function of the
       
   739    AutotestManager after previous test case is executed.\n
       
   740    Tests the following scenarios one by one.\n
       
   741    1. Force the control 1 to use off screen bitmap, instead of screen.\n
       
   742    2.Force the control 1 to use off screen bitmap, instead of screen.\n
       
   743    3.Resume using of screen Gc for control 1.\n
       
   744    4.Set Control 1 as parent for control 2.\n
       
   745    5.Supress output for control 2.\n
       
   746    6.Restore output for controls and remove off screen bitmat from control1.\n
       
   747    7.Trying to generate pointer event on control 1.\n
       
   748    8.Trying to generate pointer event on control 2.\n
       
   749    9.Generate pointer event on control 3.\n
       
   750    10.Separate Drawing of foreground and background, offscreen version.\n
       
   751    11.Separate Drawing of foreground and background, direct screen version.\n
       
   752    
       
   753  */
       
   754 void CTConeTransitionAppUi::RunTestStepL(TInt aStepNum)
       
   755 	{
       
   756 
       
   757 	User::After(TTimeIntervalMicroSeconds32(1000000 * 2));
       
   758 	switch(aStepNum)
       
   759 		{
       
   760 		case 1: 
       
   761 		//inserted to increase delay before a first test case for a 
       
   762 		//visual check of initial output
       
   763 		INFO_PRINTF1(_L("Start all test cases"));
       
   764 		break;
       
   765 		case 2:
       
   766 		INFO_PRINTF1(_L("Force the control 1 to use off screen bitmap, instead of screen"));
       
   767 		TEST(iViewControl->SetChildGc() == KErrNone);
       
   768 		iViewControl->DrawNow();
       
   769 		break;
       
   770 		case 3:
       
   771 		INFO_PRINTF1(_L("Resume using of screen Gc for control 1"));
       
   772 		iViewControl->RestoreChildGc();
       
   773 		iViewControl->ClearOffScreenBitmap();
       
   774 		iViewControl->DrawNow();
       
   775 		break;
       
   776 		case 4:
       
   777 		INFO_PRINTF1(_L("Set Control 1 as parent for control 2"));
       
   778 		TEST(iViewControl->SetChildGc() == KErrNone);
       
   779 		iViewControl->SetControlParent();
       
   780 		iViewControl->SupressOutput(0, ETrue);
       
   781 		iViewControl->SupressOutput(1, EFalse);
       
   782 		iViewControl->ClearOffScreenBitmap();
       
   783 		iViewControl->DrawNow();
       
   784 		break;
       
   785 		case 5:
       
   786 		INFO_PRINTF1(_L("Supress output for control 2"));
       
   787 		iViewControl->SupressOutput(1, ETrue);
       
   788 		iViewControl->SupressOutput(0, EFalse);
       
   789 		iViewControl->ClearOffScreenBitmap();
       
   790 		iViewControl->DrawNow();
       
   791 		break;
       
   792 		case 6:
       
   793 		INFO_PRINTF1(_L("Restore output for controls and remove off screen bitmat from control1"));
       
   794 		iViewControl->SupressOutput(1, EFalse);
       
   795 		iViewControl->SupressOutput(0, EFalse);
       
   796 		iViewControl->RestoreChildGc();
       
   797 		iViewControl->ClearOffScreenBitmap();
       
   798 		iViewControl->DrawNow();
       
   799 		break;
       
   800 		case 7:
       
   801 		{
       
   802 		SetTestStepID(_L("UIF-TConeTransition-GeneratePointerEventsOnControl1L"));		
       
   803 		INFO_PRINTF1(_L("Trying to generate pointer event on control 1"));
       
   804 		TRAPD(ret, iViewControl->GeneratePointerEventsOnControl1L());
       
   805 		TEST(ret==KErrNone);
       
   806 		RecordTestResultL();		
       
   807 		}
       
   808 		break;
       
   809 		case 8:
       
   810 		{
       
   811 		SetTestStepID(_L("UIF-TConeTransition-GeneratePointerEventsOnControl2L"));		
       
   812 		INFO_PRINTF1(_L("Trying to generate pointer event on control 2"));
       
   813 		TRAPD(ret, iViewControl->GeneratePointerEventsOnControl2L());
       
   814 		TEST(ret==KErrNone);
       
   815 		RecordTestResultL();		
       
   816 		}
       
   817 		break;
       
   818 		case 9:
       
   819 		{
       
   820 		SetTestStepID(_L("UIF-TConeTransition-GeneratePointerEventsOnControl3L"));		
       
   821 		INFO_PRINTF1(_L("Trying to generate pointer event on control 3"));
       
   822 		TRAPD(ret, iViewControl->GeneratePointerEventsOnControl3L());
       
   823 		TEST(ret==KErrNone);
       
   824 		RecordTestResultL();
       
   825 		}
       
   826 		break;
       
   827 		case 10:
       
   828 		SetTestStepID(_L("UIF-TConeTransition-OffScreenDrawing"));			
       
   829 		INFO_PRINTF1(_L("Separate Drawing of foreground and background, offscreen version"));
       
   830 		TEST(iViewControl->OffScreenDrawing() == KErrNone);
       
   831 		RecordTestResultL();		
       
   832 		break;
       
   833 		case 11: 
       
   834 		SetTestStepID(_L("UIF-TConeTransition-DirectScreenDrawing"));			
       
   835 		INFO_PRINTF1(_L("Separate Drawing of foreground and background, direct screen version"));
       
   836 		TEST(iViewControl->DirectScreenDrawing() == KErrNone);
       
   837 		RecordTestResultL();	
       
   838 		CloseTMSGraphicsStep();
       
   839 		break;
       
   840 		case 12:
       
   841 			AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
   842 		break;
       
   843 
       
   844 		}
       
   845 		
       
   846 	}
       
   847 
       
   848 
       
   849 /**
       
   850   Completes the construction of the Control Environment(CCoeEnv object).\n
       
   851   Instantiates the CTConeTransitionAppUi class which serves as a AppUi class.\n
       
   852   Sets the CTConeTransitionAppUi object as the application's user interface object.\n
       
   853   Invokes the second phase constructor of the application's UI.\n
       
   854 */
       
   855 void CTConeTransitionStep::ConstructAppL(CCoeEnv* aCoe)
       
   856 	{ // runs inside a TRAP harness
       
   857 	aCoe->ConstructL();
       
   858 	CTConeTransitionAppUi* appUi= new (ELeave) CTConeTransitionAppUi(this);
       
   859 	aCoe->SetAppUi(appUi);
       
   860 	appUi->ConstructL();
       
   861 	}
       
   862 /**
       
   863   Constructor for CTConeTransition Step class.\n
       
   864   Sets the test step name.\n
       
   865 */
       
   866 CTConeTransitionStep::CTConeTransitionStep()
       
   867 	{
       
   868 	SetTestStepName(KTConeTransitionStep);
       
   869 	}
       
   870 /**
       
   871   Destructor for CTConeTransition class.\n
       
   872 */
       
   873 CTConeTransitionStep::~CTConeTransitionStep()
       
   874 {}
       
   875 
       
   876 /**
       
   877   Entry function for CTConeTransition Test Step.\n
       
   878   Sets up the control environment.\n
       
   879   Constructs and Launches the CTConeTransition Test application.\n
       
   880 */
       
   881 TVerdict CTConeTransitionStep::doTestStepL() // main function called by E32
       
   882 	{
       
   883 	INFO_PRINTF1(_L("Test Started"));
       
   884 	
       
   885 	PreallocateHALBuffer();
       
   886 
       
   887 	__UHEAP_MARK;
       
   888 	CCoeEnv* coe=new(ELeave) CCoeEnv;
       
   889 	TRAPD(err,ConstructAppL(coe));
       
   890 
       
   891 	if (!err)
       
   892 		coe->ExecuteD();
       
   893 	else
       
   894 		{
       
   895 		SetTestStepResult(EFail);
       
   896 		delete coe;
       
   897 		}
       
   898 
       
   899 	REComSession::FinalClose();	
       
   900 
       
   901 	__UHEAP_MARKEND;
       
   902 
       
   903 	INFO_PRINTF1(_L("Test Finished"));
       
   904 	return TestStepResult();
       
   905 	}
       
   906 
       
   907 
       
   908 
       
   909