os/graphics/windowing/windowserver/test/tlib/TESTBASE.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tlib/TESTBASE.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1446 @@
     1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Base classes used for building window server test code
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <w32std.h>
    1.23 +#include <e32svr.h>
    1.24 +#include <e32property.h>
    1.25 +#include "TLIB.H"
    1.26 +#include <graphics/wsgraphicdrawerinterface.h>
    1.27 +
    1.28 +//
    1.29 +// Test code classes
    1.30 +//
    1.31 +// CTWinBase
    1.32 +// CTBaseWin
    1.33 +// CTWin
    1.34 +// CTBackedUpWin
    1.35 +// CTGroupWin
    1.36 +// CTClient
    1.37 +//
    1.38 +//
    1.39 +
    1.40 +_LIT(KTestFontTypefaceName,"DejaVu Sans Condensed");
    1.41 +
    1.42 +class CStopTheScheduler : public CAsyncOneShot
    1.43 +	{
    1.44 +public:
    1.45 +	inline CStopTheScheduler(CTClient* aClient,TInt aPriority,TBool aAll) :CAsyncOneShot(aPriority), iClient(aClient), iAll(aAll) {}
    1.46 +	inline CStopTheScheduler(CTClient* aClient,TInt aPriority) :CAsyncOneShot(aPriority), iClient(aClient) {}
    1.47 +	inline CStopTheScheduler(TInt aPriority) :CAsyncOneShot(aPriority) {}
    1.48 +	void RunL();
    1.49 +public:
    1.50 +	CTClient* iClient;
    1.51 +	TBool iAll;
    1.52 +#ifdef __WINS__
    1.53 +	TInt iCStopTheSchedulerRunCount;
    1.54 +#endif
    1.55 +	};
    1.56 +
    1.57 +
    1.58 +void TbPanic(TInt aPanic)
    1.59 +	{
    1.60 +	User::Panic(_L("TestBase"),aPanic);
    1.61 +	}
    1.62 +
    1.63 +EXPORT_C CTWinBase::CTWinBase(TInt aType) : iType(aType)
    1.64 +	{
    1.65 +	__DECLARE_NAME(_S("CTWinBase"));
    1.66 +	}
    1.67 +
    1.68 +EXPORT_C CTWinBase *CTWinBase::Parent() const
    1.69 +	{
    1.70 +	return((CTWinBase *)WinTreeNode()->Parent());
    1.71 +	}
    1.72 +
    1.73 +EXPORT_C CTWinBase *CTWinBase::NextSibling() const
    1.74 +	{
    1.75 +	return((CTWinBase *)WinTreeNode()->NextSibling());
    1.76 +	}
    1.77 +
    1.78 +EXPORT_C CTWinBase *CTWinBase::PrevSibling() const
    1.79 +	{
    1.80 +	return((CTWinBase *)WinTreeNode()->PrevSibling());
    1.81 +	}
    1.82 +
    1.83 +EXPORT_C CTClient *CTWinBase::Client() const
    1.84 +	{
    1.85 +	return(iOwnerWin->Client());
    1.86 +	}
    1.87 +
    1.88 +EXPORT_C CTBaseWin *CTWinBase::Child() const
    1.89 +	{
    1.90 +	return((CTBaseWin *)WinTreeNode()->Child());
    1.91 +	}
    1.92 +
    1.93 +EXPORT_C TPoint CTWinBase::Position() const
    1.94 +	{
    1.95 +	return(TPoint(0,0));
    1.96 +	}
    1.97 +
    1.98 +EXPORT_C void CTWinBase::PointerEnter(const TTime&)
    1.99 +	{
   1.100 +	}
   1.101 +
   1.102 +EXPORT_C void CTWinBase::PointerExit(const TTime&)
   1.103 +	{
   1.104 +	}
   1.105 +
   1.106 +EXPORT_C void CTWinBase::PointerBufferReady(const TTime&)
   1.107 +	{
   1.108 +	}
   1.109 +
   1.110 +EXPORT_C void CTWinBase::PointerL(const TPointerEvent&,const TTime&)
   1.111 +	{
   1.112 +	}
   1.113 +
   1.114 +EXPORT_C void CTWinBase::SwitchOn(const TTime &)
   1.115 +	{
   1.116 +	}
   1.117 +
   1.118 +EXPORT_C void CTWinBase::ModifiersChanged(const TModifiersChangedEvent &,const TTime &)
   1.119 +	{
   1.120 +	}
   1.121 +
   1.122 +EXPORT_C void CTWinBase::AdjustOrdinal(TInt)
   1.123 +	{
   1.124 +	}
   1.125 +
   1.126 +EXPORT_C void CTWinBase::AdjustShadow(TInt)
   1.127 +	{
   1.128 +	}
   1.129 +
   1.130 +EXPORT_C void CTWinBase::SetVisible(TBool)
   1.131 +	{
   1.132 +	}
   1.133 +
   1.134 +EXPORT_C TInt CTWinBase::SubType()
   1.135 +	{
   1.136 +	return(0);
   1.137 +	}
   1.138 +
   1.139 +EXPORT_C void CTWinBase::ErrorMessage(const TWsErrorMessage&, const TTime &)
   1.140 +	{
   1.141 +	}
   1.142 +
   1.143 +EXPORT_C void CTWinBase::__DbgTestInvariant() const
   1.144 +	{
   1.145 +	WinTreeNode()->__DbgTestInvariant();
   1.146 +	}
   1.147 +
   1.148 +// CTBaseWin //
   1.149 +
   1.150 +EXPORT_C CTBaseWin::CTBaseWin(TInt aType) : CTWinBase(aType)
   1.151 +	{
   1.152 +	__DECLARE_NAME(_S("CTBaseWin"));
   1.153 +	}
   1.154 +
   1.155 +EXPORT_C CTBaseWin::~CTBaseWin()
   1.156 +	{
   1.157 +	}
   1.158 +
   1.159 +EXPORT_C void CTBaseWin::RelinquishFocus()
   1.160 +	{
   1.161 +	CTWinBase *parent=Parent();
   1.162 +	CTWindowGroup *group=Group();
   1.163 +	CTWinBase *child=group->Child();
   1.164 +	if (child==this)
   1.165 +		child=child->NextSibling();
   1.166 +	group->SetCurrentWindow((parent->iType==EWinTypeClient) ? (CTBaseWin *)parent : (CTBaseWin *)child);
   1.167 +	}
   1.168 +
   1.169 +EXPORT_C void CTBaseWin::SetVisible(TBool aState)
   1.170 +	{
   1.171 +	BaseWin()->SetVisible(aState);
   1.172 +	}
   1.173 +
   1.174 +EXPORT_C const RWindowTreeNode *CTBaseWin::WinTreeNode() const
   1.175 +	{
   1.176 +	return((const RWindowTreeNode *)BaseWin());
   1.177 +	}
   1.178 +
   1.179 +EXPORT_C RWindowTreeNode *CTBaseWin::WinTreeNode()
   1.180 +	{
   1.181 +	return((RWindowTreeNode *)BaseWin());
   1.182 +	}
   1.183 +
   1.184 +EXPORT_C void CTBaseWin::InitWin()
   1.185 +	{
   1.186 +	}
   1.187 +
   1.188 +EXPORT_C void CTBaseWin::ConstructExtLD(CTWinBase &aParent, const TPoint &aPos, const TSize &aSize)
   1.189 +//
   1.190 +// Call ConstructL, SetExt and either of these fail destroy this and leave
   1.191 +//
   1.192 +	{
   1.193 +	TRAPD(err,ConstructL(aParent));
   1.194 +	if (err!=KErrNone)
   1.195 +		goto celd_err;
   1.196 +	TRAP(err,SetExtL(aPos,aSize));
   1.197 +	if (err!=KErrNone)
   1.198 +		{
   1.199 +celd_err:
   1.200 +		delete this;
   1.201 +		User::Leave(err);
   1.202 +		}
   1.203 +	}
   1.204 +
   1.205 +EXPORT_C void CTBaseWin::ConstructL(CTWinBase &aParent)
   1.206 +	{
   1.207 +	TInt ret;
   1.208 +	__ASSERT_DEBUG(aParent.iOwnerWin!=NULL,TbPanic(ETestBasePanicNullOwnerWin));
   1.209 +	iOwnerWin=aParent.iOwnerWin;
   1.210 +	if ((ret=ConstructWin(aParent))==KErrNone)
   1.211 +		{
   1.212 +		//TFontSpec fspec(KTestFontTypefaceName,200);
   1.213 +		//User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont, fspec));
   1.214 +		TFontSpec fspec(KTestFontTypefaceName,17);
   1.215 +		User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInPixels((CFont *&)iFont, fspec));
   1.216 +		AdjustShadow(1);
   1.217 +		InitWin();
   1.218 +		iSize=BaseWin()->Size();
   1.219 +		}
   1.220 +	User::LeaveIfError(ret);
   1.221 +	}
   1.222 +
   1.223 +EXPORT_C void CTBaseWin::Activate()
   1.224 +	{
   1.225 +	BaseWin()->Activate();
   1.226 +	}
   1.227 +
   1.228 +EXPORT_C void CTBaseWin::SetFullScreenExtL()
   1.229 +	{
   1.230 +	SetExtL(TPoint(0,0), Parent()->Size());
   1.231 +	}
   1.232 +
   1.233 +EXPORT_C void CTBaseWin::SetDefaultExtL()
   1.234 +	{
   1.235 +	TSize size=Parent()->Size();
   1.236 +	size.iWidth>>=1;
   1.237 +	size.iHeight>>=1;
   1.238 +	SetExtL(TPoint(size.iWidth>>1,size.iHeight>>1), size);
   1.239 +	}
   1.240 +
   1.241 +EXPORT_C void CTBaseWin::AssignGC(CWindowGc &aGc)
   1.242 +	{
   1.243 +	iGc= &aGc;
   1.244 +	}
   1.245 +
   1.246 +EXPORT_C void CTBaseWin::SetPos(const TPoint &aPos)
   1.247 +	{
   1.248 +	BaseWin()->SetPosition(aPos);
   1.249 +	iPos=aPos;
   1.250 +	}
   1.251 +
   1.252 +EXPORT_C void CTBaseWin::SetInitialPos(const TPoint &aPos)
   1.253 +	{
   1.254 +	TSize screen=Client()->iScreen->SizeInPixels();
   1.255 +	TPoint pos(aPos);
   1.256 +	TPoint botLeft=pos+iSize;
   1.257 +	if (botLeft.iX>screen.iWidth)
   1.258 +		pos.iX=Max(0,pos.iX-botLeft.iX+screen.iWidth);
   1.259 +	if (botLeft.iY>screen.iHeight)
   1.260 +		pos.iY=Max(0,pos.iY-botLeft.iY+screen.iHeight);
   1.261 +	SetPos(pos);
   1.262 +	}
   1.263 +
   1.264 +EXPORT_C void CTBaseWin::SetExtL(const TPoint &aPos, const TSize &aSize)
   1.265 +	{
   1.266 +	User::LeaveIfError(BaseWin()->SetExtentErr(aPos,aSize));
   1.267 +	iPos=aPos;
   1.268 +	iSize=aSize;
   1.269 +	Resized(iSize);
   1.270 +	}
   1.271 +
   1.272 +EXPORT_C void CTBaseWin::AdjustSizeL(TInt xMove,TInt yMove,TInt modifiers)
   1.273 +	{
   1.274 +	if (modifiers&EModifierCtrl)	// 4 times the movement
   1.275 +		{
   1.276 +		xMove<<=2;
   1.277 +		yMove<<=2;
   1.278 +		}
   1.279 +	if (modifiers&EModifierShift)
   1.280 +		{
   1.281 +		TSize size(iSize.iWidth+xMove,iSize.iHeight+yMove);
   1.282 +	
   1.283 +		if (size.iWidth<0)
   1.284 +			size.iWidth=0;
   1.285 +		if (size.iHeight<0)
   1.286 +			size.iHeight=0;
   1.287 +		if (modifiers&EModifierCtrl)
   1.288 +			{
   1.289 +			TPoint pos(iPos);
   1.290 +			pos.iX-=(xMove>>1);
   1.291 +			pos.iY-=(yMove>>1);
   1.292 +			SetExtL(pos,size);
   1.293 +			}
   1.294 +		else
   1.295 +			SetSizeL(size);
   1.296 +		}
   1.297 +	else
   1.298 +		SetPos(TPoint(iPos+TPoint(xMove,yMove)));
   1.299 +	}
   1.300 +
   1.301 +EXPORT_C void CTBaseWin::SetSizeL(const TSize &aSize)
   1.302 +	{
   1.303 +	User::LeaveIfError(BaseWin()->SetSizeErr(aSize));
   1.304 +	iSize=aSize;
   1.305 +	Resized(iSize);
   1.306 +	}
   1.307 +
   1.308 +EXPORT_C TSize CTBaseWin::Size() const
   1.309 +	{
   1.310 +	return(iSize);
   1.311 +	}
   1.312 +
   1.313 +EXPORT_C void CTBaseWin::Resized(const TSize &aSize)
   1.314 +//
   1.315 +	{
   1.316 +	SetDragRect(TRect(aSize));
   1.317 +	}
   1.318 +
   1.319 +EXPORT_C TPoint CTBaseWin::Position() const
   1.320 +	{
   1.321 +	return(BaseWin()->Position());
   1.322 +	}
   1.323 +
   1.324 +EXPORT_C void CTBaseWin::Delete(CTBaseWin *aWin)
   1.325 +	{
   1.326 +	RHeap& heap = User::Heap();
   1.327 +	TUint8* base=heap.Base();
   1.328 +	TInt size=heap.Size();
   1.329 +	TUint8* cell=REINTERPRET_CAST(TUint8*,aWin);
   1.330 +	__ASSERT_ALWAYS(base<=cell && cell<base+size, TbPanic(ETestBasePanicInvalidHeapAddress));
   1.331 +	CTWinBase *tmp=aWin;
   1.332 +	CTWinBase *win2;
   1.333 +	CTBaseWin *curwin=NULL;
   1.334 +	if (tmp->Group())
   1.335 +		curwin=tmp->Group()->CurWin();
   1.336 +	do
   1.337 +		{
   1.338 +		win2=tmp;
   1.339 +		while((tmp=win2->Child())!=NULL)
   1.340 +			win2=tmp;
   1.341 +		if ((tmp=win2->NextSibling())==NULL)
   1.342 +			tmp=win2->Parent();
   1.343 +		if (curwin==win2)
   1.344 +			((CTBaseWin *)win2)->RelinquishFocus();
   1.345 +		delete win2;
   1.346 +		} while(win2!=aWin);
   1.347 +	}
   1.348 +
   1.349 +EXPORT_C void CTBaseWin::KeyUpL(const TKeyEvent &,const TTime&)
   1.350 +	{
   1.351 +	}
   1.352 +
   1.353 +EXPORT_C void CTBaseWin::KeyDownL(const TKeyEvent &,const TTime&)
   1.354 +	{
   1.355 +	}
   1.356 +
   1.357 +EXPORT_C void CTBaseWin::WinKeyL(const TKeyEvent &,const TTime&)
   1.358 +	{
   1.359 +	}
   1.360 +
   1.361 +EXPORT_C void CTBaseWin::PointerL(const TPointerEvent &aPointer,const TTime&)
   1.362 +	{
   1.363 +	if (iDragging)
   1.364 +		{
   1.365 +		if (aPointer.iType==TPointerEvent::EDrag)
   1.366 +			SetPos(aPointer.iParentPosition-iDragPos);
   1.367 +		else
   1.368 +			iDragging=EFalse;
   1.369 +		return;
   1.370 +		}
   1.371 +	if (aPointer.iType==TPointerEvent::EButton1Down)
   1.372 +		{
   1.373 +		if (aPointer.iModifiers&EModifierCtrl)
   1.374 +			{
   1.375 +			if (aPointer.iModifiers&EModifierShift)
   1.376 +				BaseWin()->SetOrdinalPosition(-1);
   1.377 +			else
   1.378 +				BaseWin()->SetOrdinalPosition(0);
   1.379 +			return;
   1.380 +			}
   1.381 +#if defined(__WINS__)
   1.382 +		else if (aPointer.iModifiers&EModifierShift)
   1.383 +			__DbgTestInvariant();
   1.384 +#endif
   1.385 +		else
   1.386 +			{
   1.387 +			Group()->SetCurrentWindow(this);
   1.388 +			if (iDragRect.Contains(aPointer.iPosition))
   1.389 +				{
   1.390 +				iDragging=ETrue;
   1.391 +				iDragPos=aPointer.iPosition;
   1.392 +				return;
   1.393 +				}
   1.394 +			}
   1.395 +		}
   1.396 +	}
   1.397 +
   1.398 +EXPORT_C void CTBaseWin::DragDropL(const TPointerEvent &,const TTime &)
   1.399 +	{
   1.400 +	}
   1.401 +
   1.402 +EXPORT_C void CTBaseWin::AdjustOrdinal(TInt aAdjust)
   1.403 +	{
   1.404 +	TInt pos=BaseWin()->OrdinalPosition()+aAdjust;
   1.405 +	if (pos>=0)
   1.406 +		BaseWin()->SetOrdinalPosition(pos);
   1.407 +	}
   1.408 +
   1.409 +EXPORT_C void CTBaseWin::AdjustShadow(TInt aAdjust)
   1.410 +	{
   1.411 +	iShadow+=aAdjust;
   1.412 +	if (iShadow<0)
   1.413 +		iShadow=0;
   1.414 +	BaseWin()->SetShadowHeight(iShadow);
   1.415 +	}
   1.416 +
   1.417 +EXPORT_C void CTBaseWin::DrawBorder()
   1.418 +	{
   1.419 +	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.420 +	iGc->DrawRect(TRect(iSize));
   1.421 +	iGc->SetBrushStyle(CGraphicsContext::ENullBrush);
   1.422 +	}
   1.423 +
   1.424 +EXPORT_C void CTBaseWin::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc, TDisplayMode *aMode,TBool aVisible,TInt aTransparency)
   1.425 +	{
   1.426 +	ConstructL(*parent);
   1.427 +	if (aMode)
   1.428 +		BaseWin()->SetRequiredDisplayMode(*aMode);
   1.429 +	SetExtL(pos,size);
   1.430 +	if (!aVisible)
   1.431 +		BaseWin()->SetVisible(aVisible);
   1.432 +	if (aTransparency!=ENoTransparency)
   1.433 +		{
   1.434 +		TInt err=((RWindow*)(BaseWin()))->SetTransparencyFactor(TRgb::_Gray256(aTransparency));	
   1.435 +		User::LeaveIfError(err);	//asked for transparency when not got none!
   1.436 +		}
   1.437 +	Activate();
   1.438 +	AssignGC(aGc);
   1.439 +	}
   1.440 +
   1.441 +EXPORT_C void CTBaseWin::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc, TDisplayMode *aMode)
   1.442 +	{
   1.443 +	SetUpL(pos,size,parent,aGc,aMode,ETrue);
   1.444 +	}
   1.445 +
   1.446 +EXPORT_C void CTBaseWin::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc,TBool aVisible)
   1.447 +	{
   1.448 +	SetUpL(pos,size,parent,aGc,NULL,aVisible);
   1.449 +	}
   1.450 +
   1.451 +EXPORT_C void CTBaseWin::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
   1.452 +	{
   1.453 +	SetUpL(pos,size,parent,aGc,NULL,ETrue);
   1.454 +	}
   1.455 +
   1.456 +EXPORT_C void CTBaseWin::SetDragRect(const TRect &aRect)
   1.457 +	{
   1.458 +	BaseWin()->PointerFilter(EPointerFilterDrag,0);	// Clear the drag filter
   1.459 +	BaseWin()->SetPointerGrab(ETrue);
   1.460 +	iDragRect=aRect;
   1.461 +	}
   1.462 +
   1.463 +EXPORT_C CTWindowGroup *CTBaseWin::Group() const
   1.464 +	{
   1.465 +	return(iOwnerWin);
   1.466 +	}
   1.467 +
   1.468 +EXPORT_C void CTBaseWin::FocusChanged(TBool )
   1.469 +	{
   1.470 +	}
   1.471 +
   1.472 +EXPORT_C CTBaseWin *CTBaseWin::Next()
   1.473 +	{
   1.474 +	CTWinBase *win;
   1.475 +	CTWinBase *ret=Child();
   1.476 +	if (ret==NULL)
   1.477 +		{
   1.478 +		win=this;
   1.479 +		while((ret=win->NextSibling())==NULL)
   1.480 +			{
   1.481 +			ret=win;
   1.482 +			win=win->Parent();
   1.483 +			if (win==NULL)	// Group window
   1.484 +				{
   1.485 +				ret=ret->Child();
   1.486 +				break;
   1.487 +				}
   1.488 +			}
   1.489 +		}
   1.490 +	return((CTBaseWin *)ret);
   1.491 +	}
   1.492 +
   1.493 +EXPORT_C CTBaseWin *CTBaseWin::Prev()
   1.494 +	{
   1.495 +	CTWinBase *par=Parent();
   1.496 +	CTWinBase *win;
   1.497 +	CTWinBase *child;
   1.498 +	if ((win=PrevSibling())==NULL)
   1.499 +		{
   1.500 +		if (par->iType==EWinTypeGroup)
   1.501 +			{
   1.502 +			CTWinBase *win2=par->Child();
   1.503 +			do
   1.504 +				{
   1.505 +				win=win2;
   1.506 +				while((win2=win->NextSibling())!=NULL)
   1.507 +					win=win2;
   1.508 +				win2=win->Child();
   1.509 +				} while(win2!=NULL);
   1.510 +			}
   1.511 +		else
   1.512 +			win=par;
   1.513 +		}
   1.514 +	else
   1.515 +		{
   1.516 +		child=win->Child();
   1.517 +		while(child!=NULL)
   1.518 +			{
   1.519 +			win=child;
   1.520 +			child=child->NextSibling();
   1.521 +			}
   1.522 +		}
   1.523 +	return((CTBaseWin *)win);
   1.524 +	}
   1.525 +
   1.526 +//EXPORT_C void CTBaseWin::SetDefaultExt()
   1.527 +//	{
   1.528 +//	TbPanic(ETestBasePanicUnimplementedBaseFunction);
   1.529 +//	}
   1.530 +
   1.531 +EXPORT_C void CTBaseWin::Draw()
   1.532 +	{
   1.533 +	TbPanic(ETestBasePanicUnimplementedBaseFunction);
   1.534 +	}
   1.535 +
   1.536 +EXPORT_C void CTBaseWin::__DbgTestInvariant() const
   1.537 +	{
   1.538 +	CTWinBase::__DbgTestInvariant();
   1.539 +#if defined(__WINS__)
   1.540 +	if (BaseWin()->Size()!=iSize)
   1.541 +		User::Invariant();
   1.542 +	TPoint offset;
   1.543 +	const CTWinBase *win=this;
   1.544 +	const CTWinBase *win2;
   1.545 +	while((win2=win->Parent())!=NULL)
   1.546 +		{
   1.547 +		offset+=((CTBaseWin *)win)->BaseWin()->Position();
   1.548 +		if (BaseWin()->InquireOffset(*(win2->WinTreeNode()))!=offset)
   1.549 +			User::Invariant();
   1.550 +		win=win2;
   1.551 +		}
   1.552 +#endif
   1.553 +	}
   1.554 +
   1.555 +//CTDrawableWin//
   1.556 +//	Drawable window					   //
   1.557 +//
   1.558 +
   1.559 +EXPORT_C CTDrawableWin::CTDrawableWin(TInt aType) : CTBaseWin(aType)
   1.560 +	{
   1.561 +	__DECLARE_NAME(_S("CTDrawableWin"));
   1.562 +	}
   1.563 +
   1.564 +//CTWin//
   1.565 +//	Standard client window					   //
   1.566 +//
   1.567 +
   1.568 +EXPORT_C CTWin::CTWin() : CTDrawableWin(EWinTypeClient)
   1.569 +	{
   1.570 +	__DECLARE_NAME(_S("CTWin"));
   1.571 +	}
   1.572 +
   1.573 +EXPORT_C CTWin::~CTWin()
   1.574 +	{
   1.575 +	if (iFont)
   1.576 +		Client()->iScreen->ReleaseFont(iFont);
   1.577 +	iWin.Close();
   1.578 +	}
   1.579 +
   1.580 +EXPORT_C TInt CTWin::ConstructWin(const CTWinBase &aParent)
   1.581 +	{
   1.582 +	iWin=RWindow(aParent.Client()->iWs);
   1.583 +	return(iWin.Construct(*(aParent.WinTreeNode()),(TUint32)this));
   1.584 +	}
   1.585 +
   1.586 +EXPORT_C void CTWin::SetDefaultExt()
   1.587 +	{
   1.588 +	TSize size=Parent()->Size();
   1.589 +	size.iWidth>>=1;
   1.590 +	size.iHeight>>=1;
   1.591 +	SetExt(TPoint(size.iWidth>>1,size.iHeight>>1), size);
   1.592 +	Invalidate();
   1.593 +	}
   1.594 +
   1.595 +EXPORT_C void CTWin::SetExt(const TPoint &aPos, const TSize &aSize)
   1.596 +	{
   1.597 +	iWin.SetExtent(aPos,aSize);
   1.598 +	iPos=aPos;
   1.599 +	iSize=aSize;
   1.600 +	Resized(iSize);
   1.601 +	}
   1.602 +
   1.603 +EXPORT_C void CTWin::SetSize(const TSize &aSize)
   1.604 +	{
   1.605 +	iWin.SetSize(aSize);
   1.606 +	iSize=aSize;
   1.607 +	Resized(iSize);
   1.608 +	}
   1.609 +
   1.610 +EXPORT_C void CTWin::AdjustSize(TInt xMove,TInt yMove,TInt modifiers)
   1.611 +	{
   1.612 +	if (modifiers&EModifierCtrl)	// 4 times the movement
   1.613 +		{
   1.614 +		xMove<<=2;
   1.615 +		yMove<<=2;
   1.616 +		}
   1.617 +	if (modifiers&EModifierShift)
   1.618 +		{
   1.619 +		TSize size(iSize.iWidth+xMove,iSize.iHeight+yMove);
   1.620 +	
   1.621 +		if (size.iWidth<0)
   1.622 +			size.iWidth=0;
   1.623 +		if (size.iHeight<0)
   1.624 +			size.iHeight=0;
   1.625 +		if (modifiers&EModifierCtrl)
   1.626 +			{
   1.627 +			TPoint pos(iPos);
   1.628 +			pos.iX-=(xMove>>1);
   1.629 +			pos.iY-=(yMove>>1);
   1.630 +			SetExt(pos,size);
   1.631 +			}
   1.632 +		else
   1.633 +			SetSize(size);
   1.634 +		Invalidate();
   1.635 +		}
   1.636 +	else
   1.637 +		SetPos(TPoint(iPos+TPoint(xMove,yMove)));
   1.638 +	}
   1.639 +
   1.640 +EXPORT_C RWindowBase *CTWin::BaseWin()
   1.641 +	{
   1.642 +	return((RWindowBase *)&iWin);
   1.643 +	}
   1.644 +
   1.645 +EXPORT_C const RWindowBase *CTWin::BaseWin() const
   1.646 +	{
   1.647 +	return((const RWindowBase *)&iWin);
   1.648 +	}
   1.649 +
   1.650 +EXPORT_C RDrawableWindow *CTWin::DrawableWin()
   1.651 +	{
   1.652 +	return((RDrawableWindow *)&iWin);
   1.653 +	}
   1.654 +
   1.655 +EXPORT_C const RDrawableWindow *CTWin::DrawableWin() const
   1.656 +	{
   1.657 +	return((const RDrawableWindow *)&iWin);
   1.658 +	}
   1.659 +
   1.660 +
   1.661 +EXPORT_C void CTWin::Invalidate()
   1.662 +	{
   1.663 +	iWin.Invalidate();
   1.664 +	}
   1.665 +
   1.666 +EXPORT_C void CTWin::Invalidate(const TRect &rect)
   1.667 +	{
   1.668 +	iWin.Invalidate(rect);
   1.669 +	}
   1.670 +
   1.671 +EXPORT_C void CTWin::DrawNow()
   1.672 +	{
   1.673 +	iWin.Invalidate();
   1.674 +	iWin.BeginRedraw();
   1.675 +	iGc->Activate(iWin);
   1.676 +	iGc->UseFont((CFont *)iFont);
   1.677 +	Draw();
   1.678 +	iGc->Deactivate();
   1.679 +	iWin.EndRedraw();
   1.680 +	}
   1.681 +
   1.682 +EXPORT_C void CTWin::Redraw()
   1.683 +	{
   1.684 +	iWin.BeginRedraw();
   1.685 +	iGc->Activate(iWin);
   1.686 +	iGc->UseFont((CFont *)iFont);
   1.687 +	Draw();
   1.688 +	iGc->Deactivate();
   1.689 +	iWin.EndRedraw();
   1.690 +	}
   1.691 +
   1.692 +EXPORT_C void CTWin::Redraw(const TRect &aRect)
   1.693 +	{
   1.694 +	iWin.BeginRedraw(aRect);
   1.695 +	iGc->Activate(iWin);
   1.696 +	iGc->UseFont((CFont *)iFont);
   1.697 +	Draw();
   1.698 +	iGc->Deactivate();
   1.699 +	iWin.EndRedraw();
   1.700 +	}
   1.701 +
   1.702 +//CTBackedUpWin//
   1.703 +//	Backed up window						   //
   1.704 +//
   1.705 +
   1.706 +EXPORT_C CTBackedUpWin::CTBackedUpWin(TDisplayMode aDisplayMode) : CTDrawableWin(EWinTypeClient), iDisplayMode(aDisplayMode)
   1.707 +	{
   1.708 +	__DECLARE_NAME(_S("CTBackedUpWin"));
   1.709 +	}
   1.710 +
   1.711 +EXPORT_C CTBackedUpWin::~CTBackedUpWin()
   1.712 +	{
   1.713 +	if (iFont)
   1.714 +		Client()->iScreen->ReleaseFont(iFont);
   1.715 +	iWin.Close();
   1.716 +	}
   1.717 +
   1.718 +EXPORT_C TInt CTBackedUpWin::ConstructWin(const CTWinBase &aParent)
   1.719 +	{
   1.720 +	iWin=RBackedUpWindow(aParent.Client()->iWs);
   1.721 +	return(iWin.Construct(*(aParent.WinTreeNode()), iDisplayMode, (TUint32)this));
   1.722 +	}
   1.723 +
   1.724 +EXPORT_C RWindowBase *CTBackedUpWin::BaseWin()
   1.725 +	{
   1.726 +	return((RWindowBase *)&iWin);
   1.727 +	}
   1.728 +
   1.729 +EXPORT_C const RWindowBase *CTBackedUpWin::BaseWin() const
   1.730 +	{
   1.731 +	return((const RWindowBase *)&iWin);
   1.732 +	}
   1.733 +
   1.734 +EXPORT_C RDrawableWindow *CTBackedUpWin::DrawableWin()
   1.735 +	{
   1.736 +	return((RDrawableWindow *)&iWin);
   1.737 +	}
   1.738 +
   1.739 +EXPORT_C const RDrawableWindow *CTBackedUpWin::DrawableWin() const
   1.740 +	{
   1.741 +	return((const RDrawableWindow *)&iWin);
   1.742 +	}
   1.743 +
   1.744 +EXPORT_C RBackedUpWindow *CTBackedUpWin::BackedUpWin()
   1.745 +	{
   1.746 +	return &iWin;
   1.747 +	}
   1.748 +
   1.749 +EXPORT_C const RBackedUpWindow *CTBackedUpWin::BackedUpWin() const
   1.750 +	{
   1.751 +	return &iWin;
   1.752 +	}
   1.753 +
   1.754 +//CTTitledWindow//
   1.755 +
   1.756 +EXPORT_C CTTitledWindow::CTTitledWindow() : CTWin(), iWinColor(TRgb(255,255,255)), iPenColor(TRgb(0,0,0))
   1.757 +	{
   1.758 +	__DECLARE_NAME(_S("CTTitledWin"));
   1.759 +	}
   1.760 +
   1.761 +EXPORT_C CTTitledWindow::~CTTitledWindow()
   1.762 +	{
   1.763 +	}
   1.764 +
   1.765 +EXPORT_C void CTTitledWindow::ConstructL(CTWinBase &parent)
   1.766 +	{
   1.767 +	CTBaseWin::ConstructL(parent);
   1.768 +	iTitleHeight=iFont->HeightInPixels()+4;
   1.769 +	if (iTitle.Length()==0)
   1.770 +		SetTitle(*Client()->Title());
   1.771 +	}
   1.772 +
   1.773 +EXPORT_C void CTTitledWindow::SetColor(TRgb aRgb)
   1.774 +	{
   1.775 +	iWinColor=aRgb;
   1.776 +	iWin.SetBackgroundColor(aRgb);
   1.777 +	}
   1.778 +
   1.779 +EXPORT_C void CTTitledWindow::Resized(const TSize &aSize)
   1.780 +	{
   1.781 +	SetDragRect(TRect(0,0,aSize.iWidth,iTitleHeight));
   1.782 +	}
   1.783 +
   1.784 +EXPORT_C void CTTitledWindow::SetTitle(const TWindowTitle &aTitle)
   1.785 +	{
   1.786 +	iTitle=aTitle;
   1.787 +	}
   1.788 +
   1.789 +EXPORT_C void CTTitledWindow::Draw()
   1.790 +	{
   1.791 +	iGc->SetPenColor(iPenColor);
   1.792 +	iGc->SetBrushColor(iWinColor);
   1.793 +	DrawBorder();
   1.794 +	iGc->DrawLine(TPoint(0,iTitleHeight),TPoint(iSize.iWidth,iTitleHeight));
   1.795 +	if (Group()->HasFocus(this))
   1.796 +		{
   1.797 +		iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.798 +		iGc->SetPenColor(~iPenColor);
   1.799 +		iGc->SetBrushColor(~iWinColor);
   1.800 +		}
   1.801 +	iGc->DrawText(iTitle, TRect(1,1,iSize.iWidth-1,iTitleHeight),iFont->AscentInPixels()+1,CGraphicsContext::ECenter);
   1.802 +	iGc->SetPenColor(iPenColor);
   1.803 +	iGc->SetBrushColor(iWinColor);
   1.804 +	}
   1.805 +
   1.806 +EXPORT_C void CTTitledWindow::FocusChanged(TBool )
   1.807 +	{
   1.808 +	iWin.Invalidate(TRect(0,0,iSize.iWidth,iTitleHeight));
   1.809 +	}
   1.810 +
   1.811 +// CTBlankWindow //
   1.812 +
   1.813 +EXPORT_C CTBlankWindow::CTBlankWindow() : CTBaseWin(EWinTypeClient)
   1.814 +	{
   1.815 +	__DECLARE_NAME(_S("CTBlankWin"));
   1.816 +	}
   1.817 +
   1.818 +EXPORT_C void CTBlankWindow::ConstructL(CTWinBase &aParent)
   1.819 +	{
   1.820 +	CTBaseWin::ConstructL(aParent);
   1.821 +	}
   1.822 +
   1.823 +EXPORT_C CTBlankWindow::~CTBlankWindow()
   1.824 +	{
   1.825 +	if (iFont)
   1.826 +		Client()->iScreen->ReleaseFont(iFont);
   1.827 +	iWin.Close();
   1.828 +	}
   1.829 +
   1.830 +EXPORT_C void CTBlankWindow::SetExt(const TPoint &aPos, const TSize &aSize)
   1.831 +	{
   1.832 +	iWin.SetExtent(aPos,aSize);
   1.833 +	iPos=aPos;
   1.834 +	iSize=aSize;
   1.835 +	Resized(iSize);
   1.836 +	}
   1.837 +
   1.838 +EXPORT_C void CTBlankWindow::SetSize(const TSize &aSize)
   1.839 +	{
   1.840 +	iWin.SetSize(aSize);
   1.841 +	iSize=aSize;
   1.842 +	Resized(iSize);
   1.843 +	}
   1.844 +
   1.845 +EXPORT_C void CTBlankWindow::SetColor(const TRgb &aRgb)
   1.846 +	{
   1.847 +	iWin.SetColor(aRgb);
   1.848 +	}
   1.849 +
   1.850 +EXPORT_C TInt CTBlankWindow::ConstructWin(const CTWinBase &aParent)
   1.851 +	{
   1.852 +	iWin=RBlankWindow(aParent.Client()->iWs);
   1.853 +	return(iWin.Construct(*(aParent.WinTreeNode()),(TUint32)this));
   1.854 +	}
   1.855 +
   1.856 +EXPORT_C const RWindowBase *CTBlankWindow::BaseWin() const
   1.857 +	{
   1.858 +	return((const RWindowBase *)&iWin);
   1.859 +	}
   1.860 +
   1.861 +EXPORT_C RWindowBase *CTBlankWindow::BaseWin()
   1.862 +	{
   1.863 +	return((RWindowBase *)&iWin);
   1.864 +	}
   1.865 +
   1.866 +//CTWindowGroup//
   1.867 +
   1.868 +EXPORT_C CTWindowGroup::CTWindowGroup(CTClient *aClient) : CTWinBase(EWinTypeGroup), iGroupWin(aClient->iWs)
   1.869 +	{
   1.870 +	__DECLARE_NAME(_S("CTWindowGroup"));
   1.871 +	iClient=aClient;
   1.872 +	iOwnerWin=this;
   1.873 +	}
   1.874 +
   1.875 +EXPORT_C CTWindowGroup::~CTWindowGroup()
   1.876 +	{
   1.877 +	iGroupWin.Close();
   1.878 +	}
   1.879 +
   1.880 +EXPORT_C const RWindowTreeNode *CTWindowGroup::WinTreeNode() const
   1.881 +	{
   1.882 +	return((const RWindowTreeNode *)&iGroupWin);
   1.883 +	}
   1.884 +
   1.885 +EXPORT_C RWindowTreeNode *CTWindowGroup::WinTreeNode()
   1.886 +	{
   1.887 +	return((RWindowTreeNode *)&iGroupWin);
   1.888 +	}
   1.889 +
   1.890 +EXPORT_C void CTWindowGroup::ConstructL()
   1.891 +	{
   1.892 +	User::LeaveIfError(iGroupWin.Construct((TUint32)this));
   1.893 +	}
   1.894 +
   1.895 +EXPORT_C TSize CTWindowGroup::Size() const
   1.896 +	{
   1.897 +	return(iClient->iScreen->SizeInPixels());
   1.898 +	}
   1.899 +
   1.900 +EXPORT_C void CTWindowGroup::WinKeyL(const TKeyEvent &,const TTime&)
   1.901 +	{
   1.902 +	}
   1.903 +
   1.904 +EXPORT_C void CTWindowGroup::KeyL(const TKeyEvent &aKey,const TTime&aTime)
   1.905 +	{
   1.906 +	if (iCurWin)
   1.907 +		iCurWin->WinKeyL(aKey,aTime);
   1.908 +	}
   1.909 +
   1.910 +EXPORT_C void CTWindowGroup::KeyUpL(const TKeyEvent &,const TTime&)
   1.911 +	{
   1.912 +	}
   1.913 +
   1.914 +EXPORT_C void CTWindowGroup::KeyDownL(const TKeyEvent &,const TTime&)
   1.915 +	{
   1.916 +	}
   1.917 +
   1.918 +EXPORT_C void CTWindowGroup::ClearCurrentWindow()
   1.919 +	{
   1.920 +	iCurWin=NULL;
   1.921 +	}
   1.922 +
   1.923 +EXPORT_C void CTWindowGroup::SetCurrentWindow(CTBaseWin *aWindow)
   1.924 +	{
   1.925 +	SetCurrentWindow(aWindow, EFalse);
   1.926 +	}
   1.927 +
   1.928 +EXPORT_C void CTWindowGroup::SetCurrentWindow(CTBaseWin *aWindow, TBool aLocked)
   1.929 +	{
   1.930 +	if (iCurWin!=aWindow)
   1.931 +		{
   1.932 +		if (iFocus && iCurWin)
   1.933 +			iCurWin->FocusChanged(EFalse);
   1.934 +		iCurWin=aWindow;
   1.935 +		if (iFocus && iCurWin)
   1.936 +			iCurWin->FocusChanged(ETrue);
   1.937 +		}
   1.938 +	iLocked=aLocked;
   1.939 +	}
   1.940 +
   1.941 +EXPORT_C CTBaseWin *CTWindowGroup::CurWin(void) const
   1.942 +	{
   1.943 +	return(iCurWin);
   1.944 +	}
   1.945 +
   1.946 +EXPORT_C void CTWindowGroup::FocusLost()
   1.947 +	{
   1.948 +	iFocus=EFalse;
   1.949 +	if (iCurWin)
   1.950 +		iCurWin->FocusChanged(EFalse);
   1.951 +	}
   1.952 +
   1.953 +EXPORT_C void CTWindowGroup::FocusGained()
   1.954 +	{
   1.955 +	iFocus=ETrue;
   1.956 +	if (iCurWin)
   1.957 +		iCurWin->FocusChanged(ETrue);
   1.958 +	}
   1.959 +
   1.960 +EXPORT_C TBool CTWindowGroup::HasFocus(CTBaseWin *aWin) const
   1.961 +	{
   1.962 +	return(iFocus && iCurWin==aWin);
   1.963 +	}
   1.964 +
   1.965 +EXPORT_C CTClient *CTWindowGroup::Client() const
   1.966 +	{
   1.967 +	return(iClient);
   1.968 +	}
   1.969 +
   1.970 +EXPORT_C CTWindowGroup *CTWindowGroup::Group() const
   1.971 +	{
   1.972 +	return((CTWindowGroup *)this);
   1.973 +	}
   1.974 +
   1.975 +EXPORT_C void CTWindowGroup::PasswordL(const TTime &)
   1.976 +	{
   1.977 +	TbPanic(ETestBasePanicPassword);
   1.978 +	}
   1.979 +
   1.980 +EXPORT_C void CTWindowGroup::MessageReady(const TWsEvent &)
   1.981 +//
   1.982 +// Dummy handler for un-exepected messages (could panic, but better not as the app sending the messages fault really not ours)
   1.983 +//
   1.984 +	{
   1.985 +	}
   1.986 +
   1.987 +EXPORT_C void CTWindowGroup::ScreenDeviceChanged()
   1.988 +	{
   1.989 +	TPixelsAndRotation sizeAndRotation;
   1.990 +	Client()->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   1.991 +	Client()->iScreen->SetScreenSizeAndRotation(sizeAndRotation);
   1.992 +	}
   1.993 +
   1.994 +EXPORT_C void CTWindowGroup::UserEvent(TInt /*aEventType*/)
   1.995 +	{
   1.996 +	}
   1.997 +
   1.998 +
   1.999 +// CTClient //
  1.1000 +
  1.1001 +EXPORT_C CTClient::CTClient()
  1.1002 +	{
  1.1003 +	__DECLARE_NAME(_S("CTClient"));
  1.1004 +	}
  1.1005 +
  1.1006 +EXPORT_C void CTClient::DestroyWindows()
  1.1007 +	{
  1.1008 +	if (iGroup)
  1.1009 +		{
  1.1010 +		CTBaseWin *win;
  1.1011 +		if (iGroup->GroupWin()->WsHandle()!=0)	// Check it was created okay
  1.1012 +			while((win=iGroup->Child())!=NULL && ((TUint)win)!=ENullWsHandle)
  1.1013 +				CTBaseWin::Delete(win);
  1.1014 +		delete iGroup;
  1.1015 +		iGroup=NULL;
  1.1016 +		}
  1.1017 +	}
  1.1018 +
  1.1019 +EXPORT_C CTClient::~CTClient()
  1.1020 +	{
  1.1021 +	DestroyWindows();
  1.1022 +	delete iGc;
  1.1023 +	delete iEventHandler;
  1.1024 +	delete iRedrawEventHandler;
  1.1025 +	delete iScreen;
  1.1026 +	TInt count=iWs.ResourceCount();
  1.1027 +	__ASSERT_ALWAYS(count==0,TbPanic(ETestBasePanicResourceCount));
  1.1028 +	iWs.Close();
  1.1029 +	}
  1.1030 +
  1.1031 +EXPORT_C void CTClient::ConstructEventHandlerL()
  1.1032 +	{
  1.1033 +	iEventHandler=new(ELeave) CTEvent(&iWs);
  1.1034 +	iEventHandler->Construct();
  1.1035 +	}
  1.1036 +
  1.1037 +EXPORT_C void CTClient::ConstructL()
  1.1038 +	{
  1.1039 +	User::LeaveIfError(iWs.Connect());
  1.1040 +	iScreen=new(ELeave) CWsScreenDevice(iWs);
  1.1041 +	User::LeaveIfError(iScreen->Construct(iScreenNumber));
  1.1042 +	iRedrawEventHandler=new(ELeave) CTRedraw(&iWs);
  1.1043 +	iRedrawEventHandler->Construct();
  1.1044 +	ConstructEventHandlerL();
  1.1045 +	iGc=new(ELeave) CWindowGc(iScreen);
  1.1046 +	User::LeaveIfError(iGc->Construct());
  1.1047 +	iTitle.Copy(RThread().FullName());
  1.1048 +	}
  1.1049 +
  1.1050 +EXPORT_C void CTClient::ResetFocus()
  1.1051 +	{
  1.1052 +	iGroup->ClearCurrentWindow();
  1.1053 +	iGroup->SetCurrentWindow(iGroup->Child());
  1.1054 +	}
  1.1055 +
  1.1056 +EXPORT_C TWindowTitle *CTClient::Title()
  1.1057 +	{
  1.1058 +	return(&iTitle);
  1.1059 +	}
  1.1060 +
  1.1061 +EXPORT_C TBool CTClient::QueueRead()
  1.1062 +	{
  1.1063 +	TBool ret=iEventHandler->IsActive();
  1.1064 +	if (ret==EFalse)
  1.1065 +		iEventHandler->Request();
  1.1066 +	return(ret);
  1.1067 +	}
  1.1068 +
  1.1069 +EXPORT_C void CTClient::CancelRead()
  1.1070 +	{
  1.1071 +	iEventHandler->Cancel();
  1.1072 +	}
  1.1073 +
  1.1074 +EXPORT_C void CTClient::SetCancelFunction(const TCallBack &aCallBack)
  1.1075 +	{
  1.1076 +	iEventHandler->SetCancelFunction(aCallBack);
  1.1077 +	}
  1.1078 +
  1.1079 +EXPORT_C void CTClient::CancelRedrawRead()
  1.1080 +	{
  1.1081 +	iRedrawEventHandler->Cancel();
  1.1082 +	}
  1.1083 +
  1.1084 +EXPORT_C void CTClient::SetRedrawCancelFunction(const TCallBack &aCallBack)
  1.1085 +	{
  1.1086 +	iRedrawEventHandler->SetCancelFunction(aCallBack);
  1.1087 +	}
  1.1088 +
  1.1089 +EXPORT_C void CTClient::RequestRedraw()
  1.1090 +	{
  1.1091 +	iRedrawEventHandler->Request();
  1.1092 +	}
  1.1093 +
  1.1094 +EXPORT_C void CTClient::LogMessage(const TLogMessageText &aMessage)
  1.1095 +	{
  1.1096 +	iWs.LogMessage(aMessage);
  1.1097 +	iWs.Flush();
  1.1098 +	}
  1.1099 +
  1.1100 +EXPORT_C TBool CTClient::IsEventWaiting()
  1.1101 +	{
  1.1102 +	iWs.NumWindowGroups();		//Make sure all asyncronus calls have finished
  1.1103 +	return (iEventHandler->iStatus!=KRequestPending);
  1.1104 +	}
  1.1105 +
  1.1106 +TBool CTClient::WaitUntilEventPending(const TRequestStatus& aStatus)
  1.1107 +	{
  1.1108 +	if (aStatus!=KRequestPending)
  1.1109 +		return ETrue;
  1.1110 +	User::After(2000000);		//Need something smarter than this
  1.1111 +	return (aStatus!=KRequestPending);
  1.1112 +	}
  1.1113 +
  1.1114 +EXPORT_C TBool CTClient::WaitUntilRedrawPending()
  1.1115 +	{
  1.1116 +	return WaitUntilEventPending(iRedrawEventHandler->iStatus);
  1.1117 +	}
  1.1118 +
  1.1119 +EXPORT_C TBool CTClient::WaitUntilEventPending()
  1.1120 +	{
  1.1121 +	return WaitUntilEventPending(iEventHandler->iStatus);
  1.1122 +	}
  1.1123 +
  1.1124 +EXPORT_C TInt CTClient::WaitForRedrawsToFinish()
  1.1125 +	{
  1.1126 +	return WaitForEventsToFinish(EFalse);
  1.1127 +	}
  1.1128 +
  1.1129 +EXPORT_C TInt CTClient::WaitForAllEventProcessingToFinish()
  1.1130 +	{
  1.1131 +	return WaitForEventsToFinish(ETrue);
  1.1132 +	}
  1.1133 +
  1.1134 +TInt CTClient::WaitForEventsToFinish(TBool aAll)
  1.1135 +	{
  1.1136 +	CStopTheScheduler* stop=new CStopTheScheduler(this,ETlibRedrawActivePriority-1,aAll);
  1.1137 +	if (!stop)
  1.1138 +		return KErrNoMemory;
  1.1139 +	stop->Call();
  1.1140 +	CActiveScheduler::Start();
  1.1141 +	delete stop;
  1.1142 +	return KErrNone;
  1.1143 +	}
  1.1144 +
  1.1145 +
  1.1146 +// CStopTheScheduler //
  1.1147 +
  1.1148 +void CStopTheScheduler::RunL()
  1.1149 +	{
  1.1150 +#ifdef __WINS__
  1.1151 +	RDebug::Print(_L("CStopTheScheduler::RunL - enter - %d"), iCStopTheSchedulerRunCount);
  1.1152 +#endif
  1.1153 +	if (iClient)
  1.1154 +	    {
  1.1155 +		iClient->iWs.NumWindowGroups();		//Make sure all asyncronus calls have finished
  1.1156 +	    }
  1.1157 +	
  1.1158 +	if (!iClient || (iClient->RedrawHandler()->iStatus==KRequestPending && (!iAll || iClient->EventHandler()->iStatus==KRequestPending)))
  1.1159 +	    {
  1.1160 +#ifdef __WINS__
  1.1161 +	    RDebug::Print(_L("CStopTheScheduler::RunL - Stop - %d"), iCStopTheSchedulerRunCount);
  1.1162 +#endif
  1.1163 +	    CActiveScheduler::Stop();
  1.1164 +	    }
  1.1165 +	else
  1.1166 +	    {  
  1.1167 +#ifdef __WINS__
  1.1168 +	    RDebug::Print(_L("CStopTheScheduler::RunL - Call - %d"), iCStopTheSchedulerRunCount);
  1.1169 +#endif
  1.1170 +	    Call();
  1.1171 +	    }
  1.1172 +#ifdef __WINS__
  1.1173 +    RDebug::Print(_L("CStopTheScheduler::RunL - exit - %d"), iCStopTheSchedulerRunCount);
  1.1174 +    iCStopTheSchedulerRunCount++;
  1.1175 +#endif
  1.1176 +	}
  1.1177 +
  1.1178 +void WaitForRedrawsToFinish()
  1.1179 +	{
  1.1180 +	CStopTheScheduler* ps=new CStopTheScheduler(ETlibRedrawActivePriority-1);
  1.1181 +	if(ps)
  1.1182 +		{
  1.1183 +		ps->Call();
  1.1184 +		CActiveScheduler::Start();
  1.1185 +		delete ps;
  1.1186 +		}
  1.1187 +	}
  1.1188 +
  1.1189 +
  1.1190 +// CTEventBase //
  1.1191 +
  1.1192 +EXPORT_C CTEventBase::CTEventBase(RWsSession *aWs, TInt aPriority) : CActive(aPriority), iWs(aWs)
  1.1193 +	{
  1.1194 +	}
  1.1195 +
  1.1196 +EXPORT_C CTEventBase::~CTEventBase()
  1.1197 +	{
  1.1198 +	}
  1.1199 +
  1.1200 +EXPORT_C void CTEventBase::Construct()
  1.1201 +	{
  1.1202 +	CActiveScheduler::Add(this);
  1.1203 +	Request();
  1.1204 +	}
  1.1205 +
  1.1206 +EXPORT_C void CTEventBase::RunL()
  1.1207 +	{
  1.1208 +	if (iStatus==KErrNone)
  1.1209 +		{
  1.1210 +		++iCount;
  1.1211 +		TRAPD(err,doRunL());
  1.1212 +		if (err<=0)	// Positive value means this has been destroyed
  1.1213 +			{
  1.1214 +			if (iCancelRequested)
  1.1215 +				CancelHandler();
  1.1216 +			Request();
  1.1217 +//			if (err!=KErrNone)
  1.1218 +//				User::LeaveIfError(err); Should have a guaranteed to work error dialog here I guess
  1.1219 +			}
  1.1220 +		}
  1.1221 +	else if (iStatus==KErrCancel && iCancelRequested)
  1.1222 +		{
  1.1223 +		CancelHandler();
  1.1224 +		Request();
  1.1225 +		}
  1.1226 +	else
  1.1227 +		TbPanic(ETestBasePanicEventStat);
  1.1228 +	}
  1.1229 +
  1.1230 +void CTEventBase::SetCancelFunction(const TCallBack &aCallBack)
  1.1231 +	{
  1.1232 +	if (!IsActive() && iCancelRequested)
  1.1233 +		TbPanic(ETestBasePanicCancelFunction);
  1.1234 +	iCancelCallBack=aCallBack;
  1.1235 +	iCancelRequested=ETrue;
  1.1236 +	DoCancel();
  1.1237 +	}
  1.1238 +
  1.1239 +EXPORT_C void CTEventBase::CancelHandler()
  1.1240 +	{
  1.1241 +	iCancelCallBack.CallBack();
  1.1242 +	iCancelRequested=EFalse;
  1.1243 +	}
  1.1244 +
  1.1245 +// TLibWsEvent //
  1.1246 +
  1.1247 +EXPORT_C CTWindowGroup *TlibWsEvent::WindowGroup()
  1.1248 +	{
  1.1249 +	CTWindowGroup *group=(CTWindowGroup *)Handle();
  1.1250 +	__ASSERT_DEBUG(group->iType==EWinTypeGroup,TbPanic(ETestBasePanicWinType));
  1.1251 +	return(group);
  1.1252 +	}
  1.1253 +
  1.1254 +EXPORT_C CTBaseWin *TlibWsEvent::BaseWin()
  1.1255 +	{
  1.1256 +	CTBaseWin *win=(CTBaseWin *)Handle();
  1.1257 +	__ASSERT_DEBUG(win->iType==EWinTypeClient || win->iType==EWinTypeGroup,TbPanic(ETestBasePanicWinType));
  1.1258 +	return(win);
  1.1259 +	}
  1.1260 +
  1.1261 +// CTEvent //
  1.1262 +
  1.1263 +EXPORT_C CTEvent::CTEvent(RWsSession *aWs) : CTEventBase(aWs, ETlibWsEventActivePriority)
  1.1264 +	{
  1.1265 +	__DECLARE_NAME(_S("CTEvent"));
  1.1266 +	}
  1.1267 +
  1.1268 +EXPORT_C CTEvent::~CTEvent()
  1.1269 + 	{
  1.1270 +	Cancel();
  1.1271 +	}
  1.1272 +
  1.1273 +EXPORT_C void CTEvent::DoCancel()
  1.1274 +	{
  1.1275 +	iWs->EventReadyCancel();
  1.1276 +	}
  1.1277 +
  1.1278 +EXPORT_C void CTEvent::Request()
  1.1279 +	{
  1.1280 +	iWs->EventReady(&iStatus);
  1.1281 +	SetActive();
  1.1282 +	}
  1.1283 +
  1.1284 +EXPORT_C void CTEvent::LogEvent(const TWsEvent &)
  1.1285 +	{
  1.1286 +	}
  1.1287 +
  1.1288 +EXPORT_C void CTEvent::doRunL()
  1.1289 +	{
  1.1290 +	TlibWsEvent event;
  1.1291 +	
  1.1292 +	iWs->GetEvent(event);
  1.1293 +	LogEvent(event);
  1.1294 +	if (event.Handle()!=0 && event.Handle()!=ENullWsHandle)
  1.1295 +		{
  1.1296 +		switch(event.Type())
  1.1297 +			{
  1.1298 +			case EEventKey:
  1.1299 +				event.WindowGroup()->KeyL(*event.Key(),event.Time());
  1.1300 +				break;
  1.1301 +			case EEventKeyDown:
  1.1302 +				__ASSERT_ALWAYS(event.Key()->iCode==0 && event.Key()->iRepeats==0, TbPanic(ETestBasePanicKeyParams));
  1.1303 +				event.WindowGroup()->KeyDownL(*event.Key(),event.Time());
  1.1304 +				break;
  1.1305 +			case EEventKeyUp:
  1.1306 +				__ASSERT_ALWAYS(event.Key()->iCode==0 && event.Key()->iRepeats==0, TbPanic(ETestBasePanicKeyParams));
  1.1307 +				event.WindowGroup()->KeyUpL(*event.Key(),event.Time());
  1.1308 +				break;
  1.1309 +			case EEventModifiersChanged:
  1.1310 +				event.BaseWin()->ModifiersChanged(*event.ModifiersChanged(),event.Time());
  1.1311 +				break;
  1.1312 +			case EEventPointer:
  1.1313 +				event.BaseWin()->PointerL(*event.Pointer(),event.Time());
  1.1314 +				break;
  1.1315 +			case EEventDragDrop:
  1.1316 +				event.BaseWin()->DragDropL(*event.Pointer(),event.Time());
  1.1317 +				break;
  1.1318 +			case EEventPointerEnter:
  1.1319 +				event.BaseWin()->PointerEnter(event.Time());
  1.1320 +				break;
  1.1321 +			case EEventPointerExit:
  1.1322 +				event.BaseWin()->PointerExit(event.Time());
  1.1323 +				break;
  1.1324 +			case EEventPointerBufferReady:
  1.1325 +				event.BaseWin()->PointerBufferReady(event.Time());
  1.1326 +				break;
  1.1327 +			case EEventSwitchOn:
  1.1328 +				event.BaseWin()->SwitchOn(event.Time());
  1.1329 +				break;
  1.1330 +			case EEventFocusLost:
  1.1331 +				event.WindowGroup()->FocusLost();
  1.1332 +				break;
  1.1333 +			case EEventFocusGained:
  1.1334 +				event.WindowGroup()->FocusGained();
  1.1335 +				break;
  1.1336 +			case EEventPassword:
  1.1337 +				event.WindowGroup()->PasswordL(event.Time());
  1.1338 +				break;
  1.1339 +			case EEventMessageReady:
  1.1340 +				event.WindowGroup()->MessageReady(event);
  1.1341 +				break;
  1.1342 +			case EEventErrorMessage:
  1.1343 +				event.WindowGroup()->ErrorMessage(*event.ErrorMessage(), event.Time());
  1.1344 +				break;
  1.1345 +			case EEventSwitchOff:
  1.1346 +			case EEventKeySwitchOff:
  1.1347 +				{
  1.1348 +				TTimeIntervalMicroSeconds32 ii=1000000;
  1.1349 +				User::After(ii);			//WINS does not always work without this!
  1.1350 +				UserHal::SwitchOff();
  1.1351 +				}
  1.1352 +				break;
  1.1353 +			case EEventScreenDeviceChanged:
  1.1354 +				event.WindowGroup()->ScreenDeviceChanged();
  1.1355 +				break;
  1.1356 +			case EEventNull:
  1.1357 +				break;
  1.1358 +			default:
  1.1359 +				if (event.Type()>=EEventUser)
  1.1360 +					{
  1.1361 +					event.WindowGroup()->UserEvent(event.Type());
  1.1362 +					break;
  1.1363 +					}
  1.1364 +				else
  1.1365 +					{
  1.1366 +					//if not in BufferSecurity test - panic
  1.1367 +					TInt value = EFalse;
  1.1368 +					TInt err = RProperty::Get(KUidWServSecurityTesting,EWServSecTestBufferSecurity,value);
  1.1369 +					if ((err != KErrNone) || (value != (TInt)ETrue))
  1.1370 +						TbPanic(ETestBasePanicInvalidEvent);
  1.1371 +					}
  1.1372 +				break;
  1.1373 +			}
  1.1374 +		}
  1.1375 +	}
  1.1376 +
  1.1377 +EXPORT_C CTRedraw::CTRedraw(RWsSession *aWs) : CTEventBase(aWs, ETlibRedrawActivePriority)
  1.1378 +	{
  1.1379 +	__DECLARE_NAME(_S("CTRedraw"));
  1.1380 +	}
  1.1381 +
  1.1382 +EXPORT_C CTRedraw::~CTRedraw()
  1.1383 +	{
  1.1384 +	Cancel();
  1.1385 +	}
  1.1386 +
  1.1387 +EXPORT_C void CTRedraw::Request()
  1.1388 +	{
  1.1389 +	iWs->RedrawReady(&iStatus);
  1.1390 +	SetActive();
  1.1391 +	}
  1.1392 +
  1.1393 +EXPORT_C void CTRedraw::DoCancel()
  1.1394 +	{
  1.1395 +	iWs->RedrawReadyCancel();
  1.1396 +	}
  1.1397 +
  1.1398 +EXPORT_C void CTRedraw::doRunL()
  1.1399 +	{
  1.1400 +	TWsRedrawEvent redraw;
  1.1401 +	iWs->GetRedraw(redraw);
  1.1402 +	if (redraw.Handle()!=0 && redraw.Handle()!=ENullWsHandle)
  1.1403 +		{
  1.1404 +		__ASSERT_ALWAYS(!redraw.Rect().IsEmpty(),TbPanic(ETestBasePanicNullRedraw));
  1.1405 +		((CTWin *)redraw.Handle())->Redraw(redraw.Rect());
  1.1406 +		}
  1.1407 +	}
  1.1408 +
  1.1409 +EXPORT_C void CTUser::Splat(CTClient *aClient, const TRect &aRect, const TRgb &aRgb)
  1.1410 +	{
  1.1411 +	RBlankWindow win(aClient->iWs);
  1.1412 +	win.Construct(*(aClient->iGroup->WinTreeNode()),1);
  1.1413 +	win.SetColor(aRgb);
  1.1414 +	win.SetExtent(aRect.iTl,aRect.Size());
  1.1415 +	win.Activate();
  1.1416 +	aClient->iWs.Flush();
  1.1417 +	win.Close();
  1.1418 +	}
  1.1419 +
  1.1420 +void doTestLibStartUpL(TInt aScreenNumber, CTClient *&aClient, CActiveScheduler *&aActiveScheduler,CTrapCleanup *&aCleanUpStack,TCreateClientFunc aFunc)
  1.1421 +	{
  1.1422 +	User::LeaveIfNull(aCleanUpStack=CTrapCleanup::New());
  1.1423 +	aActiveScheduler=new(ELeave) CActiveScheduler;
  1.1424 +	CActiveScheduler::Install(aActiveScheduler);
  1.1425 +	aClient=aFunc();
  1.1426 +	aClient->SetScreenNumber(aScreenNumber);
  1.1427 +	aClient->ConstructL();
  1.1428 +	CActiveScheduler::Start();
  1.1429 +	}
  1.1430 +
  1.1431 +EXPORT_C TInt TestLibStartUp(TCreateClientFunc aFunc,TInt aScreenNumber)
  1.1432 +	{
  1.1433 +	__UHEAP_MARK;
  1.1434 +	CTrapCleanup* cleanUpStack=NULL;
  1.1435 +	CActiveScheduler *activeScheduler=NULL;
  1.1436 +	CTClient *client=NULL;
  1.1437 +	TRAPD(err,doTestLibStartUpL(aScreenNumber, client,activeScheduler,cleanUpStack,aFunc));
  1.1438 +	delete client;
  1.1439 +	delete activeScheduler;
  1.1440 +	delete cleanUpStack;
  1.1441 +	__UHEAP_MARKEND;
  1.1442 +	return(err);
  1.1443 +	}
  1.1444 +
  1.1445 +EXPORT_C TInt TestLibStartUp(TCreateClientFunc aFunc)
  1.1446 +	{
  1.1447 +	return TestLibStartUp(aFunc, KDefaultScreen);
  1.1448 +	}
  1.1449 +