os/graphics/windowing/windowserver/test/tlib/TLEVENT.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Maintains a window displaying last event details
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <w32std.h>
sl@0
    20
#include <e32svr.h>
sl@0
    21
#include "testbase.h"
sl@0
    22
sl@0
    23
const TInt NumLogLinesPerEvent=2;
sl@0
    24
sl@0
    25
sl@0
    26
//
sl@0
    27
// Event window //
sl@0
    28
//
sl@0
    29
sl@0
    30
EXPORT_C CEventWindow::CEventWindow(TInt aLogSize) : CTWin(), iLogSize(aLogSize)
sl@0
    31
	{
sl@0
    32
	}
sl@0
    33
sl@0
    34
EXPORT_C CEventWindow::~CEventWindow()
sl@0
    35
	{
sl@0
    36
	delete[] iLoggedEvents;
sl@0
    37
	RelinquishFocus();
sl@0
    38
	}
sl@0
    39
sl@0
    40
EXPORT_C void CEventWindow::ConstructL(CTWinBase &parent)
sl@0
    41
	{
sl@0
    42
	CTWin::ConstructL(parent);
sl@0
    43
	iLineHeight=iFont->HeightInPixels()+2;
sl@0
    44
	iLoggedEvents=new(ELeave) TWsEvent[iLogSize];
sl@0
    45
	iWin.EnableModifierChangedEvents(EModifierFunc|EModifierCapsLock|EModifierNumLock, EEventControlAlways);
sl@0
    46
	iWin.EnableOnEvents(EEventControlAlways);
sl@0
    47
	}
sl@0
    48
sl@0
    49
EXPORT_C void CEventWindow::SetUpL(const TPoint &pos, CTWinBase *parent, CWindowGc &aGc)
sl@0
    50
	{
sl@0
    51
	TRAPD(err,ConstructL(*parent));
sl@0
    52
	if (err!=KErrNone)
sl@0
    53
		{
sl@0
    54
		delete this;
sl@0
    55
		User::Leave(err);
sl@0
    56
		}
sl@0
    57
	SetExt(pos,TSize(600,iLineHeight*NumLogLinesPerEvent*iLogSize));
sl@0
    58
	Activate();
sl@0
    59
	AssignGC(aGc);
sl@0
    60
	}
sl@0
    61
sl@0
    62
void CEventWindow::DrawLine(TInt aLine, const TDesC &aText)
sl@0
    63
	{
sl@0
    64
	iGc->DrawText(aText, TPoint(10,iLineHeight*aLine+iFont->AscentInPixels()+1));
sl@0
    65
	}
sl@0
    66
sl@0
    67
