sl@0: // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Maintains a window displaying last event details sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "testbase.h" sl@0: sl@0: const TInt NumLogLinesPerEvent=2; sl@0: sl@0: sl@0: // sl@0: // Event window // sl@0: // sl@0: sl@0: EXPORT_C CEventWindow::CEventWindow(TInt aLogSize) : CTWin(), iLogSize(aLogSize) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CEventWindow::~CEventWindow() sl@0: { sl@0: delete[] iLoggedEvents; sl@0: RelinquishFocus(); sl@0: } sl@0: sl@0: EXPORT_C void CEventWindow::ConstructL(CTWinBase &parent) sl@0: { sl@0: CTWin::ConstructL(parent); sl@0: iLineHeight=iFont->HeightInPixels()+2; sl@0: iLoggedEvents=new(ELeave) TWsEvent[iLogSize]; sl@0: iWin.EnableModifierChangedEvents(EModifierFunc|EModifierCapsLock|EModifierNumLock, EEventControlAlways); sl@0: iWin.EnableOnEvents(EEventControlAlways); sl@0: } sl@0: sl@0: EXPORT_C void CEventWindow::SetUpL(const TPoint &pos, CTWinBase *parent, CWindowGc &aGc) sl@0: { sl@0: TRAPD(err,ConstructL(*parent)); sl@0: if (err!=KErrNone) sl@0: { sl@0: delete this; sl@0: User::Leave(err); sl@0: } sl@0: SetExt(pos,TSize(600,iLineHeight*NumLogLinesPerEvent*iLogSize)); sl@0: Activate(); sl@0: AssignGC(aGc); sl@0: } sl@0: sl@0: void CEventWindow::DrawLine(TInt aLine, const TDesC &aText) sl@0: { sl@0: iGc->DrawText(aText, TPoint(10,iLineHeight*aLine+iFont->AscentInPixels()+1)); sl@0: } sl@0: sl@0: void CEventWindow::LogEvent(TInt aLogNum, const TWsEvent &aEvent) sl@0: { sl@0: TBuf<0x80> buf1; sl@0: TBuf<0x80> buf2; sl@0: TPtrC type(_L("Unknown event type")); sl@0: TKeyEvent *key=aEvent.Key(); sl@0: switch(aEvent.Type()) sl@0: { sl@0: case EEventKey: sl@0: type.Set(_L("EEventKey")); sl@0: buf2.Format(TRefByValue(_L("Code=%d [%c], ScanCode=0x%x, Modifiers=0x%04x, repeats=%d")), key->iCode, key->iCode, key->iScanCode,key->iModifiers,key->iRepeats); sl@0: break; sl@0: case EEventKeyUp: sl@0: type.Set(_L("EEventKeyUp")); sl@0: buf2.Format(TRefByValue(_L("scanCode=0x%x, Modifiers=0x%04x")), key->iScanCode, key->iModifiers); sl@0: break; sl@0: case EEventKeyDown: sl@0: type.Set(_L("EEventKeyDown")); sl@0: buf2.Format(TRefByValue(_L("scanCode=0x%x, Modifiers=0x%04x")), key->iScanCode, key->iModifiers); sl@0: break; sl@0: case EEventPointer: sl@0: { sl@0: TPointerEvent *pointer=aEvent.Pointer(); sl@0: TPtrC ptrType(_L("Unknown pointer event")); sl@0: switch(pointer->iType) sl@0: { sl@0: case TPointerEvent::EButton1Up: sl@0: ptrType.Set(_L("EButton1Up")); sl@0: break; sl@0: case TPointerEvent::EButton3Up: sl@0: ptrType.Set(_L("EButton3Up")); sl@0: break; sl@0: case TPointerEvent::EButton2Up: sl@0: ptrType.Set(_L("EButton2Up")); sl@0: break; sl@0: case TPointerEvent::EButton1Down: sl@0: ptrType.Set(_L("EButton1Down")); sl@0: break; sl@0: case TPointerEvent::EButton3Down: sl@0: ptrType.Set(_L("EButton3Down")); sl@0: break; sl@0: case TPointerEvent::EButton2Down: sl@0: ptrType.Set(_L("EButton2Down")); sl@0: break; sl@0: case TPointerEvent::EDrag: sl@0: ptrType.Set(_L("EDrag")); sl@0: break; sl@0: case TPointerEvent::EMove: sl@0: ptrType.Set(_L("EMove")); sl@0: break; sl@0: case TPointerEvent::EButtonRepeat: sl@0: ptrType.Set(_L("EButtonRepeat")); sl@0: break; sl@0: case TPointerEvent::ESwitchOn: sl@0: ptrType.Set(_L("ESwitchOn")); sl@0: break; sl@0: } sl@0: type.Set(_L("EEventPointer")); sl@0: buf2.Format(TRefByValue(_L("Type=%S, state=0x%x, pos={%d,%d}, parent pos={%d,%d}")),&ptrType, pointer->iModifiers, sl@0: pointer->iPosition.iX,pointer->iPosition.iY,pointer->iParentPosition.iX,pointer->iParentPosition.iY); sl@0: } sl@0: break; sl@0: case EEventPointerEnter: sl@0: type.Set(_L("EEventPointerEnter")); sl@0: break; sl@0: case EEventPointerExit: sl@0: type.Set(_L("EEventPointerExit")); sl@0: break; sl@0: case EEventSwitchOn: sl@0: type.Set(_L("EEventSwitchOn")); sl@0: break; sl@0: case EEventModifiersChanged: sl@0: type.Set(_L("EEventModifiersChanged")); sl@0: buf2.Format(TRefByValue(_L("Changed=0x%x, State=0x%x ")),aEvent.ModifiersChanged()->iChangedModifiers,aEvent.ModifiersChanged()->iModifiers); sl@0: break; sl@0: case EEventFocusLost: sl@0: type.Set(_L("EEventFocusLost")); sl@0: break; sl@0: case EEventFocusGained: sl@0: type.Set(_L("EEventFocusGained")); sl@0: break; sl@0: default:; sl@0: } sl@0: TBuf<20> timeBuf; sl@0: _LIT(TimeDisc,"%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S%:3"); sl@0: TRAPD(err,aEvent.Time().FormatL(timeBuf,TimeDisc)); sl@0: if (err!=KErrNone) sl@0: { sl@0: _LIT(DummyTime,"########"); sl@0: timeBuf.Append(DummyTime); sl@0: } sl@0: buf1.Format(TRefByValue(_L("%d: %S [%x], %S")), iCount-aLogNum, &type, aEvent.Handle(), &timeBuf); sl@0: TInt baseLine=(iLogSize-aLogNum-1)*NumLogLinesPerEvent; sl@0: DrawLine(baseLine+0,buf1); sl@0: DrawLine(baseLine+1,buf2); sl@0: } sl@0: sl@0: EXPORT_C void CEventWindow::Draw() sl@0: { sl@0: DrawBorder(); sl@0: for(TInt index=0;index0;index--) sl@0: iLoggedEvents[index]=iLoggedEvents[index-1]; sl@0: iLoggedEvents[0]=aEvent; sl@0: DrawNow(); sl@0: } sl@0: sl@0: sl@0: // sl@0: // Blank window, just sort of sits there looking blank // sl@0: // sl@0: sl@0: EXPORT_C TBool CheckBlankWindow(TRect aArea,TRgb aColor,const CWsScreenDevice* aScreen) sl@0: // sl@0: // Returns ETrue if the the given rect is all the specified color sl@0: // EFalse if it is not sl@0: // sl@0: { sl@0: TInt wid=aArea.Width(); sl@0: TAny *buf2=User::AllocL(wid*sizeof(TRgb)); sl@0: TRgb *pRgb=(TRgb *)buf2; sl@0: Mem::FillZ(buf2,wid*sizeof(TRgb)); sl@0: //TRgb tmp(TRgb::Gray16(aColor.Gray16())); sl@0: //Truncate color to match color conversion in EColor64K mode before comparison sl@0: if (aScreen->DisplayMode()==EColor64K) sl@0: aColor=TRgb::Color64K(aColor.Color64K()); sl@0: for(TInt i=0;i(buf2),wid*sizeof(TRgb),wid*sizeof(TRgb)); sl@0: sl@0: TAny *buf=User::AllocL(wid*sizeof(TRgb)); sl@0: TPtr8 rgbBuf(reinterpret_cast(buf),wid*sizeof(TRgb)); sl@0: sl@0: TBool ret=ETrue; sl@0: TPoint offset=aArea.iTl; //iWin.InquireOffset(*TheClient->iGroup->WinTreeNode()); sl@0: for(;offset.iYGetScanLine(rgbBuf,offset,wid,EColor16MA); sl@0: if (rgbBuf.Compare(tstBuf)!=0) sl@0: { sl@0: ret=EFalse; sl@0: break; sl@0: } sl@0: } sl@0: User::FreeZ(buf); sl@0: User::FreeZ(buf2); sl@0: return(ret); sl@0: } sl@0: sl@0: EXPORT_C CBlankWindow::CBlankWindow() : CTWin() sl@0: { sl@0: iCol=TRgb::Gray256(128); sl@0: } sl@0: sl@0: EXPORT_C CBlankWindow::CBlankWindow(TRgb aCol) : CTWin(), iCol(aCol), iRealDraw(EFalse) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CBlankWindow::ConstructL(CTWinBase &parent) sl@0: { sl@0: CTWin::ConstructL(parent); sl@0: iWin.SetBackgroundColor(iCol); sl@0: } sl@0: sl@0: EXPORT_C void CBlankWindow::SetColor(TRgb aColor) sl@0: { sl@0: iCol=aColor; sl@0: } sl@0: sl@0: EXPORT_C void CBlankWindow::RealDraw(TBool aRealDraw) sl@0: { sl@0: iRealDraw=aRealDraw; sl@0: } sl@0: sl@0: EXPORT_C void CBlankWindow::Draw() sl@0: { sl@0: if (!iRealDraw) sl@0: iGc->Clear(); sl@0: else sl@0: { sl@0: iGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: iGc->SetBrushColor(iCol); sl@0: iGc->DrawRect(TRect(iSize)); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CBlankWindow::DrawNow() sl@0: { sl@0: iWin.Invalidate(); sl@0: iWin.BeginRedraw(); sl@0: iGc->Activate(iWin); sl@0: Draw(); sl@0: iGc->Deactivate(); sl@0: iWin.EndRedraw(); sl@0: } sl@0: sl@0: EXPORT_C void CBlankWindow::DrawNow(TRect& aRect) sl@0: { sl@0: iWin.Invalidate(aRect); sl@0: iWin.BeginRedraw(aRect); sl@0: iGc->Activate(iWin); sl@0: iGc->SetClippingRect(aRect); sl@0: Draw(); sl@0: iGc->Deactivate(); sl@0: iWin.EndRedraw(); sl@0: } sl@0: sl@0: EXPORT_C TBool CBlankWindow::Check(const CTClient& aClient) sl@0: // sl@0: // Returns ETrue if the window is Ok, sl@0: // EFalse if it is not sl@0: // sl@0: { sl@0: return CheckBlankWindow(TRect(iWin.InquireOffset(*aClient.iGroup->WinTreeNode()),Size()),TRgb::Gray16(iCol.Gray16()),aClient.iScreen); sl@0: }