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