lafagnosticuifoundation/clockanim/tef/TCLCK2STEP.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 code for the clock DLL
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent - Internal Symbian test code 
       
    21 */
       
    22 
       
    23 #include <e32keys.h>
       
    24 #include <coemain.h>
       
    25 #include <coedef.h>
       
    26 #include <coeaui.h>
       
    27 #include <coecntrl.h>
       
    28 #include <clock.h>
       
    29 #include <basched.h>
       
    30 
       
    31 #include <mbs1.mbg>
       
    32 #include "TCLCK2STEP.h"
       
    33 
       
    34 
       
    35 
       
    36 #define TCLCK1_MBM _L("z:\\system\\data\\MBS1.MBM")
       
    37 #define CLOCK EMbmMbs1Clock
       
    38 #define CLOCKMSK EMbmMbs1Clockmsk
       
    39 
       
    40 // classes
       
    41 // main functions
       
    42 
       
    43 CTestClck2Ui::CTestClck2Ui(CTmsTestStep* aStep) :
       
    44 CTestCoeAppUi(aStep)
       
    45 	{}
       
    46 
       
    47 
       
    48 void CTestClck2Ui::ConstructL()
       
    49 	{
       
    50 	CTestCoeAppUi::ConstructL();
       
    51 	iControl=new(ELeave) CClk2Control;
       
    52 	AddToStackL(iControl,ECoeStackPriorityDefault,ECoeStackFlagOwnershipTransfered);
       
    53 //	appUi->AddToStackL(control,ECoeStackPriorityDefault,ECoeStackFlagOwnershipTransfered);
       
    54 	iControl->ConstructL();
       
    55 
       
    56 	AutoTestManager().StartAutoTest();
       
    57 	}
       
    58 
       
    59 /**
       
    60    @SYMTestCaseID UIF-Clock-TClock2
       
    61  */
       
    62 
       
    63 void CTestClck2Ui::RunTestStepL(TInt aNumStep)
       
    64 	{
       
    65 	TKeyEvent theKeyEvent;
       
    66 	TEventCode theType = EEventKey;
       
    67 	
       
    68 	//only for debug
       
    69 	User::After(TTimeIntervalMicroSeconds32(1000000));
       
    70 	
       
    71 	
       
    72 	switch(aNumStep)
       
    73 		{
       
    74 		case 1:
       
    75 		SetTestStepID(_L("UIF-Clock-TClock2"));
       
    76 		theKeyEvent.iCode = EKeyEnter;
       
    77 		theKeyEvent.iModifiers = 0;
       
    78 		
       
    79 		iControl->OfferKeyEventL(theKeyEvent, theType);
       
    80 		INFO_PRINTF1(_L("Show analog & digital clocks"));
       
    81 		break;
       
    82 		
       
    83 		case 2: case 6:
       
    84 		//Animate for 5 seconds
       
    85 		User::After(5000000);
       
    86 		INFO_PRINTF1(_L("Animate for 5 seconds"));
       
    87 		break;
       
    88 
       
    89 		case 3:
       
    90 		theKeyEvent.iCode = 'I';
       
    91 		theKeyEvent.iModifiers = 0;
       
    92 		
       
    93 		iControl->OfferKeyEventL(theKeyEvent, theType);
       
    94 		INFO_PRINTF1(_L("Stop wserv heartbeat timer"));
       
    95 		break;
       
    96 
       
    97 		case 4:
       
    98 		User::After(5000000);
       
    99 		INFO_PRINTF1(_L("Wait 5 seconds"));
       
   100 		break;
       
   101 
       
   102 		case 5:  
       
   103 		theKeyEvent.iCode = 'A';
       
   104 		theKeyEvent.iModifiers = 0;
       
   105 		
       
   106 		iControl->OfferKeyEventL(theKeyEvent, theType);
       
   107 		INFO_PRINTF1(_L("Start wserv heartbeat timer"));
       
   108 		RecordTestResultL();
       
   109 		CloseTMSGraphicsStep();
       
   110 		break;
       
   111 		
       
   112 		case 7:
       
   113 			AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
   114 		}
       
   115 	}
       
   116 
       
   117 
       
   118 void CTClck2Step::ConstructAppL(CCoeEnv* aCoeEnv)
       
   119 	{
       
   120 	aCoeEnv->ConstructL();
       
   121 	CTestClck2Ui* appUi=new(ELeave) CTestClck2Ui(this);
       
   122 	appUi->ConstructL();
       
   123 	aCoeEnv->SetAppUi(appUi);
       
   124 	}
       
   125 
       
   126 CTClck2Step::~CTClck2Step()
       
   127 /**
       
   128  * Destructor
       
   129  */
       
   130 	{
       
   131 	}
       
   132 
       
   133 CTClck2Step::CTClck2Step()
       
   134 /**
       
   135  * Constructor
       
   136  */
       
   137 	{
       
   138 	// Call base class method to set up the human readable name for logging
       
   139 	SetTestStepName(KTClck2Step);
       
   140 	}
       
   141 
       
   142 TVerdict CTClck2Step::doTestStepL()
       
   143 	{
       
   144 	INFO_PRINTF1(_L("Test Started"));
       
   145 	CCoeEnv* coeEnv=new CCoeEnv;
       
   146 	if (coeEnv==NULL)
       
   147 		{
       
   148 		SetTestStepResult(EFail);
       
   149 		return TestStepResult();
       
   150 		}
       
   151 	TRAPD(error, ConstructAppL(coeEnv));
       
   152 	if (error!=KErrNone)
       
   153 		{
       
   154 		delete coeEnv;
       
   155 		SetTestStepResult(EFail);
       
   156 		return TestStepResult();
       
   157 		}
       
   158 	coeEnv->ExecuteD();
       
   159 	INFO_PRINTF1(_L("Test Finished"));
       
   160 	return TestStepResult();
       
   161 	}
       
   162 
       
   163 
       
   164 // CClck2DestructableFont
       
   165 
       
   166 CClck2DestructableFont::CClck2DestructableFont(CWsScreenDevice* aScreenDevice)
       
   167 	:iScreenDevice(aScreenDevice)
       
   168 	{
       
   169 	}
       
   170 
       
   171 void CClck2DestructableFont::ConstructL(const TFontSpec& aFontSpec)
       
   172 	{
       
   173 	User::LeaveIfError(iScreenDevice->GetNearestFontInTwips((CFont*&)iFont, aFontSpec));
       
   174 	}
       
   175 
       
   176 CClck2DestructableFont::~CClck2DestructableFont()
       
   177 	{
       
   178 	iScreenDevice->ReleaseFont(iFont); // N.B. do not need to do "delete iFont"
       
   179 	}
       
   180 
       
   181 TInt CClck2DestructableFont::Handle() const
       
   182 	{
       
   183 	return iFont->Handle();
       
   184 	}
       
   185 
       
   186 // CClk2Control
       
   187 
       
   188 CClk2Control::CClk2Control()
       
   189 	:iBackgroundColor(85, 85, 85),
       
   190 	 iAnimDll(iCoeEnv->WsSession()),
       
   191 	 iDigitalClock0Position(350, 125),
       
   192 	 iDigitalClock0Size(180, 70),
       
   193 	 iAnalogClock0Position(10, 0),
       
   194 	 iAnalogClock0Size(300, 222),
       
   195 	 iUniversalTimeOffset(0)
       
   196 	{
       
   197 	__ASSERT_DEBUG(iDigitalClock0==NULL, User::Panic(_L("Clock test-code"), 1));
       
   198 	__ASSERT_DEBUG(iAnalogClock0==NULL, User::Panic(_L("Clock test-code"), 2));
       
   199 	}
       
   200 
       
   201 void CClk2Control::ConstructL()
       
   202 	{
       
   203 	// CONE construction stuff
       
   204 	CreateBackedUpWindowL(iCoeEnv->RootWin());
       
   205 	SetExtent(TPoint(10, 10), TSize(620, 220));
       
   206 	ActivateL();
       
   207 	iCoeEnv->WsSession().Flush();
       
   208 
       
   209 	User::LeaveIfError(iAnimDll.Load(_L("CLOCKA.DLL")));
       
   210 
       
   211 	// clock construction stuff
       
   212 	CreateDigitalClocksL();
       
   213 	CreateAnalogClocksL();
       
   214 	}
       
   215 
       
   216 CClk2Control::~CClk2Control()
       
   217 	{
       
   218 	if (iDigitalClock0!=NULL)
       
   219 		iDigitalClock0->Destroy();
       
   220 	if (iAnalogClock0!=NULL)
       
   221 		iAnalogClock0->Destroy();
       
   222 	iAnimDll.Close();
       
   223 	}
       
   224 
       
   225 TKeyResponse CClk2Control::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   226 	{
       
   227 	if (aType==EEventKey)
       
   228 		{
       
   229 		switch (aKeyEvent.iCode)
       
   230 			{
       
   231 		case CTRL('e'):
       
   232 			iCoeEnv->Flush();
       
   233 			CBaActiveScheduler::Exit();
       
   234 			break;
       
   235 		case EKeySpace:
       
   236 			if (aKeyEvent.iModifiers&EModifierShift)
       
   237 				iDigitalClock0->SetBackgroundColor(TRgb(85, 85, 85), TRgb(0, 0, 0));
       
   238 			else
       
   239 				iDigitalClock0->SetBackgroundColor(TRgb(170, 170, 170), TRgb(85, 85, 85));
       
   240 			break;
       
   241 		case EKeyEnter:
       
   242 			if (aKeyEvent.iModifiers&EModifierShift)
       
   243 				{
       
   244 				iDigitalClock0->SetVisible(EFalse);
       
   245 				iAnalogClock0->SetVisible(EFalse);
       
   246 				}
       
   247 			else
       
   248 				{
       
   249 				iDigitalClock0->SetVisible(ETrue);
       
   250 				iAnalogClock0->SetVisible(ETrue);
       
   251 				}
       
   252 			break;
       
   253 		case 'U':
       
   254 		case 'u':
       
   255 			iDigitalClock0->UpdateDisplay();
       
   256 			iAnalogClock0->UpdateDisplay();
       
   257 			break;
       
   258 		case 'D':
       
   259 		case 'd':
       
   260 			iDigitalClock0->Draw();
       
   261 			iAnalogClock0->Draw();
       
   262 			break;
       
   263 		case 'A':
       
   264 		case 'a':
       
   265 			{
       
   266 			TRawEvent	event;
       
   267 			event.Set(TRawEvent::EActive);
       
   268 			UserSvr::AddEvent(event);
       
   269 			}
       
   270 			break;
       
   271 		case 'I':
       
   272 		case 'i':
       
   273 			{
       
   274 			TRawEvent	event;
       
   275 			event.Set(TRawEvent::EInactive);
       
   276 			UserSvr::AddEvent(event);
       
   277 			}
       
   278 			break;
       
   279 			}
       
   280 		}
       
   281 
       
   282 	return EKeyWasConsumed;
       
   283 	}
       
   284 
       
   285 void CClk2Control::Draw(const TRect&) const
       
   286 	{
       
   287 	CGraphicsContext& systemGc=SystemGc();
       
   288 	systemGc.SetPenStyle(CGraphicsContext::ENullPen);
       
   289 	systemGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   290 	systemGc.SetBrushColor(iBackgroundColor);
       
   291 	systemGc.DrawRect(Rect());
       
   292 	}
       
   293 
       
   294 void CClk2Control::CreateDigitalClocksL()
       
   295 	{
       
   296 	TMargins margins;
       
   297 	margins.iLeft=0;
       
   298 	margins.iRight=0;
       
   299 	margins.iTop=0;
       
   300 	margins.iBottom=0;
       
   301 	// construct digital clock
       
   302 	STimeDeviceShadow digitalClock0Shadow;
       
   303 	digitalClock0Shadow.iIsOn=ETrue;
       
   304 	digitalClock0Shadow.iColor=TRgb(85, 85, 85);
       
   305 	digitalClock0Shadow.iOffset.SetXY(2, 2);
       
   306 	//
       
   307 	iDigitalClock0=new(ELeave) RDigitalClock(iAnimDll, BackedUpWindow());
       
   308 	iDigitalClock0->ConstructL(TTimeIntervalSeconds(30*60), iDigitalClock0Position, iDigitalClock0Size, margins, digitalClock0Shadow, TRgb(170, 170, 170), 1);
       
   309 	//
       
   310 	TBuf<64> digitalClock0Format0=_L("%-B%J%:1%T%+B");
       
   311 	CClck2DestructableFont* digitalClock0Font0=new(ELeave) CClck2DestructableFont(iCoeEnv->ScreenDevice());
       
   312 	CleanupStack::PushL(digitalClock0Font0);
       
   313 	TFontSpec digitalClock0FontSpec0(_L("arial"), iCoeEnv->ScreenDevice()->VerticalPixelsToTwips(25));
       
   314 	digitalClock0FontSpec0.iFontStyle.SetPosture(EPostureItalic);
       
   315 	digitalClock0FontSpec0.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
       
   316 	digitalClock0Font0->ConstructL(digitalClock0FontSpec0);
       
   317 	iDigitalClock0->AddTextSectionL(TDigitalDisplayTextSection(digitalClock0Font0->Handle(), TRgb(0, 0, 0),
       
   318 																EDigitalDisplayHorizontalTextAlignmentCenter,
       
   319 																EDigitalDisplayVerticalTextAlignmentCenterExclDescent,
       
   320 																0, 0, digitalClock0Format0));
       
   321 	//
       
   322 	CleanupStack::PopAndDestroy(); // pop and destroy digitalClock0Font0
       
   323 	}
       
   324 
       
   325 void CClk2Control::CreateAnalogClocksL()
       
   326 	{
       
   327 	CWsScreenDevice* screenDevice=iCoeEnv->ScreenDevice();
       
   328 	TMargins margins;
       
   329 	margins.iLeft=0;
       
   330 	margins.iRight=0;
       
   331 	margins.iTop=0;
       
   332 	margins.iBottom=0;
       
   333 	// construct analog clock
       
   334 	//
       
   335 	STimeDeviceShadow  analogClock0Shadow;
       
   336 	analogClock0Shadow.iIsOn=ETrue;
       
   337 	analogClock0Shadow.iColor=TRgb(85, 85, 85);
       
   338 	analogClock0Shadow.iOffset.SetXY(4, 4);
       
   339 	//
       
   340 	CFbsBitmap* analogClock0Face=new(ELeave) CFbsBitmap;
       
   341 	CleanupStack::PushL(analogClock0Face);
       
   342 	User::LeaveIfError(analogClock0Face->Load(TCLCK1_MBM, CLOCK));
       
   343 	analogClock0Face->SetSizeInTwips(screenDevice);
       
   344 	CFbsBitmap* analogClock0FaceMask=new(ELeave) CFbsBitmap;
       
   345 	CleanupStack::PushL(analogClock0FaceMask);
       
   346 	User::LeaveIfError(analogClock0FaceMask->Load(TCLCK1_MBM, CLOCKMSK));
       
   347 	analogClock0Face->SetSizeInTwips(screenDevice);
       
   348 	//
       
   349 	iAnalogClock0=new(ELeave) RAnalogClock(iAnimDll, BackedUpWindow());
       
   350 	iAnalogClock0->ConstructL(TTimeIntervalSeconds(30*60), iAnalogClock0Position, iAnalogClock0Size, margins, analogClock0Shadow,
       
   351 								analogClock0Face->Handle(), analogClock0FaceMask->Handle(), 3);
       
   352 	//
       
   353 	TRgb black(0, 0, 0);
       
   354 	CArrayFix<TPoint>* pointList=new(ELeave) CArrayFixFlat<TPoint>(4);
       
   355 	CleanupStack::PushL(pointList);
       
   356 	//
       
   357 	// N.B. the dimensions/positions of the hand features (i.e. lines and circles) are specified with the hand assumed to be in the
       
   358 	// 12 o'clock position, with TPoint(0, 0) being the center of the clock
       
   359 	TAnalogDisplayHand analogClock0HourHand(EAnalogDisplayHandOneRevPer12Hours);
       
   360 	analogClock0HourHand.AddLine(CGraphicsContext::ESolidPen, black, TSize(4, 4), TPoint(0, 10), TPoint(0, -55));
       
   361 	iAnalogClock0->AddHandL(analogClock0HourHand);
       
   362 	//
       
   363 	TAnalogDisplayHand analogClock0MinuteHand(EAnalogDisplayHandOneRevPerHour);
       
   364 	analogClock0MinuteHand.AddLine(CGraphicsContext::ESolidPen, black, TSize(4, 4), TPoint(0, 10), TPoint(0, -70));
       
   365 	iAnalogClock0->AddHandL(analogClock0MinuteHand);
       
   366 	//
       
   367 	TAnalogDisplayHand analogClock0SecondHand(EAnalogDisplayHandOneRevPerMinute);
       
   368 	analogClock0SecondHand.AddLine(CGraphicsContext::ESolidPen, black, TSize(2, 2), TPoint(0, 10), TPoint(0, -70));
       
   369 	iAnalogClock0->AddHandL(analogClock0SecondHand);
       
   370 	//
       
   371 	CleanupStack::PopAndDestroy(); // pop and destroy pointList
       
   372 	CleanupStack::PopAndDestroy(); // pop and destroy analogClock0FaceMask
       
   373 	CleanupStack::PopAndDestroy(); // pop and destroy analogClock0Face
       
   374 	}
       
   375