lafagnosticuifoundation/uigraphicsutils/tef/TBORDERStep.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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent - Internal Symbian test code 
       
    19 */
       
    20 
       
    21 
       
    22 #include <e32keys.h>
       
    23 #include <basched.h>
       
    24 #include <coemain.h>
       
    25 #include <coeaui.h>
       
    26 #include <gulutil.h>
       
    27 
       
    28 #include "TBorderstep.h"
       
    29 
       
    30 //
       
    31 // class CSimpleControl
       
    32 //
       
    33 
       
    34 
       
    35 void CSimpleControl::ConstructL()
       
    36     {
       
    37     CreateWindowL();
       
    38     Window().SetShadowDisabled(ETrue);
       
    39 	iAlign=CGraphicsContext::ECenter;
       
    40     SetExtentToWholeScreen();
       
    41     ActivateL();
       
    42 	iBuf1 = _L("This &line has 0 margin...");
       
    43 	iBuf2 = _L("and this one has a &margin of 20!");
       
    44 	iRect = TRect(TPoint(40,40),TSize(560,160));
       
    45     }
       
    46 
       
    47 TKeyResponse CSimpleControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
    48     {
       
    49     if (aType!=EEventKey)
       
    50         return(EKeyWasNotConsumed);
       
    51     TInt code=aKeyEvent.iCode;
       
    52     if (code==CTRL('e'))
       
    53         CBaActiveScheduler::Exit();
       
    54 	if (code==CTRL('l'))
       
    55 		iAlign=CGraphicsContext::ELeft;
       
    56 	else if (code==CTRL('r'))
       
    57 		iAlign=CGraphicsContext::ERight;
       
    58 	else if (code==CTRL('c'))
       
    59 		iAlign=CGraphicsContext::ECenter;
       
    60 	else
       
    61 		return(EKeyWasConsumed);
       
    62 	ActivateGc();
       
    63 	DrawText();
       
    64 	DeactivateGc();
       
    65     return(EKeyWasConsumed);
       
    66     }
       
    67 
       
    68 void CSimpleControl::DrawBorder(CWindowGc& aGC, TRgb aColor, TGulBorder::TBorderType aBorderType, TInt aYPos, TInt aYTextPos, const TDesC &aBorderName) const
       
    69 	{
       
    70 	TGulBorder border(aBorderType);
       
    71 	aGC.SetClippingRect(TRect(TPoint(30,aYPos),TSize(100,20)));
       
    72 	border.Draw(aGC,TRect(TPoint(30,aYPos),TSize(100,20)));
       
    73 	aGC.CancelClippingRect();
       
    74 	border.Draw(aGC,TRect(TPoint(140,aYPos),TSize(100,20)));
       
    75 	aGC.SetPenColor(aColor);
       
    76 	aGC.DrawText(aBorderName,TPoint(250,aYTextPos));
       
    77 	}
       
    78 
       
    79 void CSimpleControl::Draw(const TRect& /*aRect*/) const
       
    80 	{
       
    81 	CWindowGc& gc = SystemGc();
       
    82 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
    83 	gc.DrawRect(Rect());
       
    84 	gc.UseFont(iCoeEnv->NormalFont());
       
    85 
       
    86 	TInt yPos = 30;
       
    87 	TInt yTextPos = 42;
       
    88 	const TInt yInc = 25;
       
    89 
       
    90 	DrawBorder(gc,KRgbBlack,TGulBorder::ENone, yPos, yTextPos,_L("ENone"));
       
    91 	yTextPos+=yInc;
       
    92 	yPos+=yInc;
       
    93 
       
    94 	DrawBorder(gc,KRgbBlack,TGulBorder::ESingleBlack, yPos, yTextPos,_L("ESingleBlack"));
       
    95 	yTextPos+=yInc;
       
    96 	yPos+=yInc;
       
    97 	
       
    98 	DrawBorder(gc,KRgbBlack,TGulBorder::EShallowRaised, yPos, yTextPos,_L("EShallowRaised"));	
       
    99 	yTextPos+=yInc;
       
   100 	yPos+=yInc;
       
   101 	
       
   102 	DrawBorder(gc,KRgbBlack,TGulBorder::EDeepRaised, yPos, yTextPos,_L("EDeepRaised"));	
       
   103 	yTextPos+=yInc;
       
   104 	yPos+=yInc;
       
   105 	
       
   106 	DrawBorder(gc,KRgbBlack,TGulBorder::EShallowSunken, yPos, yTextPos,_L("EShallowSunken"));	
       
   107 	yTextPos+=yInc;
       
   108 	yPos+=yInc;
       
   109 	
       
   110 	DrawBorder(gc,KRgbBlack,TGulBorder::EDeepSunken, yPos, yTextPos,_L("EDeepSunken"));	
       
   111 	yTextPos+=yInc;
       
   112 	yPos+=yInc;
       
   113 	
       
   114 	DrawBorder(gc,KRgbBlack,TGulBorder::EThickDeepRaisedWithOutline, yPos, yTextPos,_L("EThickDeepRaisedWithOutline"));	
       
   115 	yTextPos+=yInc;
       
   116 	yPos+=yInc;
       
   117 	}
       
   118 
       
   119 void CSimpleControl::DrawText() const
       
   120 	{ // assumes brush style is NULL on entry to routine; trashed at exit
       
   121 	CWindowGc& gc = SystemGc();
       
   122 	TRect rect = iRect;
       
   123 	rect.Shrink(TSize(80,60));
       
   124 	rect.Move(0,-30);
       
   125 	const CFont* font = iCoeEnv->NormalFont();
       
   126 	gc.UseFont(font);
       
   127 	TRect tmp=rect;
       
   128 	gc.DrawRect(tmp);
       
   129 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   130 	tmp.Shrink(1,1);
       
   131 	DrawUtils::DrawText(gc,iBuf1,tmp,font->AscentInPixels()*2,iAlign,0,font);
       
   132 	rect.Move(0,60);
       
   133 	gc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
   134 	gc.DrawRect(rect);
       
   135 	rect.Shrink(1,1);
       
   136 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   137 	DrawUtils::DrawText(gc,iBuf2,rect,font->AscentInPixels()*2,iAlign,20,font);
       
   138 	}
       
   139 
       
   140 
       
   141 CTestBorderUi::CTestBorderUi(CTmsTestStep* aStep) :
       
   142 	CTestCoeAppUi(aStep)
       
   143 	{}
       
   144 
       
   145 CTestBorderUi::~CTestBorderUi()
       
   146 	{
       
   147 	if(iControl)
       
   148 		{
       
   149 //		RemoveFromStack(iControl);
       
   150 //		delete iControl;
       
   151 		}
       
   152 	}
       
   153 
       
   154 void CTestBorderUi::ConstructL()
       
   155 	{
       
   156 	CTestCoeAppUi::ConstructL();
       
   157 	iControl=new(ELeave) CSimpleControl;
       
   158 	AddToStackL(iControl,ECoeStackPriorityDefault,ECoeStackFlagOwnershipTransfered);
       
   159 	iControl->ConstructL();
       
   160 
       
   161 	AutoTestManager().StartAutoTest();
       
   162 	}
       
   163 
       
   164 
       
   165 void CTestBorderUi::RunTestStepL(TInt aStep)
       
   166 	{
       
   167 	TKeyEvent	theKeyEvent;
       
   168 
       
   169 
       
   170 	User::After(TTimeIntervalMicroSeconds32(1000000));
       
   171 	
       
   172 	switch(aStep)
       
   173 		{
       
   174 		case 1:
       
   175 		theKeyEvent.iCode = CTRL('l');
       
   176 		INFO_PRINTF1(_L("Left alignment"));
       
   177 		iCoeEnv->SimulateKeyEventL(theKeyEvent, EEventKey);
       
   178 		break;
       
   179 		case 2:
       
   180 		theKeyEvent.iCode = CTRL('r');
       
   181 		INFO_PRINTF1(_L("Right alignment"));
       
   182 		iCoeEnv->SimulateKeyEventL(theKeyEvent, EEventKey);
       
   183 		break;
       
   184 		case 3:
       
   185 		theKeyEvent.iCode = CTRL('c');
       
   186 		INFO_PRINTF1(_L("Center alignment"));
       
   187 		iCoeEnv->SimulateKeyEventL(theKeyEvent, EEventKey);
       
   188 		break;
       
   189 		case 4:
       
   190 		AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
   191 		break;
       
   192 		}
       
   193 
       
   194 	}
       
   195 
       
   196 //
       
   197 // Main
       
   198 //
       
   199 
       
   200 void CTBorderStep::ConstructAppL(CCoeEnv* aCoeEnv)
       
   201     { // runs inside a TRAP harness
       
   202 	aCoeEnv->ConstructL();
       
   203 	CTestBorderUi* appUi=new(ELeave) CTestBorderUi(this);
       
   204 	appUi->ConstructL();
       
   205 	aCoeEnv->SetAppUi(appUi);
       
   206     }
       
   207 
       
   208 
       
   209 CTBorderStep::~CTBorderStep()
       
   210 /**
       
   211    Destructor
       
   212  */
       
   213 	{
       
   214 	}
       
   215 
       
   216 CTBorderStep::CTBorderStep()
       
   217 /**
       
   218    Constructor
       
   219  */
       
   220 	{
       
   221 	// Call base class method to set up the human readable name for logging
       
   222 	SetTestStepName(KTBorderStep);
       
   223 	}
       
   224 
       
   225 
       
   226 TVerdict CTBorderStep::doTestStepL()
       
   227 	{
       
   228 	INFO_PRINTF1(_L("Test Started"));
       
   229 
       
   230 	PreallocateHALBuffer();
       
   231 
       
   232 	__UHEAP_MARK;
       
   233 
       
   234     CCoeEnv* coe=new(ELeave) CCoeEnv;
       
   235     TRAPD(err,ConstructAppL(coe));
       
   236     if (!err)
       
   237         coe->ExecuteD();
       
   238 		else
       
   239 			{
       
   240 			SetTestStepResult(EFail);
       
   241 			delete coe;
       
   242 			}
       
   243 
       
   244  	INFO_PRINTF1(_L("Test Finished"));
       
   245 
       
   246 	__UHEAP_MARKEND;
       
   247 	return TestStepResult();
       
   248 	}