|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent |
|
20 */ |
|
21 |
|
22 #include "compwin.h" |
|
23 #include "utils.h" |
|
24 #include "crpwin.h" |
|
25 #include "edgedwin.h" |
|
26 #include "coordinatewin.h" |
|
27 #include "backedupwin.h" |
|
28 #include "enormouswin.h" |
|
29 #include "spritewin.h" |
|
30 #include "animatedwin.h" |
|
31 |
|
32 #include "test_step_logger.h" |
|
33 #include "test_step_comparison.h" |
|
34 #include "stresslet.h" |
|
35 #include "comparison.h" |
|
36 |
|
37 //static configuration data, definitions and default assignments |
|
38 TInt CCompWin::sBackgroundAlpha = 0; |
|
39 |
|
40 //configuration parameter names |
|
41 _LIT(KT_WservStressParamBackgroundAlpha, "background_alpha"); |
|
42 |
|
43 |
|
44 /** |
|
45 BASE COMPARISON WINDOW |
|
46 */ |
|
47 CCompWin* CCompWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc) |
|
48 { |
|
49 typedef CCompWin* (*TPtrNewLC)(RWsSession&, RWindowGroup*, CCompWin*, CWindowGc&); |
|
50 TPtrNewLC winFactory[8]; |
|
51 TInt numEnabledWindows = 0; |
|
52 |
|
53 //setup an array of factory functions, one for each enabled window type |
|
54 if (CAnimatedWin::IsEnabled()) |
|
55 { |
|
56 winFactory[numEnabledWindows++] = TPtrNewLC(CAnimatedWin::NewLC); |
|
57 } |
|
58 if (CCoordinateWin::IsEnabled()) |
|
59 { |
|
60 winFactory[numEnabledWindows++] = TPtrNewLC(CCoordinateWin::NewLC); |
|
61 } |
|
62 if (CBackedupWin::IsEnabled()) |
|
63 { |
|
64 winFactory[numEnabledWindows++] = TPtrNewLC(CBackedupWin::NewLC); |
|
65 } |
|
66 if (CEnormousWin::IsEnabled()) |
|
67 { |
|
68 winFactory[numEnabledWindows++] = TPtrNewLC(CEnormousWin::NewLC); |
|
69 } |
|
70 if (CCrpWin::IsEnabled()) |
|
71 { |
|
72 winFactory[numEnabledWindows++] = TPtrNewLC(CCrpWin::NewLC); |
|
73 } |
|
74 if (CEdgedWin::IsEnabled()) |
|
75 { |
|
76 winFactory[numEnabledWindows++] = TPtrNewLC(CEdgedWin::NewLC); |
|
77 } |
|
78 if (CSpritedWin::IsEnabled()) |
|
79 { |
|
80 winFactory[numEnabledWindows++] = TPtrNewLC(CSpritedWin::NewLC); |
|
81 } |
|
82 |
|
83 if (numEnabledWindows == 0) |
|
84 { |
|
85 aWs.LogMessage(_L("Error: No window-type is enabled(see ini file)")); |
|
86 User::Leave(KErrNotFound); |
|
87 } |
|
88 |
|
89 TInt winType = TRnd::rnd(numEnabledWindows); |
|
90 CCompWin* self = winFactory[ winType ](aWs, aGroup, aParent, aGc); |
|
91 return self; |
|
92 } |
|
93 |
|
94 void CCompWin::LoadConfiguration(const MTestStepConfigurationContext* aContext) |
|
95 { |
|
96 aContext->GetInt(KT_WservStressParamBackgroundAlpha, sBackgroundAlpha); |
|
97 } |
|
98 |
|
99 /** |
|
100 Get a random TDrawMode value. |
|
101 */ |
|
102 CGraphicsContext::TDrawMode CCompWin::GetRandomDrawMode() |
|
103 { |
|
104 static CGraphicsContext::TDrawMode modes[] = |
|
105 { |
|
106 CGraphicsContext::EDrawModeAND, CGraphicsContext::EDrawModeNOTAND, |
|
107 CGraphicsContext::EDrawModePEN, CGraphicsContext::EDrawModeANDNOT, |
|
108 CGraphicsContext::EDrawModeXOR, CGraphicsContext::EDrawModeOR, |
|
109 CGraphicsContext::EDrawModeNOTANDNOT, CGraphicsContext::EDrawModeNOTXOR, |
|
110 CGraphicsContext::EDrawModeNOTSCREEN, CGraphicsContext::EDrawModeNOTOR, |
|
111 CGraphicsContext::EDrawModeNOTPEN, CGraphicsContext::EDrawModeORNOT, |
|
112 CGraphicsContext::EDrawModeNOTORNOT, CGraphicsContext::EDrawModeWriteAlpha |
|
113 }; |
|
114 return modes[TRnd::rnd(sizeof(modes)/sizeof(CGraphicsContext::TDrawMode))]; |
|
115 } |
|
116 |
|
117 CGraphicsContext::TPenStyle CCompWin::GetRandomPenStyle() |
|
118 { |
|
119 static CGraphicsContext::TPenStyle styles[] = |
|
120 { |
|
121 CGraphicsContext::ENullPen, |
|
122 CGraphicsContext::ESolidPen, |
|
123 CGraphicsContext::EDottedPen, |
|
124 CGraphicsContext::EDashedPen, |
|
125 CGraphicsContext::EDotDashPen, |
|
126 CGraphicsContext::EDotDotDashPen |
|
127 }; |
|
128 return styles[TRnd::rnd(sizeof(styles)/sizeof(CGraphicsContext::TPenStyle))]; |
|
129 } |
|
130 |
|
131 CGraphicsContext::TBrushStyle CCompWin::GetRandomBrushStyle() |
|
132 { |
|
133 //CGraphicsContext::EPatternedBrush is not joined in the test in current version. |
|
134 static CGraphicsContext::TBrushStyle styles[] = |
|
135 { |
|
136 CGraphicsContext::ENullBrush, |
|
137 CGraphicsContext::ESolidBrush, |
|
138 CGraphicsContext::EVerticalHatchBrush, |
|
139 CGraphicsContext::EForwardDiagonalHatchBrush, |
|
140 CGraphicsContext::EHorizontalHatchBrush, |
|
141 CGraphicsContext::ERearwardDiagonalHatchBrush, |
|
142 CGraphicsContext::ESquareCrossHatchBrush, |
|
143 CGraphicsContext::EDiamondCrossHatchBrush |
|
144 }; |
|
145 return styles[TRnd::rnd(sizeof(styles)/sizeof(CGraphicsContext::TBrushStyle))]; |
|
146 } |
|
147 |
|
148 CCompWin::CCompWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc) : |
|
149 iWs(aWs), |
|
150 iGroup(aGroup), |
|
151 iParent(aParent), |
|
152 iWsGc(aGc) |
|
153 { |
|
154 } |
|
155 |
|
156 CCompWin::~CCompWin() |
|
157 { |
|
158 iChildren.ResetAndDestroy(); |
|
159 |
|
160 if (iParent) |
|
161 { |
|
162 iParent->RemoveChild(this); |
|
163 } |
|
164 |
|
165 if (iWindow) |
|
166 { |
|
167 iWindow->Close(); |
|
168 delete iWindow; |
|
169 } |
|
170 } |
|
171 |
|
172 void CCompWin::PreConstructL(TBool aTransparency, TBool aBackedup) |
|
173 { |
|
174 if (aBackedup) |
|
175 { |
|
176 iWindow = iBackedupWindow = new(ELeave) RBackedUpWindow(iWs); |
|
177 if (iParent) |
|
178 { |
|
179 User::LeaveIfError(iBackedupWindow->Construct(*iParent->Window(), EColor64K, (TUint32)(this))); |
|
180 iParent->AddChildL(this); |
|
181 } |
|
182 else |
|
183 { |
|
184 User::LeaveIfError(iBackedupWindow->Construct(*iGroup, EColor64K, (TUint32)(this))); |
|
185 } |
|
186 } |
|
187 else |
|
188 { |
|
189 iWindow = iRedrawWindow = new(ELeave) RWindow(iWs); |
|
190 if (iParent) |
|
191 { |
|
192 User::LeaveIfError(iRedrawWindow->Construct(*iParent->Window(), (TUint32)(this))); |
|
193 iParent->AddChildL(this); |
|
194 } |
|
195 else |
|
196 { |
|
197 User::LeaveIfError(iRedrawWindow->Construct(*iGroup, (TUint32)(this))); |
|
198 } |
|
199 } |
|
200 if (iRedrawWindow) |
|
201 { |
|
202 if (aTransparency) |
|
203 { |
|
204 iRedrawWindow->SetTransparencyAlphaChannel(); |
|
205 } |
|
206 /* Note: if background color is set to include a transparent background |
|
207 * and AUTOCLEAR is set to 1 in wsini.ini, window's background will not be |
|
208 * totaly cleared. |
|
209 */ |
|
210 iRedrawWindow->SetBackgroundColor(BackgroundColor()); |
|
211 } |
|
212 |
|
213 iPos.iX = TRnd::rnd(KPosLimit); |
|
214 iPos.iY = TRnd::rnd(KPosLimit); |
|
215 iSize.iWidth = TRnd::rnd(KPosLimit); |
|
216 iSize.iHeight = TRnd::rnd(KPosLimit); |
|
217 iPos.iX -= iSize.iWidth / 2; |
|
218 iPos.iY -= iSize.iHeight / 2; |
|
219 SetPos(iPos); |
|
220 SetSize(iSize); |
|
221 iWindow->SetOrdinalPosition(0); |
|
222 } |
|
223 |
|
224 void CCompWin::PostConstructL() |
|
225 { |
|
226 iVisible = ETrue; |
|
227 iWindow->Activate(); |
|
228 } |
|
229 |
|
230 void CCompWin::SetPos(const TPoint & aPos) |
|
231 { |
|
232 iPos = aPos; |
|
233 iWindow->SetPosition(iPos); |
|
234 } |
|
235 |
|
236 void CCompWin::SetSize(const TSize & aSize) |
|
237 { |
|
238 iSize = aSize; |
|
239 TInt err = iWindow->SetSizeErr(iSize); |
|
240 if (err != KErrNone) |
|
241 { |
|
242 __DEBUGGER(); |
|
243 } |
|
244 if (iRedrawWindow) |
|
245 { |
|
246 iRedrawWindow->Invalidate(); |
|
247 } |
|
248 else if (iBackedupWindow) |
|
249 { |
|
250 Redraw(aSize); |
|
251 } |
|
252 } |
|
253 |
|
254 |
|
255 void CCompWin::BringToFrontL() |
|
256 { |
|
257 if (iParent) |
|
258 { |
|
259 iParent->RemoveChild(this); |
|
260 iParent->AddChildL(this); |
|
261 } |
|
262 iWindow->SetOrdinalPosition(0); |
|
263 } |
|
264 |
|
265 void CCompWin::SendToBackL() |
|
266 { |
|
267 if (iParent) |
|
268 { |
|
269 iParent->RemoveChild(this); |
|
270 iParent->iChildren.Insert(this, 0); |
|
271 iWindow->SetOrdinalPosition(-1); |
|
272 } |
|
273 } |
|
274 |
|
275 void CCompWin::RemoveChild(CCompWin* aChild) |
|
276 { |
|
277 TInt num = iChildren.Find(aChild); |
|
278 if (num != KErrNotFound) |
|
279 { |
|
280 iChildren.Remove(num); |
|
281 } |
|
282 } |
|
283 |
|
284 void CCompWin::AddChildL(CCompWin* aChild) |
|
285 { |
|
286 CleanupStack::PushL(aChild); |
|
287 User::LeaveIfError(iChildren.Append(aChild)); |
|
288 CleanupStack::Pop(aChild); |
|
289 } |
|
290 |
|
291 CCompWin * CCompWin::RandomWindow() |
|
292 { |
|
293 TInt num = TRnd::rnd(iChildren.Count() + 1); |
|
294 |
|
295 if (num == iChildren.Count()) |
|
296 { |
|
297 return this; |
|
298 } |
|
299 else |
|
300 { |
|
301 return iChildren[num]->RandomWindow(); |
|
302 } |
|
303 } |
|
304 |
|
305 void CCompWin::ToggleVisible() |
|
306 { |
|
307 iVisible = !iVisible; |
|
308 iWindow->SetVisible(iVisible); |
|
309 } |
|
310 |
|
311 void CCompWin::Dump(RFile& aFile, TPoint& aOrigin, TInt aDepth, CCompWin * aMark) |
|
312 { |
|
313 TPoint abs = aOrigin + iPos; |
|
314 static TBuf8<256> buf; |
|
315 buf.SetLength(0); |
|
316 for (TInt d = 0; d < aDepth; ++d) |
|
317 { |
|
318 buf.Append(_L8(" ")); |
|
319 } |
|
320 buf.Append(_L8("rel [")); |
|
321 buf.AppendNum((TInt64)iPos.iX); |
|
322 buf.Append(_L8(",")); |
|
323 buf.AppendNum((TInt64)iPos.iY); |
|
324 buf.Append(_L8("] abs [")); |
|
325 buf.AppendNum((TInt64)abs.iX); |
|
326 buf.Append(_L8(",")); |
|
327 buf.AppendNum((TInt64)abs.iY); |
|
328 buf.Append(_L8("] size [")); |
|
329 buf.AppendNum((TInt64)iSize.iWidth); |
|
330 buf.Append(_L8(",")); |
|
331 buf.AppendNum((TInt64)iSize.iHeight); |
|
332 buf.Append(_L8("] ")); |
|
333 if (iVisible) |
|
334 { |
|
335 buf.Append(_L8("visible ")); |
|
336 } |
|
337 else |
|
338 { |
|
339 buf.Append(_L8("invisible ")); |
|
340 } |
|
341 buf.Append(TypeName()); |
|
342 if (this == aMark) |
|
343 { |
|
344 buf.Append(_L8(" <active>")); |
|
345 } |
|
346 buf.Append(_L8("\r\n")); |
|
347 aFile.Write(buf); |
|
348 |
|
349 DumpDetails(aFile, aDepth); |
|
350 |
|
351 for (TInt num = 0; num < iChildren.Count(); ++num) |
|
352 { |
|
353 iChildren[num]->Dump(aFile, abs, aDepth + 1, aMark); |
|
354 } |
|
355 } |
|
356 |
|
357 void CCompWin::DumpDetails(RFile&, TInt) |
|
358 { |
|
359 } |
|
360 |
|
361 void CCompWin::HandleRedraw(TWsRedrawEvent& aEvent) |
|
362 { |
|
363 Redraw(aEvent.Rect()); |
|
364 } |
|
365 |
|
366 void CCompWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin) |
|
367 { |
|
368 if (aClip.Width() > 0 && aClip.Height() > 0) |
|
369 { |
|
370 TPoint origin = iPos + aOrigin; |
|
371 TRect clip(origin, iSize); |
|
372 clip.Intersection(aClip); |
|
373 |
|
374 for (TInt num = 0; num < iChildren.Count(); ++num) |
|
375 { |
|
376 if (iChildren[num]->iVisible) |
|
377 { |
|
378 iChildren[num]->DrawBitmap(aGc, clip, origin); |
|
379 } |
|
380 } |
|
381 } |
|
382 } |
|
383 |
|
384 /** |
|
385 Fills window's background with it's background color, |
|
386 then iterates visible children |
|
387 */ |
|
388 void CCompWin::ClearBitmapBackground(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin) |
|
389 { |
|
390 if (aClip.Width() > 0 && aClip.Height() > 0) |
|
391 { |
|
392 TPoint origin = iPos + aOrigin; |
|
393 TRect clip(origin, iSize); |
|
394 clip.Intersection(aClip); |
|
395 |
|
396 aGc->Reset(); |
|
397 aGc->SetOrigin(TPoint(0,0)); |
|
398 aGc->SetPenColor(BackgroundColor()); |
|
399 aGc->SetBrushColor(BackgroundColor()); |
|
400 aGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
401 aGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
402 aGc->DrawRect(clip); |
|
403 |
|
404 for (TInt num = 0; num < iChildren.Count(); ++num) |
|
405 { |
|
406 if (iChildren[num]->iVisible) |
|
407 { |
|
408 iChildren[num]->ClearBitmapBackground(aGc, clip, origin); |
|
409 } |
|
410 } |
|
411 } |
|
412 } |
|
413 |
|
414 TBool CCompWin::QueryReadyForVerification() |
|
415 { |
|
416 TBool res = ETrue; |
|
417 |
|
418 TInt idx = 0; |
|
419 |
|
420 while ( idx < iChildren.Count() && res ) |
|
421 { |
|
422 res = iChildren[ idx ]->QueryReadyForVerification(); |
|
423 idx++; |
|
424 } |
|
425 |
|
426 return res; |
|
427 } |
|
428 |
|
429 /** |
|
430 Subtracts window region from the supplied region |
|
431 then calls all children to subtract themsleves |
|
432 @param aRegion region from which current window are should be subtructed |
|
433 @param aClip clipping area provided by the parent window |
|
434 @param aOrigin absolute origin of parent |
|
435 */ |
|
436 void CCompWin::SubSelfFromRegion(TRegion& aRegion, const TRect& aClip, const TPoint& aOrigin) |
|
437 { |
|
438 if (!iVisible) |
|
439 { |
|
440 return; |
|
441 } |
|
442 TPoint origin = iPos + aOrigin; |
|
443 TRect clip(origin, iSize); |
|
444 clip.Intersection(aClip); |
|
445 aRegion.SubRect(clip); |
|
446 for (TInt num = 0; num < iChildren.Count(); ++num) |
|
447 { |
|
448 if (iChildren[num]->iVisible) |
|
449 { |
|
450 iChildren[num]->SubSelfFromRegion(aRegion, clip, origin); |
|
451 } |
|
452 } |
|
453 } |
|
454 |
|
455 void CCompWin::SetVerifyTick(TUint32 aTick) |
|
456 { |
|
457 iVerifyTick = aTick; |
|
458 for (TInt num = 0; num < iChildren.Count(); ++num) |
|
459 { |
|
460 if (iChildren[num]->iVisible) |
|
461 { |
|
462 iChildren[num]->SetVerifyTick(aTick); |
|
463 } |
|
464 } |
|
465 } |
|
466 |