windowing/windowserver/test/SHELL.CPP
changeset 0 5d03bc08d59c
child 110 7f25ef56562d
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1995-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 // Shell to launch test code
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <f32file.h>
       
    20 #include "W32STD.H"
       
    21 #include "../SERVER/w32cmd.h"
       
    22 #include <e32svr.h>
       
    23 #include <hal.h>
       
    24 #include "../tlib/testbase.h"
       
    25 #include "../TClick/CLICK.H"
       
    26 
       
    27 #define __USING_PROCESS_
       
    28 
       
    29 #if !defined(__USING_PROCESS_)
       
    30 #define RP_FILENAME_SET _L(".DLL")
       
    31 #endif
       
    32 
       
    33 #define THE_PASSWORD _L("pass")
       
    34 #define INDEX_FOR_SHELL_TEST 0
       
    35 #define SHELL_TEST_NAME _L("ShellTest")
       
    36 #define INDEX_FOR_RESTART_TEST 1
       
    37 #define RESTART_TEST_NAME _L("RestartTest")
       
    38 #define INDEX_FOR_RESTART_EVENT_TEST 2
       
    39 #define RESTART_EVENT_TEST_NAME _L("RestartEventTest")
       
    40 
       
    41 const TInt EDoubleClickTime=500000;
       
    42 const TInt EDoubleClickDistance=16;
       
    43 
       
    44 #ifndef __USING_PROCESS_
       
    45 LOCAL_D const TUint KHeapSize=0x400000;
       
    46 #endif
       
    47 
       
    48 enum TShellPanic
       
    49 	{
       
    50 	EShellPanicRunningProcessCancel,
       
    51 	EShellPanicTemp,
       
    52 	EShellPanicRunningProcessNullPtr,
       
    53 	EShellPanicPassword,
       
    54 	};
       
    55 
       
    56 typedef TInt (*DllTestAppEntryPoint)(TAny *aParam);
       
    57 
       
    58 class CShellClient;
       
    59 
       
    60 class RShellWsSession : public RWsSession
       
    61 	{
       
    62 public:
       
    63 	static void Shutdown();
       
    64 	void SendShutdown();
       
    65 	};
       
    66 
       
    67 class MProcessObserver
       
    68 	{
       
    69 public:
       
    70 	virtual void ProcessDied()=0;
       
    71 	};
       
    72 
       
    73 class CRunningProcess : public CActive
       
    74 	{
       
    75 public:
       
    76 	CRunningProcess(MProcessObserver* aObserver);
       
    77 	~CRunningProcess();
       
    78 	void ConstructL(const TDesC& aName);
       
    79 	void ConstructTestExecuteL(const TDesC &aName);
       
    80 	void Link(CRunningProcess** aRpPtr);
       
    81 #if defined(__USING_PROCESS_)
       
    82 	inline RProcess& Process() {return iProcess;}
       
    83 #else
       
    84 	inline RThread& Process() {return iProcess;}
       
    85 #endif
       
    86 private:
       
    87 	virtual void DoCancel();
       
    88 	virtual void RunL();
       
    89 private:
       
    90 #if defined(__WINS__)
       
    91 	RLibrary iLib;
       
    92 #endif
       
    93 #if defined(__USING_PROCESS_)
       
    94 	RProcess iProcess;
       
    95 #else
       
    96 	RThread iProcess;
       
    97 #endif
       
    98 	CRunningProcess* iNext;
       
    99 	CRunningProcess** iPrevPtr;
       
   100 	TParse iFileName;
       
   101 	MProcessObserver* iObserver;
       
   102 	};
       
   103 
       
   104 class CShellErrorDialog : public CTDialog
       
   105 	{		  
       
   106 public:
       
   107 	CShellErrorDialog(CTWindowGroup *aGroupWin,CWindowGc *aGc);
       
   108 	void ButtonPressL(TInt aButton);
       
   109 	void ConstructLD();
       
   110 private:
       
   111 	CTWindowGroup *iGroupWin;
       
   112 	CWindowGc *iGc;
       
   113 	};
       
   114 
       
   115 class CTCalibWindow : public CTWin
       
   116 	{
       
   117 public:
       
   118 	CTCalibWindow();
       
   119 	void InitWin();
       
   120 	void DrawPoint(const TPoint &aPoint, const TDesC &aText);
       
   121 	void Draw();
       
   122 	void PointerL(const TPointerEvent &aPointer,const TTime& aTime);
       
   123 private:
       
   124 	TInt iCount;
       
   125 	TDigitizerCalibration iCalibPoints;
       
   126 	TDigitizerCalibration iReturnValues;
       
   127 	};
       
   128 
       
   129 
       
   130 class CListWindow : public CTTitledWindow
       
   131 	{
       
   132 public:
       
   133 	CListWindow();
       
   134 	void CloseWindow();
       
   135 	void ConstructL(CTWinBase &parent, TBool aExitOnEscape);
       
   136 	void Draw();
       
   137 	virtual void SelectedL(TInt aIndex)=0;
       
   138 	virtual void WinKeyL(const TKeyEvent &aKey,const TTime& aTime);
       
   139 	void SetExt(const TPoint &aPos, const TSize &aSize);
       
   140 	void SetSize(const TSize &);
       
   141 protected:
       
   142 	virtual TPtrC GetText(TInt aLine)=0;
       
   143 	virtual TInt ListCount()=0;
       
   144 	void SetSize();
       
   145 	void PointerL(const TPointerEvent &aPointer,const TTime& aTime);
       
   146 private:
       
   147 	void Resized(const TSize &aSize);
       
   148 	void SetListPos(TInt aNewPos);
       
   149 	TInt TextRowHeight() const;
       
   150 	void RowBox(TRect &aRect, TInt aRow) const;
       
   151 private:
       
   152 	TRgb iColorMap[4];
       
   153 	TInt iListPos;
       
   154 	TTime iPrevTime;
       
   155 	TBool iExitOnEscape;
       
   156 	};
       
   157 
       
   158 class CShellWindow : public CListWindow, public MProcessObserver
       
   159 	{
       
   160 public:
       
   161 	CShellWindow();
       
   162 	~CShellWindow();
       
   163 	void ConstructL(CTWinBase &parent);
       
   164 	TBool RunClientL(const TDesC &aName,TBool aTestExecute);
       
   165 	void SelectedL(TInt aIndex);
       
   166 	virtual void WinKeyL(const TKeyEvent &aKey,const TTime& aTime);
       
   167 	void ForegroundAppDialogL();
       
   168 	void HeapCountDialogL();
       
   169 	void SetPointerZone(TInt aZone);
       
   170 	void SetAutoLaunch(TBool aAutoLaunch);
       
   171 	// Virtual function defined in CTBaseWin and overriden in CListWindow
       
   172 	void PointerL(const TPointerEvent &aPointer,const TTime& aTime);
       
   173 	// Virtual function defined in CTBaseWin and overriden in CTTitledWindow
       
   174 	void FocusChanged(TBool aState);
       
   175 private:
       
   176 	void DoShellTests();
       
   177 	void BugHunt();
       
   178 	void CheckTerminate();
       
   179 	//Pure virtual functions defined in CListWindow
       
   180 	TPtrC GetText(TInt aLine);
       
   181 	TInt ListCount();
       
   182 	//Pure virtual function defined in MProcessObserver
       
   183 	void ProcessDied();
       
   184 	//Simulates SwitchOffEvent
       
   185 	void SimulateSwitchOffEvent();
       
   186 #ifdef SYMBIAN_PROCESS_MONITORING_AND_STARTUP	
       
   187 	//Simulates RestartSystemEvent
       
   188 	void SimulateRestartEvent();
       
   189 	//Simulates RestartSystemEvent and test the receiving of off event
       
   190 	void SimulateAndReceiveRestartEvent();
       
   191 #endif
       
   192 	
       
   193 private:
       
   194 	TBool iFailModeEnabled;
       
   195 	TInt iPointerZone;
       
   196 	CRunningProcess *iProcessList;
       
   197 	CArrayFixFlat<TFileName> iFileNames;
       
   198 	CTPointerCursor *iPointerCursor;
       
   199 	RSoundPlugIn iClick;
       
   200 	TInt iCaptureKey;
       
   201 	TBool iAutoLaunch;
       
   202 	TInt iNumWindowGroups;
       
   203 	TBool iIsFocused;
       
   204 	};
       
   205 
       
   206 class CTIconWindow : public CTBlankWindow
       
   207 	{
       
   208 public:
       
   209 	CTIconWindow(TInt aType);
       
   210 	void InitWinL();
       
   211 	void SetExtentL();
       
   212 private:
       
   213 	TInt iType;
       
   214 	};
       
   215 
       
   216 class CTPasswordWindow: public CTTitledWindow
       
   217 	{
       
   218 public:
       
   219 	CTPasswordWindow();
       
   220 	void InitWin();
       
   221 	void Draw();
       
   222 private:
       
   223 	TPoint iTextPos;
       
   224 	};
       
   225 
       
   226 class CTaskListWindow : public CListWindow
       
   227 	{
       
   228 public:
       
   229 	CTaskListWindow();
       
   230 	void ConstructL(CTWinBase &parent);
       
   231 	void SelectedL(TInt aIndex);
       
   232 private:
       
   233 	virtual TPtrC GetText(TInt aLine);
       
   234 	virtual TInt ListCount();
       
   235 private:
       
   236 	CArrayFixFlat<TInt> iWindowHandles;
       
   237 	CArrayFixFlat<TFullName> iWindowThreadNames;
       
   238 	TBuf<KMaxFullName+KMaxName+2> iLatestText;
       
   239 	};
       
   240 
       
   241 class CShellWindowGroup : public CTWindowGroup
       
   242 	{
       
   243 public:
       
   244 	CShellWindowGroup(CTClient *aClient);
       
   245 	~CShellWindowGroup();
       
   246 	void ConstructL();
       
   247 	void KeyL(const TKeyEvent &aKey,const TTime& aTime);
       
   248 	void ErrorMessage(const TWsErrorMessage &aErrorMessage, const TTime &);
       
   249 	void ScreenDeviceChangedL();
       
   250 private:
       
   251 	TUint32 iCapHandle1;
       
   252 	TUint32 iCapHandle2;
       
   253 	TUint32 iCapHandle3;
       
   254 	TUint32 iCapHandle4;
       
   255 	};
       
   256 
       
   257 class CIconWindowGroup : public CTWindowGroup
       
   258 	{
       
   259 public:
       
   260 	CIconWindowGroup(CTClient *aClient);
       
   261 	void ConstructL();
       
   262 	};
       
   263 
       
   264 class CPasswordWindowGroup : public CTWindowGroup
       
   265 	{
       
   266 public:
       
   267 	CPasswordWindowGroup(CTClient *aClient);
       
   268 	~CPasswordWindowGroup();
       
   269 	void ConstructL();
       
   270 	void KeyL(const TKeyEvent &aKey,const TTime&aTime);
       
   271 	void Cancel();
       
   272 	void PasswordL(const TTime &aTime);
       
   273 private:
       
   274 	CTPasswordWindow *iWin;
       
   275 	TBool iPasswordMode;
       
   276 	};
       
   277 
       
   278 class CShellClient : public CTClient
       
   279 	{
       
   280 public:
       
   281 	CShellClient();
       
   282 	~CShellClient();
       
   283 	void ConstructL();
       
   284 	void KeyL(const TKeyEvent &aKey,const TTime& aTime);
       
   285 	void Exit();
       
   286 	void CreateTestWindowL(CTWin *aWin, const TPoint &aPos);
       
   287 	void CreateTestWindowL(CTWin *win, const TPoint &aPos, CTWinBase *parent);
       
   288 	void ErrorDialog(const TDesC &aTitle, TInt aErr);
       
   289 	void ScreenDeviceChangedL();
       
   290 public:
       
   291 	RFs iFs;
       
   292 private:
       
   293 	TInt iNum;
       
   294 	CTWindowGroup *iIconGroup;
       
   295 	CTIconWindow *iIconWin1;
       
   296 	CTIconWindow *iIconWin2;
       
   297 	CTPointerCursor *iPointerCursor;
       
   298 	CPasswordWindowGroup *iPasswordGroup;
       
   299 	};
       
   300 
       
   301 class ROverrideProtectionInRSessionBase : public RWsSession
       
   302 	{
       
   303 public:
       
   304 	inline TInt Send(TInt aFunction) const {return(RSessionBase::Send(aFunction,TIpcArgs()));};
       
   305 	};
       
   306 
       
   307 const TInt Xmove=8;
       
   308 const TInt Ymove=6;
       
   309 
       
   310 const TInt ENumPointerCursors=2;
       
   311 
       
   312 void DrawShellDragCursor(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *aParam);
       
   313 void DrawShellListCursor(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *aParam);
       
   314 
       
   315 TSpriteCreateParams spriteParams1(TSize(32,32),TPoint(-16,-16),DrawShellListCursor,NULL,EFalse,CGraphicsContext::EDrawModeXOR);
       
   316 TSpriteCreateParams spriteParams2(TSize(32,32),TPoint(-16,-16),DrawShellDragCursor,NULL,ETrue,CGraphicsContext::EDrawModePEN);
       
   317 
       
   318 TSpriteCreateParams *PointerParams[ENumPointerCursors]={&spriteParams1,&spriteParams2};
       
   319 
       
   320 
       
   321 void Panic(TInt aPanic)
       
   322 	{
       
   323 	User::Panic(_L("Shell"),aPanic);
       
   324 	}
       
   325 
       
   326 void RShellWsSession::Shutdown()
       
   327 	{
       
   328 	RShellWsSession ShellSession;
       
   329 	ShellSession.Connect();
       
   330 	ShellSession.SendShutdown();
       
   331 	}
       
   332 
       
   333 void RShellWsSession::SendShutdown()
       
   334 	{
       
   335 	SendReceive(EWservMessShutdown,TIpcArgs(EWservShutdownCheck));
       
   336 	}
       
   337 
       
   338 //
       
   339 // Sprite drawing functions //
       
   340 //
       
   341 
       
   342 void DrawPointerCursor(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *)
       
   343 	{
       
   344 	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 2));
       
   345 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   346 	aGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   347 	aGc->DrawRect(TRect(aSize));
       
   348 	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   349 	aGc->SetPenColor(TRgb::Gray4(3));
       
   350 	aGc->SetBrushColor(TRgb::Gray4(3));
       
   351 	aGc->DrawRect(TRect(0,aSize.iHeight/2-1,aSize.iWidth,aSize.iHeight/2+2));
       
   352 	aGc->DrawRect(TRect(aSize.iWidth/2-1,0,aSize.iWidth/2+2,aSize.iHeight));
       
   353 	if (!aDoMask)
       
   354 		{
       
   355 		aGc->SetPenColor(TRgb::Gray4(0));
       
   356 		aGc->DrawLine(TPoint(0,aSize.iHeight/2),TPoint(aSize.iWidth,aSize.iHeight/2));
       
   357 		aGc->DrawLine(TPoint(aSize.iWidth/2,0),TPoint(aSize.iWidth/2,aSize.iHeight));
       
   358 		}
       
   359 	}
       
   360 
       
   361 void DrawShellDragCursor(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *)
       
   362 	{
       
   363 	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 2));
       
   364 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   365 	aGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   366 	aGc->DrawRect(TRect(aSize));
       
   367 	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   368 	aGc->SetPenColor(TRgb::Gray4(aDoMask ? 3 : 1));
       
   369 	for(TInt y=0;y<aSize.iHeight;y++)
       
   370 		{
       
   371 		TInt xfact=aSize.iWidth*Abs(y-aSize.iHeight/2)/aSize.iHeight;
       
   372 		aGc->DrawLine(TPoint(xfact,y),TPoint(aSize.iWidth-xfact,y));
       
   373 		}
       
   374 	}
       
   375 
       
   376 void DrawShellListCursor(CBitmapContext *aGc,TInt , const TSize &aSize, TBool , TAny *)
       
   377 	{
       
   378 	aGc->SetBrushColor(TRgb::Gray4(0));
       
   379 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   380 	aGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   381 	aGc->DrawRect(TRect(aSize));
       
   382 	aGc->SetBrushColor(TRgb::Gray4(3));
       
   383 	aGc->DrawRect(TRect(0,aSize.iHeight/2-1,aSize.iWidth,aSize.iHeight/2+2));
       
   384 	aGc->DrawRect(TRect(aSize.iWidth/2-1,0,aSize.iWidth/2+2,aSize.iHeight));
       
   385 	}
       
   386 
       
   387 //
       
   388 // Calibration window //
       
   389 //
       
   390 
       
   391 CTCalibWindow::CTCalibWindow()
       
   392 	{
       
   393 	}
       
   394 
       
   395 void CTCalibWindow::InitWin()
       
   396 	{
       
   397 	UserHal::CalibrationPoints(iCalibPoints);
       
   398 	AssignGC(*Client()->iGc);
       
   399 	iWin.SetOrdinalPosition(0,1);
       
   400 	iWin.Activate();
       
   401 	}
       
   402 
       
   403 void CTCalibWindow::DrawPoint(const TPoint &aPoint, const TDesC &aText)
       
   404 	{
       
   405 	iGc->MoveTo(aPoint);
       
   406 	iGc->MoveBy(TPoint(0,-20));
       
   407 	iGc->DrawLineBy(TPoint(0,40));
       
   408 	iGc->MoveBy(TPoint(-20,-20));
       
   409 	iGc->DrawLineBy(TPoint(40,0));
       
   410 	iGc->DrawText(aText, aPoint+TPoint(4,-4));
       
   411 	}
       
   412 
       
   413 void CTCalibWindow::Draw()
       
   414 	{
       
   415 	iGc->Clear();
       
   416 	DrawPoint(iCalibPoints.iTl,_L("1"));
       
   417 	DrawPoint(iCalibPoints.iBl,_L("2"));
       
   418 	DrawPoint(iCalibPoints.iTr,_L("3"));
       
   419 	DrawPoint(iCalibPoints.iBr,_L("4"));
       
   420 	}
       
   421 
       
   422 void CTCalibWindow::PointerL(const TPointerEvent &aPointer,const TTime& )
       
   423 	{
       
   424 	if (aPointer.iType==TPointerEvent::EButton1Down)
       
   425 		{
       
   426 		switch(iCount++)
       
   427 			{
       
   428 			case 0:
       
   429 				iReturnValues.iTl=aPointer.iPosition;
       
   430 				break;
       
   431 			case 1:
       
   432 				iReturnValues.iBl=aPointer.iPosition;
       
   433 				break;
       
   434 			case 2:
       
   435 				iReturnValues.iTr=aPointer.iPosition;
       
   436 				break;
       
   437 			case 3:
       
   438 				iReturnValues.iBr=aPointer.iPosition;
       
   439 				UserHal::SetXYInputCalibration(iReturnValues);
       
   440 				delete this;
       
   441 				break;
       
   442 			}
       
   443 		}
       
   444 	}
       
   445 
       
   446 //
       
   447 // Error dialog //
       
   448 //
       
   449 
       
   450 CShellErrorDialog::CShellErrorDialog(CTWindowGroup *aGroupWin,CWindowGc *aGc) : CTDialog(),
       
   451 	iGroupWin(aGroupWin),
       
   452 	iGc(aGc)
       
   453 	{
       
   454 	}
       
   455 
       
   456 void CShellErrorDialog::ButtonPressL(TInt aButton)
       
   457 	{
       
   458 	if (aButton==0)
       
   459 		CTDialog::ButtonPressL(aButton);
       
   460 	}
       
   461 
       
   462 void CShellErrorDialog::ConstructLD()
       
   463 	{
       
   464 	CTDialog::ConstructLD(*iGroupWin, *iGc);
       
   465 	}
       
   466 
       
   467 //
       
   468 // Offscreen icon->button window //
       
   469 //
       
   470 
       
   471 CTIconWindow::CTIconWindow(TInt aType) : iType(aType)
       
   472 	{
       
   473 	}
       
   474 
       
   475 void CTIconWindow::InitWinL()
       
   476 	{
       
   477 	SetExtentL();
       
   478 	iWin.SetShadowDisabled(ETrue);
       
   479 	Activate();
       
   480 	}
       
   481 
       
   482 void CTIconWindow::SetExtentL()
       
   483 	{
       
   484 	enum {ENumYKeys=5};
       
   485 	enum {ENumXKeys=9};
       
   486 	TRect digRect(Client()->iScreen->PointerRect());
       
   487 	TSize scrSize(Client()->iScreen->SizeInPixels());
       
   488 	TInt ypos=0;
       
   489 	TInt count=0;
       
   490 	iWin.RemoveAllKeyRects();
       
   491 	if (iType==0)
       
   492 		{
       
   493 		for (;count<ENumYKeys;count++)
       
   494 			{
       
   495 			TInt oldypos=ypos;
       
   496 			ypos=digRect.iTl.iY+(count+1)*digRect.Height()/ENumYKeys;
       
   497 			User::LeaveIfError(iWin.AddKeyRect(TRect(0,oldypos,-digRect.iTl.iX,ypos),'A'+count,ETrue));
       
   498 			}
       
   499 		iWin.SetExtent(digRect.iTl,TSize(-digRect.iTl.iX,scrSize.iHeight));
       
   500 		}
       
   501 	else
       
   502 		{
       
   503 		TInt xpos=0;
       
   504 		for (count=0;count<ENumXKeys;count++)
       
   505 			{
       
   506 			TInt oldxpos=xpos;
       
   507 			xpos=digRect.iTl.iY+(count+1)*digRect.Width()/ENumXKeys;
       
   508 			User::LeaveIfError(iWin.AddKeyRect(TRect(oldxpos,0,xpos,digRect.iBr.iY-scrSize.iHeight), EStdKeyF1+count, EFalse));
       
   509 			}
       
   510 		iWin.SetExtent(TPoint(digRect.iTl.iX,scrSize.iHeight),TSize(digRect.Width(),digRect.Height()-scrSize.iHeight));
       
   511 		}
       
   512 	}
       
   513 
       
   514 //
       
   515 // Individual window sub-classes
       
   516 //
       
   517 
       
   518 void CShellClient::ErrorDialog(const TDesC &aTitle, TInt aErr)
       
   519 	{
       
   520 	TBuf<0x20> err;
       
   521 	err.Format(TRefByValue<const TDesC>(_L("Error %d")),aErr);
       
   522 	DisplayDialog(this, aTitle, err,_L(""));
       
   523 	}
       
   524 
       
   525 CListWindow::CListWindow() : CTTitledWindow(), iPrevTime(0)
       
   526 	{
       
   527 	iColorMap[0]=TRgb::Gray4(0);
       
   528 	iColorMap[1]=TRgb::Gray4(3);
       
   529 	iColorMap[2]=TRgb::Gray4(3);
       
   530 	iColorMap[3]=TRgb::Gray4(0);
       
   531 	}
       
   532 
       
   533 void CListWindow::CloseWindow()
       
   534 	{
       
   535 	CTClient *client=((CShellClient *)Client());
       
   536 	CTWin::Delete(this);
       
   537 	client->ResetFocus();
       
   538 	}
       
   539 
       
   540 void CListWindow::SetExt(const TPoint &aPos, const TSize &)
       
   541 	{
       
   542 	SetPos(aPos);
       
   543 	}
       
   544 
       
   545 void CListWindow::SetSize(const TSize &)
       
   546 	{
       
   547 	}
       
   548 
       
   549 void CListWindow::SetSize()
       
   550 	{
       
   551 	iSize.iHeight=ListCount()*(iFont->HeightInPixels()+1)+iTitleHeight+2;
       
   552 	iSize.iWidth=iFont->TextWidthInPixels(*Client()->Title())+30;
       
   553 	for(TInt index=0;index<ListCount();index++)
       
   554 		{
       
   555 		TInt wid=iFont->TextWidthInPixels(GetText(index));
       
   556 		if (wid>iSize.iWidth)
       
   557 			iSize.iWidth=wid;
       
   558 		}
       
   559 	iSize.iWidth+=4;
       
   560 	iWin.SetSize(iSize);
       
   561 	Resized(iSize);
       
   562 	}
       
   563 
       
   564 void CListWindow::ConstructL(CTWinBase &parent, TBool aExitOnEscape)
       
   565 	{
       
   566 	iExitOnEscape=aExitOnEscape;
       
   567 	CTTitledWindow::ConstructL(parent);
       
   568 	}
       
   569 
       
   570 void CListWindow::SetListPos(TInt aNewPos)
       
   571 	{
       
   572 	if (aNewPos>=0 && aNewPos<ListCount())
       
   573 		{
       
   574 		iListPos=aNewPos;
       
   575 		Invalidate();
       
   576 		}
       
   577 	}
       
   578 
       
   579 void CListWindow::WinKeyL(const TKeyEvent &aKey, const TTime&)
       
   580 	{
       
   581 	switch(aKey.iCode)
       
   582 		{
       
   583 		case EKeyUpArrow:
       
   584 			SetListPos(iListPos-1);
       
   585 			break;
       
   586 		case EKeyDownArrow:
       
   587 			SetListPos(iListPos+1);
       
   588 			break;
       
   589 		case EKeyEnter:
       
   590 			SelectedL(iListPos);
       
   591 			break;
       
   592 		case EKeyEscape:		// Fall through from EKeyEnter
       
   593 			if (iExitOnEscape)
       
   594 				CloseWindow();
       
   595 			break;
       
   596 		}
       
   597 	}
       
   598 
       
   599 void CListWindow::PointerL(const TPointerEvent &aPointer,const TTime& aTime)
       
   600 	{
       
   601 	if (aPointer.iType==TPointerEvent::EButton1Down)
       
   602 		{
       
   603 		TRect rect;
       
   604 		for(TInt index=0;index<ListCount();index++)
       
   605 			{
       
   606 			RowBox(rect,index);
       
   607 			if (rect.Contains(aPointer.iPosition))
       
   608 				{
       
   609 				if (index==iListPos && (aPointer.iModifiers&EModifierDoubleClick /*|| index<=INDEX_FOR_SHELL_TEST*/))
       
   610 					SelectedL(iListPos);
       
   611 				else
       
   612 					{
       
   613 					iPrevTime=aTime;
       
   614 					SetListPos(index);
       
   615 					}
       
   616 				return;
       
   617 				}
       
   618 			}
       
   619 		}
       
   620 	CTTitledWindow::PointerL(aPointer,aTime);
       
   621 	}
       
   622 
       
   623 TInt CListWindow::TextRowHeight() const
       
   624 	{
       
   625 	return(iFont->HeightInPixels()+1);
       
   626 	}
       
   627 
       
   628 void CListWindow::RowBox(TRect &aRect, TInt aRow) const
       
   629 	{
       
   630 	aRect.iTl.iX=2;
       
   631 	aRect.iTl.iY=iTitleHeight+TextRowHeight()*aRow;
       
   632 	aRect.iBr.iX=iSize.iWidth-2;
       
   633 	aRect.iBr.iY=aRect.iTl.iY+TextRowHeight();
       
   634 	}
       
   635 
       
   636 void CListWindow::Draw()
       
   637 	{
       
   638 	CTTitledWindow::Draw();
       
   639 	iGc->SetPenColor(TRgb::Gray16(0));
       
   640 	TPoint pos(2,iTitleHeight+iFont->AscentInPixels()+2);
       
   641 	TInt gap=TextRowHeight();
       
   642 	for(TInt index=0;index<ListCount();index++,pos.iY+=gap)
       
   643 		{
       
   644 		iGc->DrawText(GetText(index), pos);
       
   645 		if (index==iListPos)
       
   646 			{
       
   647 			TRect rect;
       
   648 			RowBox(rect,index);
       
   649 			iGc->MapColors(rect,iColorMap);
       
   650 			}
       
   651 		}
       
   652 	}
       
   653 
       
   654 void CListWindow::Resized(const TSize &aSize)
       
   655 	{
       
   656 	SetDragRect(TRect(0,0,aSize.iWidth,iTitleHeight));
       
   657 	}
       
   658 
       
   659 //
       
   660 // CShellWindow class //
       
   661 //
       
   662 
       
   663 CShellWindow::CShellWindow() : CListWindow(), iFileNames(4)
       
   664 	{
       
   665 	}
       
   666 
       
   667 CShellWindow::~CShellWindow()
       
   668 	{
       
   669 	if (iCaptureKey)
       
   670 		Client()->iGroup->GroupWin()->CancelCaptureKey(iCaptureKey);
       
   671 	delete iPointerCursor;
       
   672 	while(iProcessList)
       
   673 		delete iProcessList;
       
   674 	}
       
   675 
       
   676 void CShellWindow::SetPointerZone(TInt aZone)
       
   677 	{
       
   678 	TRAPD(err,iPointerCursor->UpdateL(0, PointerParams[aZone]));
       
   679 	if (err!=KErrNone)
       
   680 		((CShellClient *)Client())->ErrorDialog(_L("Error Changing Pointer"), err);
       
   681 	else
       
   682 		iPointerZone=aZone;
       
   683 	}
       
   684 
       
   685 void CShellWindow::SetAutoLaunch(TBool aAutoLaunch)
       
   686 	{
       
   687 	iAutoLaunch=aAutoLaunch;
       
   688 	if (aAutoLaunch)
       
   689 		iNumWindowGroups=Client()->iWs.NumWindowGroups();
       
   690 	}
       
   691 
       
   692 void CShellWindow::PointerL(const TPointerEvent &aPointer,const TTime& aTime)
       
   693 	{
       
   694 	TInt zone=(aPointer.iPosition.iY<iTitleHeight) ? 1 : 0;
       
   695 	if (iPointerZone!=zone)
       
   696 		SetPointerZone(zone);
       
   697 	CListWindow::PointerL(aPointer,aTime);
       
   698 	}
       
   699 
       
   700 void CShellWindow::ConstructL(CTWinBase &parent)
       
   701 	{
       
   702 	CListWindow::ConstructL(parent, EFalse);
       
   703 	RFile dllList;
       
   704 	RProcess thisProc;
       
   705 	TParse dllListFileName;
       
   706 #if defined(__USING_PROCESS_)
       
   707 	TFileName fName(thisProc.FileName());
       
   708 	User::LeaveIfError(dllListFileName.Set(_L("\\SYSTEM\\DATA\\DLL_LIST.TXT"),&fName,NULL));
       
   709 	User::LeaveIfError(dllList.Open(((CShellClient *)Client())->iFs,dllListFileName.FullName(),EFileShareReadersOnly|EFileStreamText));
       
   710 #else
       
   711 	User::LeaveIfError(dllList.Open(((CShellClient *)Client())->iFs,_L("Z:\\SYSTEM\\DATA\\DLL_LIST.TXT"),EFileShareReadersOnly|EFileStreamText));
       
   712 #endif
       
   713 	TBuf8<0x200> dllNames;
       
   714 	User::LeaveIfError(dllList.Read(dllNames));
       
   715 	dllList.Close();
       
   716 	TPtrC8 name(dllNames);
       
   717 	FOREVER
       
   718 		{
       
   719 		TInt pos=name.Locate('\r');
       
   720 		if (pos==KErrNotFound)
       
   721 			break;
       
   722 		if (pos<=KMaxFileName)
       
   723 			{
       
   724 			TFileName buf;
       
   725 			buf.Copy(name.Left(pos));
       
   726 			iFileNames.AppendL(buf);
       
   727 			}
       
   728 		name.Set(name.Mid(pos+2));
       
   729 		};
       
   730 	SetSize();
       
   731 	BaseWin()->PointerFilter(EPointerFilterMove|EPointerFilterDrag,0);
       
   732 	iPointerCursor=new(ELeave) CTPointerCursor(Client()->iWs);
       
   733 	iPointerCursor->ConstructL(0);
       
   734 	SetPointerZone(0);
       
   735 	iWin.SetCustomPointerCursor(iPointerCursor->PointerCursor());
       
   736 	iClick=RSoundPlugIn(Client()->iWs);
       
   737 	User::LeaveIfError(iClick.Construct(TUid::Uid(CLICK_THIRD_UID)));
       
   738 	TBool isChangeAble;
       
   739 	if (iClick.IsLoaded(isChangeAble))
       
   740 		{
       
   741 		TInt ret=Client()->iGroup->GroupWin()->CaptureKey(3,EModifierCtrl|EModifierShift|EModifierFunc
       
   742 																	,EModifierCtrl|EModifierShift|EModifierFunc);	//Ctrl-Alt-Shift-C
       
   743 		User::LeaveIfError(ret);
       
   744 		iCaptureKey=ret;
       
   745 		}
       
   746 	}
       
   747 
       
   748 TBool CShellWindow::RunClientL(const TDesC &aName,TBool aTestExecute)
       
   749 	{
       
   750 	if (aName.Length()!=0)
       
   751 		{
       
   752 		CRunningProcess* rp=new(ELeave) CRunningProcess(this);
       
   753 		rp->Link(&iProcessList);
       
   754 		CActiveScheduler::Add(rp);
       
   755 		TInt err=KErrNone;		//To stop a warning
       
   756 		if (aTestExecute)
       
   757 			{
       
   758 			TRAP(err,rp->ConstructTestExecuteL(aName));
       
   759 			}
       
   760 		else
       
   761 			{
       
   762 			TRAP(err,rp->ConstructL(aName));
       
   763 			}
       
   764 		if (err!=KErrNone)
       
   765 			{
       
   766 			delete rp;
       
   767 			User::Leave(err);
       
   768 			}
       
   769 		return ETrue;
       
   770 		}
       
   771 	return EFalse;
       
   772 	}
       
   773 
       
   774 void CShellWindow::SelectedL(TInt aIndex)
       
   775 	{
       
   776 	TPtrC name=GetText(aIndex);
       
   777 	if (aIndex==INDEX_FOR_SHELL_TEST && name==SHELL_TEST_NAME)
       
   778 		{
       
   779 		DoShellTests();
       
   780 		return;
       
   781 		}
       
   782 #ifdef SYMBIAN_PROCESS_MONITORING_AND_STARTUP		
       
   783 	else if (aIndex==INDEX_FOR_RESTART_TEST && name==RESTART_TEST_NAME)
       
   784 		{
       
   785 		SimulateRestartEvent();
       
   786 		return;
       
   787 		}
       
   788 	else if (aIndex==INDEX_FOR_RESTART_EVENT_TEST && name==RESTART_EVENT_TEST_NAME)
       
   789 		{
       
   790 		SimulateAndReceiveRestartEvent();
       
   791 		return;
       
   792 		}
       
   793 #endif		
       
   794 	TRAPD(err,RunClientL(GetText(aIndex),EFalse));
       
   795 	if (err==KErrNotFound)
       
   796 		{
       
   797 		TRAP(err,RunClientL(GetText(aIndex),ETrue));
       
   798 		}
       
   799 	if (err!=KErrNone)
       
   800 		((CShellClient *)Client())->ErrorDialog(_L("Error launching process"), err);
       
   801 	}
       
   802 
       
   803 TPtrC CShellWindow::GetText(TInt aLine)
       
   804 	{
       
   805 	return(TPtrC(iFileNames[aLine]));
       
   806 	}
       
   807 
       
   808 TInt CShellWindow::ListCount()
       
   809 	{
       
   810 	return(iFileNames.Count());
       
   811 	}
       
   812 
       
   813 void CShellWindow::ForegroundAppDialogL()
       
   814 	{
       
   815 	TInt focusGroup;
       
   816 	TName winName;
       
   817 	TThreadId threadId;
       
   818 	User::LeaveIfError(focusGroup=Client()->iWs.GetFocusWindowGroup());
       
   819 	User::LeaveIfError(Client()->iWs.GetWindowGroupClientThreadId(focusGroup, threadId));
       
   820 	User::LeaveIfError(Client()->iWs.GetWindowGroupNameFromIdentifier(focusGroup,winName));
       
   821 	RThread thread;
       
   822 	User::LeaveIfError(thread.Open(threadId));
       
   823 	CShellErrorDialog *dialog=new(ELeave) CShellErrorDialog(Client()->iGroup, iGc);
       
   824 	dialog->ConstructLD();
       
   825 	dialog->SetTitle(_L("The Foreground App Is"));
       
   826 	dialog->SetLine1(thread.FullName());
       
   827 	thread.Close();
       
   828 	dialog->SetLine2(winName);
       
   829 	dialog->SetNumButtons(1);
       
   830 	dialog->SetButtonText(0,_L("Okay"));
       
   831 	if (dialog->Display()!=0)
       
   832 		Panic(0);
       
   833 	dialog=NULL;
       
   834 	}
       
   835 
       
   836 void CShellWindow::HeapCountDialogL()
       
   837 	{
       
   838 	CShellErrorDialog *dialog=new(ELeave) CShellErrorDialog(Client()->iGroup, iGc);
       
   839 	dialog->ConstructLD();
       
   840 	dialog->SetTitle(_L("Wserv Heap Count"));
       
   841 	TBuf<0x20> line1;
       
   842 	line1.Format(TRefByValue<const TDesC>(_L("Count=%d")),Client()->iWs.HeapCount());
       
   843 	dialog->SetLine1(line1);
       
   844 	dialog->SetNumButtons(1);
       
   845 	dialog->SetButtonText(0,_L("Okay"));
       
   846 	if (dialog->Display()!=0)
       
   847 		Panic(0);
       
   848 	dialog=NULL;
       
   849 	}
       
   850 
       
   851 void CShellWindow::WinKeyL(const TKeyEvent &aKey,const TTime& aTime)
       
   852 	{
       
   853 	TBool funcKeyPressed=aKey.iModifiers&EModifierFunc;
       
   854 	if (aKey.iModifiers&EModifierCtrl)
       
   855 		{
       
   856 		switch(aKey.iCode)
       
   857 			{
       
   858 			case EKeyLeftArrow:
       
   859 				{
       
   860 				TInt col=Client()->iWs.GetBackgroundColor().Gray16();
       
   861 				if (col>0)
       
   862 					Client()->iWs.SetBackgroundColor(TRgb::Gray16(col-1));
       
   863 				}
       
   864 				break;
       
   865 			case EKeyRightArrow:
       
   866 				{
       
   867 				TInt col=Client()->iWs.GetBackgroundColor().Gray16();
       
   868 				if (col<15)
       
   869 					Client()->iWs.SetBackgroundColor(TRgb::Gray16(col+1));
       
   870 				}
       
   871 				break;
       
   872 			case EKeyTab:
       
   873 				if (funcKeyPressed)
       
   874 					ForegroundAppDialogL();
       
   875 				else
       
   876 					{
       
   877 					Group()->GroupWin()->SetOrdinalPosition(0);
       
   878 					((CShellClient *)Client())->CreateTestWindowL(new(ELeave) CTaskListWindow(), TPoint(50,30));
       
   879 					Client()->ResetFocus();
       
   880 					}
       
   881 				break;
       
   882 			case 1:		//Ctrl-A
       
   883 			case 17:	//Ctrl-Q
       
   884 				SetPos(TPoint(3,(Client()->iScreen->SizeInPixels().iHeight-Size().iHeight)/2));
       
   885 				break;
       
   886 			case 2:		//Ctrl-B
       
   887 			case 23:	//Ctrl-W
       
   888 				SetPos(TPoint((Client()->iScreen->SizeInPixels().iWidth-Size().iWidth)/2,(Client()->iScreen->SizeInPixels().iHeight-Size().iHeight)/2));
       
   889 				break;
       
   890 			case 3:		//Ctrl-C
       
   891 			case 5:		//Ctrl-E
       
   892 				if (funcKeyPressed && aKey.iModifiers&EModifierShift && aKey.iCode==3)			//Ctrl-Alt-Sh-C
       
   893 					iClick.CommandReply(EClickCommandToggleOutput,TPtrC8(NULL,0));
       
   894 				else
       
   895 					SetPos(TPoint(Client()->iScreen->SizeInPixels().iWidth-Size().iWidth-3,(Client()->iScreen->SizeInPixels().iHeight-Size().iHeight)/2));
       
   896 				break;
       
   897 			case 18:	//Ctrl-R
       
   898 				{
       
   899 				CWsScreenDevice* screen=Client()->iScreen;
       
   900 				TPixelsAndRotation sizeAndRotation;
       
   901 				screen->GetScreenModeSizeAndRotation(0,sizeAndRotation);
       
   902 				Client()->iWs.SetPointerCursorArea(0,TRect(sizeAndRotation.iPixelSize));
       
   903 				screen->SetCurrentRotations(0,CFbsBitGc::EGraphicsOrientationNormal);
       
   904 				screen->SetScreenMode(0);
       
   905 				CArrayFixFlat<TInt> *rotations=new(ELeave) CArrayFixFlat<TInt>(1);
       
   906 				CleanupStack::PushL(rotations);
       
   907 				TInt numModes=screen->NumScreenModes();
       
   908 				TInt ii,err;
       
   909 				for (ii=1;ii<numModes;++ii)
       
   910 					{
       
   911 					err=screen->GetRotationsList(ii,rotations);
       
   912 					if (err==KErrNone)
       
   913 						screen->SetCurrentRotations(ii,REINTERPRET_CAST(CFbsBitGc::TGraphicsOrientation&,(*rotations)[0]));
       
   914 					}
       
   915 				CleanupStack::PopAndDestroy();
       
   916 				}
       
   917 				break;
       
   918 			default:
       
   919 				goto not_used;
       
   920 			}
       
   921 		}
       
   922 	else if (funcKeyPressed)
       
   923 		{
       
   924 		switch(aKey.iCode)
       
   925 			{
       
   926 			case 'c':
       
   927 				{
       
   928 				CTCalibWindow *win=new(ELeave) CTCalibWindow();
       
   929 				win->ConstructL(*Client()->iGroup);
       
   930 				}
       
   931 				break;
       
   932 			case 's':	// Sleep
       
   933 				User::After(2000000);
       
   934 				break;
       
   935 			case 'd':
       
   936 				DisplayDialog(_L("Dialog test"),_L("Line of text"),_L(""));
       
   937 				break;
       
   938 			case 'o':
       
   939 				UserHal::SwitchOff();
       
   940 				break;
       
   941 			case 'f':
       
   942 				if (iFailModeEnabled)
       
   943 					((CShellClient *)Client())->iWs.HeapSetFail(RHeap::ENone,0);
       
   944 				else
       
   945 					((CShellClient *)Client())->iWs.HeapSetFail(RHeap::ERandom,20);
       
   946 				iFailModeEnabled=!iFailModeEnabled;
       
   947 				break;
       
   948 			case 'x':
       
   949 			case 'X':
       
   950 				if (aKey.iModifiers&EModifierShift)
       
   951 					RShellWsSession::Shutdown();
       
   952 				else
       
   953 					((CShellClient *)Client())->Exit();
       
   954 				break;
       
   955 			case 'l':
       
   956 				Client()->iWs.LogMessage(_L("Hello, this is log test"));
       
   957 				break;
       
   958 			case 'h':
       
   959 				HeapCountDialogL();
       
   960 				break;
       
   961 			case 'b':
       
   962 				BugHunt();
       
   963 				break;
       
   964 			case EKeyLeftArrow:
       
   965 				AdjustSize(-Xmove,0,aKey.iModifiers);
       
   966 				break;
       
   967 			case EKeyRightArrow:
       
   968 				AdjustSize(Xmove,0,aKey.iModifiers);
       
   969 				break;
       
   970 			case EKeyUpArrow:
       
   971 				AdjustSize(0,-Ymove,aKey.iModifiers);
       
   972 				break;
       
   973 			case EKeyDownArrow:
       
   974 				AdjustSize(0,Ymove,aKey.iModifiers);
       
   975 				break;
       
   976 			default:
       
   977 				goto not_used;
       
   978 			}
       
   979 		}
       
   980 	else
       
   981 		goto not_used;
       
   982 	return;
       
   983 not_used:
       
   984 	CListWindow::WinKeyL(aKey,aTime);
       
   985 	}
       
   986 
       
   987 void CShellWindow::FocusChanged(TBool aState)
       
   988 	{
       
   989 	CListWindow::FocusChanged(aState);
       
   990 	iIsFocused=aState;
       
   991 	CheckTerminate();
       
   992 	}
       
   993 
       
   994 void CShellWindow::DoShellTests()
       
   995 //
       
   996 //Doing testing that can only be done from the shell
       
   997 //
       
   998 	{
       
   999 	/*Group()->GroupWin()->EnableReceiptOfFocus(EFalse);
       
  1000 	BaseWin()->SetSizeErr(TSize(160,220));
       
  1001 	Group()->GroupWin()->EnableReceiptOfFocus(ETrue);
       
  1002 	*/
       
  1003 	SimulateSwitchOffEvent();
       
  1004 	}
       
  1005 
       
  1006 /**
       
  1007 Sends the raw events to the current registered window session.
       
  1008 Since no Window Group is allowed to request the off events,
       
  1009 WServ shall handle these raw events.
       
  1010 */
       
  1011 void CShellWindow::SimulateSwitchOffEvent()
       
  1012 	{
       
  1013 	TRawEvent rawEvent;
       
  1014 	rawEvent.Set(TRawEvent::ESwitchOff);
       
  1015 	Client()->iWs.SimulateRawEvent(rawEvent);
       
  1016 	Client()->iWs.Flush();
       
  1017 	}	
       
  1018 
       
  1019 #ifdef SYMBIAN_PROCESS_MONITORING_AND_STARTUP	
       
  1020 /**
       
  1021 @SYMTestCaseID 			GRAPHICS-WSERV-0404
       
  1022 @SYMTestCaseDesc 		Restart system event can be successfully sent through WServ
       
  1023 @SYMPREQ				PREQ1089
       
  1024 @SYMREQ					REQ6883
       
  1025 @SYMTestStatus			Implemented
       
  1026 @SYMTestPriority		High
       
  1027 @SYMTestPurpose			Test restart system event in WServ
       
  1028 @SYMTestActions			The test code will simulate a 'restart event'.
       
  1029 @SYMTestExpectedResults	The system should restart (manually observed).
       
  1030 */
       
  1031 void CShellWindow::SimulateRestartEvent()
       
  1032 	{
       
  1033 	TRawEvent rawEvent;
       
  1034 	rawEvent.Set(TRawEvent::ERestartSystem);
       
  1035 	Client()->iWs.SimulateRawEvent(rawEvent);
       
  1036 	Client()->iWs.Flush();
       
  1037 	}
       
  1038 
       
  1039 /**
       
  1040 @SYMTestCaseID 			GRAPHICS-WSERV-0405
       
  1041 @SYMTestCaseDesc 		Restart system event can be received by client that have registered for off event
       
  1042 @SYMPREQ				PREQ1089
       
  1043 @SYMREQ					REQ6883
       
  1044 @SYMTestStatus			Implemented
       
  1045 @SYMTestPriority		High
       
  1046 @SYMTestPurpose			Test restart system event in WServ with off event handler
       
  1047 @SYMTestActions			The test code will register for off event, simulate a 'restart event' and then receive the restart event
       
  1048 @SYMTestExpectedResults	Verify that the restart event is received and the testPass dialog displayed for this test (manually observed).
       
  1049 */
       
  1050 void CShellWindow::SimulateAndReceiveRestartEvent()
       
  1051 	{
       
  1052 	const TInt KEventWaitTimer = 5000000; // 5 sec, The wait time that this test will wait for the restart event before declaring this test fail
       
  1053 	TInt err = Client()->iWs.RequestOffEvents(ETrue, Client()->iGroup->GroupWin());
       
  1054 	if (err != KErrNone)
       
  1055 		{
       
  1056 		static_cast<CShellClient *>(Client())->ErrorDialog(_L("Failed to request off event"),err);
       
  1057 		}
       
  1058 
       
  1059 	TRawEvent rawEvent;
       
  1060 	rawEvent.Set(TRawEvent::ERestartSystem);
       
  1061 	Client()->iWs.SimulateRawEvent(rawEvent);
       
  1062 
       
  1063 	TRequestStatus status;
       
  1064 	Client()->iWs.EventReady(&status);
       
  1065 	Client()->iWs.Flush();
       
  1066 	User::WaitForRequest(status);
       
  1067 
       
  1068 	TWsEvent event;
       
  1069 	RTimer timer;
       
  1070 	timer.CreateLocal();
       
  1071 	TRequestStatus timerStatus;
       
  1072 	timer.After(timerStatus,KEventWaitTimer);
       
  1073 	TBool testPass=EFalse;
       
  1074 	while (timerStatus != KErrNone) // wait for the restart event until timer expire
       
  1075 		{
       
  1076 		Client()->iWs.GetEvent(event);
       
  1077 		if (event.Type() == EEventRestartSystem)
       
  1078 			{
       
  1079 			timer.Cancel();
       
  1080 			User::WaitForRequest(timerStatus); // to receive the cancel event
       
  1081 
       
  1082 			testPass = ETrue;
       
  1083 			_LIT(KTestPass,"TestPassed");
       
  1084 			TWindowTitle winTitle(KTestPass);
       
  1085 			DisplayDialog(Client(), winTitle, _L("Received Restart Event"), KNullDesC);
       
  1086 			break;
       
  1087 			}
       
  1088 
       
  1089 		// probably got pointer event above instead of restart event, so try getting the next event until we see retart event
       
  1090 		Client()->iWs.EventReady(&status);
       
  1091 		User::WaitForRequest(status, timerStatus);
       
  1092 		}
       
  1093 
       
  1094 	if (testPass == EFalse)
       
  1095 		{
       
  1096 		// timer expired before getting restart event
       
  1097 		_LIT(KTestPass,"TestFailed");
       
  1098 		TWindowTitle winTitle(KTestPass);
       
  1099 		DisplayDialog(Client(), winTitle, _L("Did not receive Restart Event"), KNullDesC);
       
  1100 		}
       
  1101 
       
  1102 	timer.Close();
       
  1103 
       
  1104 	Client()->iWs.RequestOffEvents(EFalse);
       
  1105 	}
       
  1106 
       
  1107 #endif		
       
  1108 
       
  1109 void CShellWindow::BugHunt()
       
  1110 //
       
  1111 // Attempt to reproduce messaging issue while program exiting with message outstanding
       
  1112 //
       
  1113 	{
       
  1114 	RThread().SetPriority(EPriorityRealTime);
       
  1115 	((ROverrideProtectionInRSessionBase *)&(Client()->iWs))->Send(1);
       
  1116 	RThread().Kill(0);
       
  1117 	}
       
  1118 
       
  1119 void CShellWindow::CheckTerminate()
       
  1120 	{
       
  1121 	if (iIsFocused && iAutoLaunch && iProcessList==NULL && iNumWindowGroups==Client()->iWs.NumWindowGroups())
       
  1122 		{
       
  1123 #if defined(__WINS__)
       
  1124 		delete this;
       
  1125 		RShellWsSession::Shutdown();
       
  1126 #else 
       
  1127 		// on hardware for automated test purposes cause board to crash to 
       
  1128 		// indicate the completion of test run
       
  1129 		User::SetCritical(User::ESystemCritical);
       
  1130 		User::Panic(_L("test"), KErrGeneral);
       
  1131 #endif
       
  1132 		}
       
  1133 	}
       
  1134 
       
  1135 void CShellWindow::ProcessDied()
       
  1136 	{
       
  1137 	CheckTerminate();
       
  1138 	}
       
  1139 
       
  1140 //
       
  1141 // End of CShellWindow class //
       
  1142 //
       
  1143 
       
  1144 //
       
  1145 // CTaskListWindow class //
       
  1146 //
       
  1147 
       
  1148 CTaskListWindow::CTaskListWindow() : CListWindow(), iWindowHandles(4), iWindowThreadNames(4)
       
  1149 	{
       
  1150 	}
       
  1151 
       
  1152 void CTaskListWindow::ConstructL(CTWinBase &parent)
       
  1153 	{
       
  1154 	CListWindow::ConstructL(parent,ETrue);
       
  1155 	User::LeaveIfError(Client()->iWs.WindowGroupList(0,&iWindowHandles));
       
  1156 	for(TInt index=0;index<iWindowHandles.Count();index++)
       
  1157 		{
       
  1158 		TThreadId id;
       
  1159 		Client()->iWs.GetWindowGroupClientThreadId(iWindowHandles[index],id);
       
  1160 		RThread thread;
       
  1161 		User::LeaveIfError(thread.Open(id));
       
  1162 		iWindowThreadNames.AppendL(thread.FullName());
       
  1163 		thread.Close();
       
  1164 		}
       
  1165 	SetSize();
       
  1166 	}
       
  1167 
       
  1168 void CTaskListWindow::SelectedL(TInt aIndex)
       
  1169 	{
       
  1170 	Client()->iWs.SetWindowGroupOrdinalPosition(iWindowHandles[aIndex], 0);
       
  1171 	CloseWindow();
       
  1172 	}
       
  1173 
       
  1174 TPtrC CTaskListWindow::GetText(TInt aLine)
       
  1175 	{
       
  1176 	iLatestText=iWindowThreadNames[aLine];
       
  1177 	iLatestText.Append(_L("::"));
       
  1178 	TName winName;
       
  1179 	if (Client()->iWs.GetWindowGroupNameFromIdentifier(iWindowHandles[aLine],winName)==KErrNone)
       
  1180 		iLatestText.Append(winName);
       
  1181 	return(iLatestText);
       
  1182 	}
       
  1183 
       
  1184 TInt CTaskListWindow::ListCount()
       
  1185 	{
       
  1186 	return(iWindowHandles.Count());
       
  1187 	}
       
  1188 //
       
  1189 // End of CTaskListWindow class //
       
  1190 //
       
  1191 
       
  1192 CShellWindowGroup::CShellWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
       
  1193 	{
       
  1194 	}
       
  1195 
       
  1196 CShellWindowGroup::~CShellWindowGroup()
       
  1197 	{
       
  1198 	iGroupWin.CancelCaptureKey(iCapHandle1);
       
  1199 	iGroupWin.CancelCaptureKey(iCapHandle2);
       
  1200 	iGroupWin.CancelCaptureKey(iCapHandle3);
       
  1201 	iGroupWin.CancelCaptureKey(iCapHandle4);
       
  1202 	}
       
  1203 
       
  1204 void CShellWindowGroup::ConstructL()
       
  1205 	{
       
  1206 	CTWindowGroup::ConstructL();
       
  1207 	iCapHandle1=User::LeaveIfError(iGroupWin.CaptureKey(EKeyTab, EModifierCtrl|EModifierShift|EModifierPureKeycode,EModifierCtrl|EModifierShift|EModifierPureKeycode));
       
  1208 	iGroupWin.DefaultOwningWindow();
       
  1209 	iGroupWin.EnableErrorMessages(EEventControlOnlyWithKeyboardFocus);
       
  1210 	iGroupWin.EnableScreenChangeEvents();
       
  1211 	}
       
  1212 
       
  1213 void CShellWindowGroup::KeyL(const TKeyEvent &aKey,const TTime& aTime)
       
  1214 	{
       
  1215 	if (iCurWin)
       
  1216 		iCurWin->WinKeyL(aKey,aTime);
       
  1217 	}
       
  1218 
       
  1219 void CShellWindowGroup::ErrorMessage(const TWsErrorMessage &aErrorMessage, const TTime &)
       
  1220 	{
       
  1221 	TBuf<0x40> errorText;
       
  1222 	switch(aErrorMessage.iErrorCategory)
       
  1223 		{
       
  1224 		case TWsErrorMessage::EDrawingRegion:
       
  1225 			{
       
  1226 			_LIT(Graphics,"Graphics %d");
       
  1227 			errorText.Format(Graphics,aErrorMessage.iError);
       
  1228 			}
       
  1229 			break;
       
  1230 		case TWsErrorMessage::EBackLight:
       
  1231 			{
       
  1232 			_LIT(Backlight,"Backlight %d");
       
  1233 			errorText.Format(Backlight,aErrorMessage.iError);
       
  1234 			}
       
  1235 			break;
       
  1236 		case TWsErrorMessage::ELogging:
       
  1237 			{
       
  1238 			_LIT(Logging,"Error Starting Logging: %d, Location: %d");
       
  1239 			// minus the error value is stored in the bottom 8 bits
       
  1240 			// an indication of position in the code, that the error occured in, is stored in the top 24 bits
       
  1241 			TInt line=(aErrorMessage.iError)&0xFFFFFF00;
       
  1242 			errorText.Format(Logging,line-aErrorMessage.iError,line>>8);
       
  1243 			}
       
  1244 			break;
       
  1245 		case TWsErrorMessage::EContrast:
       
  1246 			{
       
  1247 			_LIT(Contrast,"Contrast %d");
       
  1248 			errorText.Format(Contrast,aErrorMessage.iError);
       
  1249 			}
       
  1250 			break;
       
  1251 		default:
       
  1252 			{
       
  1253 			_LIT(Unknown,"Unknown %d");
       
  1254 			errorText.Format(Unknown,aErrorMessage.iError);
       
  1255 			}
       
  1256 			break;
       
  1257 		}
       
  1258 	_LIT(WservError,"Wserv error");
       
  1259 	TWindowTitle winTitle(WservError);
       
  1260 	DisplayDialog(Client(), winTitle, errorText, KNullDesC);
       
  1261 	}
       
  1262 
       
  1263 void CShellWindowGroup::ScreenDeviceChangedL()
       
  1264 	{
       
  1265 	TPixelsTwipsAndRotation sizeAndRotation;
       
  1266 	Client()->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation);
       
  1267 	Client()->iScreen->SetScreenSizeAndRotation(sizeAndRotation);
       
  1268 	((CShellClient *)Client())->ScreenDeviceChangedL();
       
  1269 	}
       
  1270 
       
  1271 //
       
  1272 
       
  1273 CIconWindowGroup::CIconWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
       
  1274 	{
       
  1275 	}
       
  1276 
       
  1277 void CIconWindowGroup::ConstructL()
       
  1278 	{
       
  1279 	CTWindowGroup::ConstructL();
       
  1280 	iGroupWin.EnableReceiptOfFocus(EFalse);
       
  1281 	iGroupWin.SetOrdinalPosition(0,100);
       
  1282 	}
       
  1283 
       
  1284 //
       
  1285 // password window //
       
  1286 //
       
  1287 
       
  1288 CTPasswordWindow::CTPasswordWindow()
       
  1289 	{
       
  1290 	}
       
  1291 
       
  1292 void CTPasswordWindow::InitWin()
       
  1293 	{
       
  1294 	TInt wid=iFont->TextWidthInPixels(_L("Press Enter"));
       
  1295 	iTextPos.iX=(iWin.Size().iWidth-wid)/2;
       
  1296 	iTextPos.iY=(iWin.Size().iHeight)/2;
       
  1297 	}
       
  1298 
       
  1299 void CTPasswordWindow::Draw()
       
  1300 	{
       
  1301 	CTTitledWindow::Draw();
       
  1302 	iGc->DrawText(_L("Press Enter"),iTextPos);
       
  1303 	}
       
  1304 
       
  1305 //
       
  1306 
       
  1307 CPasswordWindowGroup::CPasswordWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
       
  1308 	{
       
  1309 	}
       
  1310 
       
  1311 CPasswordWindowGroup::~CPasswordWindowGroup()
       
  1312 	{
       
  1313 	delete iWin;
       
  1314 	}
       
  1315 
       
  1316 void CPasswordWindowGroup::PasswordL(const TTime &)
       
  1317 	{
       
  1318 	__ASSERT_DEBUG(!iPasswordMode,Panic(EShellPanicPassword));
       
  1319 	iPasswordMode=ETrue;
       
  1320 	iWin->SetTitle(_L("Password Mode Enabled"));
       
  1321 	}
       
  1322 
       
  1323 void CPasswordWindowGroup::Cancel()
       
  1324 	{
       
  1325 	iPasswordMode=EFalse;
       
  1326 	iWin->SetVisible(EFalse);
       
  1327 	iGroupWin.SetOrdinalPosition(0,-1000);
       
  1328 	iWin->SetTitle(_L("Why am I here?"));
       
  1329 	}
       
  1330 
       
  1331 void CPasswordWindowGroup::KeyL(const TKeyEvent &aKey,const TTime&)
       
  1332 	{
       
  1333 	if (iPasswordMode && aKey.iCode==EKeyEnter)
       
  1334 		{
       
  1335 		Client()->iWs.PasswordEntered();
       
  1336 		Cancel();
       
  1337 		}
       
  1338 	}
       
  1339 
       
  1340 void CPasswordWindowGroup::ConstructL()
       
  1341 	{
       
  1342 	CTWindowGroup::ConstructL();
       
  1343 	iGroupWin.SetOrdinalPosition(-1);
       
  1344 	iWin=new(ELeave) CTPasswordWindow();
       
  1345 	iWin->ConstructL(*this);
       
  1346 	iWin->AssignGC(*Client()->iGc);
       
  1347 	Cancel();
       
  1348 	iWin->Win()->PasswordWindow(EPasswordAlwaysTriggerNow);
       
  1349 	iWin->Activate();
       
  1350 	SetCurrentWindow(iWin);
       
  1351 	}
       
  1352 
       
  1353 //
       
  1354 
       
  1355 CShellClient::CShellClient()
       
  1356 	{
       
  1357 	}
       
  1358 
       
  1359 void CShellClient::CreateTestWindowL(CTWin *aWin, const TPoint &aPos,CTWinBase *parent)
       
  1360 	{
       
  1361 	TRAPD(err,aWin->ConstructL(*parent));
       
  1362 	if (err!=KErrNone)
       
  1363 		{
       
  1364 		delete aWin;
       
  1365 		User::Leave(err);
       
  1366 		}
       
  1367 	aWin->SetInitialPos(aPos);
       
  1368 	aWin->Activate();
       
  1369 	aWin->AssignGC(*iGc);
       
  1370 	}
       
  1371 
       
  1372 void CShellClient::CreateTestWindowL(CTWin *aWin, const TPoint &aPos)
       
  1373 	{
       
  1374 	CreateTestWindowL(aWin, aPos, iGroup);
       
  1375 	}
       
  1376 
       
  1377 CShellClient::~CShellClient()
       
  1378 	{
       
  1379 	delete iPointerCursor;
       
  1380 	delete iIconWin1;
       
  1381 	delete iIconWin2;
       
  1382 	delete iIconGroup;
       
  1383 	delete iPasswordGroup;
       
  1384 	iWs.FreeSystemPointerCursorList();
       
  1385 	iFs.Close();
       
  1386 	}
       
  1387 
       
  1388 
       
  1389 void CShellClient::ConstructL()
       
  1390 	{
       
  1391 	User::LeaveIfError(iFs.Connect());
       
  1392 	CTClient::ConstructL();
       
  1393 	iWs.RequestOffEvents(EFalse);		//To test this function
       
  1394 
       
  1395 	TBool keyClicksSupported=EFalse;
       
  1396 	HAL::Get(HALData::EKeyboardClick,keyClicksSupported);
       
  1397 	if (keyClicksSupported)
       
  1398 		{
       
  1399 		HAL::Set(HALData::EKeyboardClickState,1);
       
  1400 		TInt maxVol=1;
       
  1401 		HAL::Get(HALData::EKeyboardClickVolumeMax,maxVol);
       
  1402 		HAL::Set(HALData::EKeyboardClickVolume,maxVol);
       
  1403 		}	
       
  1404 	
       
  1405 	iWs.SetDoubleClick(TTimeIntervalMicroSeconds32(EDoubleClickTime), EDoubleClickDistance);
       
  1406 
       
  1407 	User::LeaveIfError(iWs.SetHotKey(EHotKeyBacklightToggle, 2, EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl|EModifierShift));
       
  1408 	User::LeaveIfError(iWs.SetHotKey(EHotKeyBacklightOn, 14, EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl|EModifierShift));
       
  1409 	User::LeaveIfError(iWs.SetHotKey(EHotKeyBacklightOff, 13, EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl|EModifierShift));
       
  1410 //
       
  1411 	iGroup=new(ELeave) CShellWindowGroup(this);
       
  1412 	iGroup->ConstructL();
       
  1413 	iWs.RequestOffEvents(ETrue,iGroup->GroupWin());	//To test this function
       
  1414 	iWs.RequestOffEvents(EFalse);
       
  1415 	iIconGroup=new(ELeave) CIconWindowGroup(this);
       
  1416 	iIconGroup->ConstructL();
       
  1417 	iIconWin1=new(ELeave) CTIconWindow(0);
       
  1418 	iIconWin1->ConstructL(*iIconGroup);
       
  1419 	iIconWin2=new(ELeave) CTIconWindow(1);
       
  1420 	iIconWin2->ConstructL(*iIconGroup);
       
  1421 
       
  1422 	CShellWindow *win=new(ELeave) CShellWindow();
       
  1423 	CreateTestWindowL(win, TPoint(330,10));
       
  1424 	TWinCommand command;
       
  1425 	User::CommandLine(command);
       
  1426 	win->SetAutoLaunch(win->RunClientL(command,EFalse));
       
  1427 
       
  1428     iPointerCursor=new(ELeave) CTPointerCursor(iWs);
       
  1429     TSpriteCreateParams params(TSize(24,48),TPoint(-12,-24),DrawPointerCursor,NULL, ETrue,CGraphicsContext::EDrawModePEN);
       
  1430     iPointerCursor->ConstructL(1,&params,0);
       
  1431 	iGroup->GroupWin()->SetCustomPointerCursor(iPointerCursor->PointerCursor());
       
  1432 	ResetFocus();
       
  1433 	}
       
  1434 
       
  1435 void CShellClient::ScreenDeviceChangedL()
       
  1436 	{
       
  1437 	iIconWin1->SetExtentL();
       
  1438 	iIconWin2->SetExtentL();
       
  1439 	}
       
  1440 
       
  1441 void CShellClient::Exit()
       
  1442 	{
       
  1443 	CActiveScheduler::Stop();
       
  1444 	}
       
  1445 
       
  1446 CRunningProcess::CRunningProcess(MProcessObserver* aObserver) : CActive(-5), iObserver(aObserver) 
       
  1447 	{}
       
  1448 
       
  1449 CRunningProcess::~CRunningProcess()
       
  1450 	{
       
  1451 	Cancel();
       
  1452 	if (iNext)
       
  1453 		iNext->iPrevPtr=iPrevPtr;
       
  1454 	*iPrevPtr=iNext;
       
  1455 #if defined(__WINS__)
       
  1456 	iLib.Close();
       
  1457 #endif
       
  1458 #if defined(__USING_PROCESS_)
       
  1459 	iProcess.Close();
       
  1460 #else
       
  1461 	iProcess.Close();
       
  1462 #endif
       
  1463 	if (iObserver)
       
  1464 		iObserver->ProcessDied();
       
  1465 	}
       
  1466 
       
  1467 void CRunningProcess::ConstructL(const TDesC &aName)
       
  1468 	{
       
  1469 #if defined(__USING_PROCESS_)
       
  1470 	TParse fileName;
       
  1471 	fileName.Set(_L("E:\\.EXE"),&aName,NULL);
       
  1472 	TInt error = iProcess.Create(fileName.FullName(),_L(""));
       
  1473 	if(error != KErrNone)
       
  1474 		{
       
  1475 		fileName.Set(_L(""),&aName,NULL);
       
  1476 		User::LeaveIfError(iProcess.Create(fileName.FullName(),_L("")));
       
  1477 		}
       
  1478 #else
       
  1479 	User::LeaveIfError(iFileName.Set(RP_FILENAME_SET,&aName,NULL));
       
  1480 	User::LeaveIfError(iLib.Load(iFileName.FullName()));
       
  1481 	DllTestAppEntryPoint libFunc=(DllTestAppEntryPoint)iLib.Lookup(1);
       
  1482 	User::LeaveIfNull((TAny *)libFunc);
       
  1483 	TBuf<KMaxFileName> threadName;
       
  1484 	TInt err;
       
  1485 	TInt num=0;
       
  1486 	do
       
  1487 		{
       
  1488 		threadName.Format(TRefByValue<const TDesC>(_L("%S%02d")),&aName,num++);
       
  1489 		err=iProcess.Create(threadName,libFunc,KDefaultStackSize,NULL,&iLib,NULL,KHeapSize,KHeapSize,EOwnerProcess);
       
  1490 		} while(err==KErrAlreadyExists);
       
  1491 	User::LeaveIfError(err);
       
  1492 #endif
       
  1493 	iProcess.Logon(iStatus);
       
  1494 	iProcess.Resume();
       
  1495 	SetActive();
       
  1496 	}
       
  1497 
       
  1498 void CRunningProcess::ConstructTestExecuteL(const TDesC &aName)
       
  1499 	{
       
  1500 	//testexecute z:\wstest\wstest_t_autotest.script
       
  1501 	_LIT(KTestExecute,"testexecute");
       
  1502 	_LIT(KComandLinePrefix,"z:\\wstest\\wstest_t_");
       
  1503 	_LIT(KComandLinePostfix,"test.script");
       
  1504 #if defined(__USING_PROCESS_)
       
  1505 	TParse fileName;
       
  1506 	fileName.Set(KNullDesC,&KTestExecute,NULL);
       
  1507 	TBuf<128> commandLine;
       
  1508 	commandLine.Append(KComandLinePrefix);
       
  1509 	commandLine.Append(aName);
       
  1510 	commandLine.Append(KComandLinePostfix);
       
  1511 	User::LeaveIfError(iProcess.Create(fileName.FullName(),commandLine));
       
  1512 	iProcess.Logon(iStatus);
       
  1513 	iProcess.Resume();
       
  1514 	SetActive();
       
  1515 #endif
       
  1516 	}
       
  1517 
       
  1518 void CRunningProcess::Link(CRunningProcess **aRpPtr)
       
  1519 	{
       
  1520 	iNext=*aRpPtr;
       
  1521 	if (iNext)
       
  1522 		iNext->iPrevPtr=&iNext;
       
  1523 	*aRpPtr=this;
       
  1524 	iPrevPtr=aRpPtr;
       
  1525 	}
       
  1526 
       
  1527 void CRunningProcess::DoCancel()
       
  1528 	{
       
  1529 	iProcess.LogonCancel(iStatus);
       
  1530 	}
       
  1531 
       
  1532 void CRunningProcess::RunL()
       
  1533 	{
       
  1534 	if (iStatus!=KErrNone)
       
  1535 		{
       
  1536 		TBuf<32> buf;
       
  1537 		buf.Num(iStatus.Int());
       
  1538 		DisplayDialog(_L("Program exited with error"),iProcess.ExitCategory(),buf);
       
  1539 		}
       
  1540 	delete this;
       
  1541 	}
       
  1542 
       
  1543 GLDEF_C CTClient *CreateClientL()
       
  1544 	{
       
  1545 	return(new(ELeave) CShellClient());
       
  1546 	}
       
  1547 
       
  1548 GLDEF_C TInt E32Main()
       
  1549 	{
       
  1550 	return(TestLibStartUp(CreateClientL));
       
  1551 	}