void CEventWindow::LogEvent(TInt aLogNum, const TWsEvent &aEvent)
sl@0
    68
	{
sl@0
    69
	TBuf<0x80> buf1;
sl@0
    70
	TBuf<0x80> buf2;
sl@0
    71
	TPtrC type(_L("Unknown event type"));
sl@0
    72
	TKeyEvent *key=aEvent.Key();
sl@0
    73
	switch(aEvent.Type())
sl@0
    74
		{
sl@0
    75
		case EEventKey:
sl@0
    76
			type.Set(_L("EEventKey"));
sl@0
    77
			buf2.Format(TRefByValue<const TDesC>(_L("Code=%d [%c], ScanCode=0x%x, Modifiers=0x%04x, repeats=%d")), key->iCode, key->iCode, key->iScanCode,key->iModifiers,key->iRepeats);
sl@0
    78
			break;
sl@0
    79
		case EEventKeyUp:
sl@0
    80
			type.Set(_L("EEventKeyUp"));
sl@0
    81
			buf2.Format(TRefByValue<const TDesC>(_L("scanCode=0x%x, Modifiers=0x%04x")), key->iScanCode, key->iModifiers);
sl@0
    82
			break;
sl@0
    83
		case EEventKeyDown:
sl@0
    84
			type.Set(_L("EEventKeyDown"));
sl@0
    85
			buf2.Format(TRefByValue<const TDesC>(_L("scanCode=0x%x, Modifiers=0x%04x")), key->iScanCode, key->iModifiers);
sl@0
    86
			break;
sl@0
    87
		case EEventPointer:
sl@0
    88
			{
sl@0
    89
			TPointerEvent *pointer=aEvent.Pointer();
sl@0
    90
			TPtrC ptrType(_L("Unknown pointer event"));
sl@0
    91
			switch(pointer->iType)	
sl@0
    92
				{
sl@0
    93
				case TPointerEvent::EButton1Up:
sl@0
    94
					ptrType.Set(_L("EButton1Up"));
sl@0
    95
					break;
sl@0
    96
				case TPointerEvent::EButton3Up:
sl@0
    97
					ptrType.Set(_L("EButton3Up"));
sl@0
    98
					break;
sl@0
    99
				case TPointerEvent::EButton2Up:
sl@0
   100
					ptrType.Set(_L("EButton2Up"));
sl@0
   101
					break;
sl@0
   102
				case TPointerEvent::EButton1Down:
sl@0
   103
					ptrType.Set(_L("EButton1Down"));
sl@0
   104
					break;
sl@0
   105
				case TPointerEvent::EButton3Down:
sl@0
   106
					ptrType.Set(_L("EButton3Down"));
sl@0
   107
					break;
sl@0
   108
				case TPointerEvent::EButton2Down:
sl@0
   109
					ptrType.Set(_L("EButton2Down"));
sl@0
   110
					break;
sl@0
   111
				case TPointerEvent::EDrag:
sl@0
   112
					ptrType.Set(_L("EDrag"));
sl@0
   113
					break;
sl@0
   114
				case TPointerEvent::EMove:
sl@0
   115
					ptrType.Set(_L("EMove"));
sl@0
   116
					break;
sl@0
   117
				case TPointerEvent::EButtonRepeat:
sl@0
   118
					ptrType.Set(_L("EButtonRepeat"));
sl@0
   119
					break;
sl@0
   120
				case TPointerEvent::ESwitchOn:
sl@0
   121
					ptrType.Set(_L("ESwitchOn"));
sl@0
   122
					break;
sl@0
   123
				}
sl@0
   124
			type.Set(_L("EEventPointer"));
sl@0
   125
			buf2.Format(TRefByValue<const TDesC>(_L("Type=%S, state=0x%x, pos={%d,%d}, parent pos={%d,%d}")),&ptrType, pointer->iModifiers,
sl@0
   126
				pointer->iPosition.iX,pointer->iPosition.iY,pointer->iParentPosition.iX,pointer->iParentPosition.iY);
sl@0
   127
			}
sl@0
   128
			break;
sl@0
   129
		case EEventPointerEnter:
sl@0
   130
			type.Set(_L("EEventPointerEnter"));
sl@0
   131
			break;
sl@0
   132
		case EEventPointerExit:
sl@0
   133
			type.Set(_L("EEventPointerExit"));
sl@0
   134
			break;
sl@0
   135
		case EEventSwitchOn:
sl@0
   136
			type.Set(_L("EEventSwitchOn"));
sl@0
   137
			break;
sl@0
   138
		case EEventModifiersChanged:
sl@0
   139
			type.Set(_L("EEventModifiersChanged"));
sl@0
   140
			buf2.Format(TRefByValue<const TDesC>(_L("Changed=0x%x, State=0x%x ")),aEvent.ModifiersChanged()->iChangedModifiers,aEvent.ModifiersChanged()->iModifiers);
sl@0
   141
			break;
sl@0
   142
		case EEventFocusLost:
sl@0
   143
			type.Set(_L("EEventFocusLost"));
sl@0
   144
			break;
sl@0
   145
		case EEventFocusGained:
sl@0
   146
			type.Set(_L("EEventFocusGained"));
sl@0
   147
			break;
sl@0
   148
		default:;
sl@0
   149
		}
sl@0
   150
	TBuf<20> timeBuf;
sl@0
   151
	_LIT(TimeDisc,"%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S%:3");
sl@0
   152
	TRAPD(err,aEvent.Time().FormatL(timeBuf,TimeDisc));
sl@0
   153
	if (err!=KErrNone)
sl@0
   154
		{
sl@0
   155
		_LIT(DummyTime,"########");
sl@0
   156
		timeBuf.Append(DummyTime);
sl@0
   157
		}
sl@0
   158
	buf1.Format(TRefByValue<const TDesC>(_L("%d: %S [%x], %S")), iCount-aLogNum, &type, aEvent.Handle(), &timeBuf);
sl@0
   159
	TInt baseLine=(iLogSize-aLogNum-1)*NumLogLinesPerEvent;
sl@0
   160
	DrawLine(baseLine+0,buf1);
sl@0
   161
	DrawLine(baseLine+1,buf2);
sl@0
   162
	}
sl@0
   163
sl@0
   164
EXPORT_C void CEventWindow::Draw()
sl@0
   165
	{
sl@0
   166
	DrawBorder();
sl@0
   167
	for(TInt index=0;index<iNumLogged;index++)
sl@0
   168
		LogEvent(index,iLoggedEvents[index]);
sl@0
   169
	}
sl@0
   170
sl@0
   171
EXPORT_C void CEventWindow::WinKeyL(const TKeyEvent &,const TTime&)
sl@0
   172
	{
sl@0
   173
	}
sl@0
   174
sl@0
   175
EXPORT_C void CEventWindow::LogEvent(const TWsEvent &aEvent)
sl@0
   176
	{
sl@0
   177
	iCount++;
sl@0
   178
	if (iNumLogged<iLogSize)
sl@0
   179
		iNumLogged++;
sl@0
   180
	for(TInt index=iNumLogged-1;index>0;index--)
sl@0
   181
		iLoggedEvents[index]=iLoggedEvents[index-1];
sl@0
   182
	iLoggedEvents[0]=aEvent;
sl@0
   183
	DrawNow();
sl@0
   184
	}
sl@0
   185
sl@0
   186
sl@0
   187
//
sl@0
   188
// Blank window, just sort of sits there looking blank //
sl@0
   189
//
sl@0
   190
sl@0
   191
EXPORT_C TBool CheckBlankWindow(TRect aArea,TRgb aColor,const CWsScreenDevice* aScreen)
sl@0
   192
//
sl@0
   193
// Returns ETrue if the the given rect is all the specified color
sl@0
   194
// EFalse if it is not
sl@0
   195
//
sl@0
   196
	{
sl@0
   197
	TInt wid=aArea.Width();
sl@0
   198
	TAny *buf2=User::AllocL(wid*sizeof(TRgb));
sl@0
   199
	TRgb *pRgb=(TRgb *)buf2;
sl@0
   200
	Mem::FillZ(buf2,wid*sizeof(TRgb));
sl@0
   201
	//TRgb tmp(TRgb::Gray16(aColor.Gray16()));
sl@0
   202
	//Truncate color to match color conversion in EColor64K mode before comparison
sl@0
   203
	if (aScreen->DisplayMode()==EColor64K)
sl@0
   204
		aColor=TRgb::Color64K(aColor.Color64K());
sl@0
   205
	for(TInt i=0;i<wid;i++,pRgb++)
sl@0
   206
		*pRgb=aColor;
sl@0
   207
	TPtr8 tstBuf(reinterpret_cast<TUint8*>(buf2),wid*sizeof(TRgb),wid*sizeof(TRgb));
sl@0
   208
sl@0
   209
	TAny *buf=User::AllocL(wid*sizeof(TRgb));
sl@0
   210
	TPtr8 rgbBuf(reinterpret_cast<TUint8*>(buf),wid*sizeof(TRgb));
sl@0
   211
sl@0
   212
	TBool ret=ETrue;
sl@0
   213
	TPoint offset=aArea.iTl;		//iWin.InquireOffset(*TheClient->iGroup->WinTreeNode());
sl@0
   214
	for(;offset.iY<aArea.iBr.iY;offset.iY++)
sl@0
   215
		{
sl@0
   216
		aScreen->GetScanLine(rgbBuf,offset,wid,EColor16MA);
sl@0
   217
		if (rgbBuf.Compare(tstBuf)!=0)
sl@0
   218
			{
sl@0
   219
			ret=EFalse;
sl@0
   220
			break;
sl@0
   221
			}
sl@0
   222
		}
sl@0
   223
	User::FreeZ(buf);
sl@0
   224
	User::FreeZ(buf2);
sl@0
   225
	return(ret);
sl@0
   226
	}
sl@0
   227
sl@0
   228
EXPORT_C CBlankWindow::CBlankWindow() : CTWin()
sl@0
   229
	{
sl@0
   230
	iCol=TRgb::Gray256(128);
sl@0
   231
	}
sl@0
   232
sl@0
   233
EXPORT_C CBlankWindow::CBlankWindow(TRgb aCol) : CTWin(), iCol(aCol), iRealDraw(EFalse)
sl@0
   234
	{
sl@0
   235
	}
sl@0
   236
sl@0
   237
EXPORT_C void CBlankWindow::ConstructL(CTWinBase &parent)
sl@0
   238
	{
sl@0
   239
	CTWin::ConstructL(parent);
sl@0
   240
	iWin.SetBackgroundColor(iCol);
sl@0
   241
	}
sl@0
   242
sl@0
   243
EXPORT_C void CBlankWindow::SetColor(TRgb aColor)
sl@0
   244
	{
sl@0
   245
	iCol=aColor;
sl@0
   246
	}
sl@0
   247
sl@0
   248
EXPORT_C void CBlankWindow::RealDraw(TBool aRealDraw)
sl@0
   249
	{
sl@0
   250
	iRealDraw=aRealDraw;
sl@0
   251
	}
sl@0
   252
sl@0
   253
EXPORT_C void CBlankWindow::Draw()
sl@0
   254
	{
sl@0
   255
	if (!iRealDraw)
sl@0
   256
		iGc->Clear();
sl@0
   257
	else
sl@0
   258
		{
sl@0
   259
		iGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   260
		iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   261
		iGc->SetBrushColor(iCol);
sl@0
   262
		iGc->DrawRect(TRect(iSize));
sl@0
   263
		}
sl@0
   264
	}
sl@0
   265
sl@0
   266
EXPORT_C void CBlankWindow::DrawNow()
sl@0
   267
	{
sl@0
   268
	iWin.Invalidate();
sl@0
   269
	iWin.BeginRedraw();
sl@0
   270
	iGc->Activate(iWin);
sl@0
   271
	Draw();
sl@0
   272
	iGc->Deactivate();
sl@0
   273
	iWin.EndRedraw();
sl@0
   274
	}
sl@0
   275
sl@0
   276
EXPORT_C void CBlankWindow::DrawNow(TRect& aRect)
sl@0
   277
	{
sl@0
   278
	iWin.Invalidate(aRect);
sl@0
   279
	iWin.BeginRedraw(aRect);
sl@0
   280
	iGc->Activate(iWin);
sl@0
   281
	iGc->SetClippingRect(aRect);
sl@0
   282
	Draw();
sl@0
   283
	iGc->Deactivate();
sl@0
   284
	iWin.EndRedraw();
sl@0
   285
	}
sl@0
   286
sl@0
   287
EXPORT_C TBool CBlankWindow::Check(const CTClient& aClient)
sl@0
   288
//
sl@0
   289
// Returns ETrue if the window is Ok,
sl@0
   290
// EFalse if it is not
sl@0
   291
//
sl@0
   292
	{
sl@0
   293
	return CheckBlankWindow(TRect(iWin.InquireOffset(*aClient.iGroup->WinTreeNode()),Size()),TRgb::Gray16(iCol.Gray16()),aClient.iScreen);
sl@0
   294
	}