|
1 // Copyright (c) 1995-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 // Test code to tun ANIMDLL.DLL |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <w32std.h> |
|
20 #include <e32svr.h> |
|
21 #include "../tlib/testbase.h" |
|
22 #include "TANIM.H" |
|
23 #include "ANIMDLL.H" |
|
24 |
|
25 #define NONEXISTENT_DLL_NAME _L("Z:\\NONEXISTENT.DLL") |
|
26 #define ANIM_BITMAP _L("Z:\\WSTEST\\TANIM.MBM") |
|
27 #define ANIM_DLL_NAME _L("ANIDLL.DLL") |
|
28 |
|
29 enum TAnimPanic |
|
30 { |
|
31 EAnimPanicBadLoadFailed, |
|
32 }; |
|
33 |
|
34 class CTAnimClient; |
|
35 |
|
36 class TestAnim : public RAnim |
|
37 { |
|
38 public: |
|
39 TestAnim(RAnimDll &aDll); |
|
40 TInt Construct(RWindowBase &aWin,const TPoint &aPos,CFbsBitmap *aBit1,CFbsBitmap *aBit2,CFbsBitmap *aMask,TInt aInterval, CFbsFont *aFont); |
|
41 void Set(const TPoint &aPos, TInt aInterval); |
|
42 void TextPos(const TPoint &aPos); |
|
43 void SetPolyRectL(const TRect &aRect); |
|
44 void ToggleMask(); |
|
45 }; |
|
46 |
|
47 class CTAnimWindow2 : public CTBlankWindow |
|
48 { |
|
49 public: |
|
50 CTAnimWindow2(RAnimDll &aAnimDll); |
|
51 ~CTAnimWindow2(); |
|
52 void ConstructL(CTWinBase &parent, const TPoint &aPos, const TSize &aSize); |
|
53 void ConstructExtLD(CTWinBase &aParent, const TPoint &aPos, const TSize &aSize); |
|
54 private: |
|
55 TestAnim iAnim; |
|
56 CFbsBitmap iAnimBitmap1; |
|
57 CFbsBitmap iAnimBitmap2; |
|
58 }; |
|
59 |
|
60 class CTAnimWindow1 : public CTTitledWindow |
|
61 { |
|
62 public: |
|
63 CTAnimWindow1(RAnimDll &aAnimDll); |
|
64 ~CTAnimWindow1(); |
|
65 void ConstructL(CTWinBase &parent); |
|
66 void Draw(); |
|
67 void AdjustAnimRect(TInt xMove,TInt yMove,TInt modifiers); |
|
68 void AdjustPolyRectL(TInt xMove,TInt yMove,TInt modifiers); |
|
69 void ToggleMask(); |
|
70 TInt SubType(); |
|
71 private: |
|
72 TestAnim iAnim; |
|
73 TPoint iAnimPos; |
|
74 TRect iAnimPolyRect; |
|
75 CFbsBitmap iAnimBitmap1; |
|
76 CFbsBitmap iAnimBitmap2; |
|
77 CFbsBitmap iMask; |
|
78 }; |
|
79 |
|
80 class CTAnimWindowGroup : public CTWindowGroup |
|
81 { |
|
82 public: |
|
83 CTAnimWindowGroup(CTClient *aClient); |
|
84 void CursorKeyL(TInt xMove,TInt yMove,TInt modifiers); |
|
85 void KeyL(const TKeyEvent &aKey, const TTime &aTime); |
|
86 TInt iCursorMode; |
|
87 }; |
|
88 |
|
89 class CTAnimClient : public CTClient |
|
90 { |
|
91 public: |
|
92 CTAnimClient(); |
|
93 ~CTAnimClient(); |
|
94 void ConstructL(); |
|
95 void KeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
96 void ExitL(); |
|
97 void ErrorTests(); |
|
98 CTBaseWin *CreateTestWindowL(TPoint pos,TSize size,CTWinBase *parent, TInt aType); |
|
99 private: |
|
100 TInt iNum; |
|
101 RAnimDll iAnimDll; |
|
102 }; |
|
103 |
|
104 const TInt Xmove=8; |
|
105 const TInt Ymove=6; |
|
106 |
|
107 void AnimPanic(TInt aPanic) |
|
108 { |
|
109 User::Panic(_L("ANIM"),aPanic); |
|
110 } |
|
111 |
|
112 // |
|
113 // Anim class |
|
114 // |
|
115 |
|
116 TestAnim::TestAnim(RAnimDll &aDll) : RAnim(aDll) |
|
117 { |
|
118 } |
|
119 |
|
120 TInt TestAnim::Construct(RWindowBase &aWin, const TPoint &aPos, CFbsBitmap *aBit1,CFbsBitmap *aBit2,CFbsBitmap *aMask, TInt aInterval, CFbsFont *aFont) |
|
121 { |
|
122 TPckgBuf<CTAParams> params; |
|
123 params().pos=aPos; |
|
124 params().interval=aInterval; |
|
125 params().bit1=aBit1->Handle(); |
|
126 params().bit2=aBit2->Handle(); |
|
127 params().mask=aMask->Handle(); |
|
128 params().font=aFont->Handle(); |
|
129 return(RAnim::Construct(aWin,0,params)); |
|
130 } |
|
131 |
|
132 void TestAnim::Set(const TPoint &aPos, TInt aInterval) |
|
133 { |
|
134 TPckgBuf<CTAParams> params; |
|
135 params().pos=aPos; |
|
136 params().interval=aInterval; |
|
137 Command(EADllOpcodeMove,params); |
|
138 } |
|
139 |
|
140 void TestAnim::TextPos(const TPoint &aPos) |
|
141 { |
|
142 TPckgBuf<TPoint> params; |
|
143 params()=aPos; |
|
144 Command(EADllTextPos,params); |
|
145 } |
|
146 |
|
147 void TestAnim::SetPolyRectL(const TRect &aRect) |
|
148 { |
|
149 TPckgC<TRect> params(aRect); |
|
150 User::LeaveIfError(CommandReply(EADllOpcodePolyLineRect,params)); |
|
151 } |
|
152 |
|
153 void TestAnim::ToggleMask() |
|
154 { |
|
155 Command(EADllToggleBitmapMask); |
|
156 } |
|
157 |
|
158 // |
|
159 // Individual window sub-classes |
|
160 // |
|
161 |
|
162 CTAnimWindow1::CTAnimWindow1(RAnimDll &aAnimDll) : CTTitledWindow(), |
|
163 iAnim(aAnimDll) |
|
164 { |
|
165 } |
|
166 |
|
167 CTAnimWindow1::~CTAnimWindow1() |
|
168 { |
|
169 iAnim.Close(); |
|
170 } |
|
171 |
|
172 void CTAnimWindow1::ConstructL(CTWinBase &parent) |
|
173 { |
|
174 CTTitledWindow::ConstructL(parent); |
|
175 User::LeaveIfError(iAnimBitmap1.Load(ANIM_BITMAP,EMbmTanimAnim1)); |
|
176 User::LeaveIfError(iAnimBitmap2.Load(ANIM_BITMAP,EMbmTanimAnim2)); |
|
177 User::LeaveIfError(iMask.Load(ANIM_BITMAP,EMbmTanimMask)); |
|
178 iAnimPos=TPoint(10,10); |
|
179 User::LeaveIfError(iAnim.Construct(iWin, iAnimPos,&iAnimBitmap1,&iAnimBitmap2,&iMask,1,iFont)); |
|
180 iAnimPolyRect=TRect(TPoint(10,40),TSize(50,50)); |
|
181 iAnim.SetPolyRectL(iAnimPolyRect); |
|
182 iAnim.TextPos(TPoint(20,50)); |
|
183 } |
|
184 |
|
185 void CTAnimWindow1::Draw() |
|
186 { |
|
187 TInt i; |
|
188 |
|
189 CTTitledWindow::Draw(); |
|
190 iGc->SetPenColor(TRgb::Gray16(8)); |
|
191 TInt hgt=iSize.iHeight-iTitleHeight; |
|
192 for(i=0;i<iSize.iWidth;i+=30) |
|
193 { |
|
194 iGc->DrawLine(TPoint(i,iTitleHeight),TPoint(iSize.iWidth,iTitleHeight+(hgt*i)/iSize.iWidth)); |
|
195 iGc->DrawLine(TPoint(iSize.iWidth-i,iTitleHeight+hgt),TPoint(iSize.iWidth,iTitleHeight+(hgt*i)/iSize.iWidth)); |
|
196 iGc->DrawLine(TPoint(iSize.iWidth-i,iTitleHeight+hgt),TPoint(0,iTitleHeight+hgt-(hgt*i)/iSize.iWidth)); |
|
197 iGc->DrawLine(TPoint(i,iTitleHeight),TPoint(0,iTitleHeight+hgt-(hgt*i)/iSize.iWidth)); |
|
198 } |
|
199 } |
|
200 |
|
201 void CTAnimWindow1::AdjustAnimRect(TInt xMove,TInt yMove,TInt modifiers) |
|
202 { |
|
203 if (modifiers&EModifierCtrl) // 4 times the movement |
|
204 { |
|
205 xMove<<=2; |
|
206 yMove<<=2; |
|
207 } |
|
208 iAnimPos+=TPoint(xMove,yMove); |
|
209 iAnim.Set(iAnimPos,5); |
|
210 } |
|
211 |
|
212 void CTAnimWindow1::AdjustPolyRectL(TInt xMove,TInt yMove,TInt modifiers) |
|
213 { |
|
214 if (modifiers&EModifierCtrl) // 4 times the movement |
|
215 { |
|
216 xMove<<=2; |
|
217 yMove<<=2; |
|
218 } |
|
219 if (modifiers&EModifierShift) // 4 times the movement |
|
220 iAnimPolyRect.Grow(xMove,yMove); |
|
221 else |
|
222 iAnimPolyRect.Move(TPoint(xMove,yMove)); |
|
223 iAnim.SetPolyRectL(iAnimPolyRect); |
|
224 } |
|
225 |
|
226 void CTAnimWindow1::ToggleMask() |
|
227 { |
|
228 iAnim.ToggleMask(); |
|
229 } |
|
230 |
|
231 TInt CTAnimWindow1::SubType() |
|
232 { |
|
233 return(69); |
|
234 } |
|
235 |
|
236 // CTAnimWindow2 // |
|
237 |
|
238 CTAnimWindow2::CTAnimWindow2(RAnimDll &aAnimDll) : CTBlankWindow(), |
|
239 iAnim(aAnimDll) |
|
240 { |
|
241 } |
|
242 |
|
243 CTAnimWindow2::~CTAnimWindow2() |
|
244 { |
|
245 iAnim.Close(); |
|
246 } |
|
247 |
|
248 void CTAnimWindow2::ConstructL(CTWinBase &parent, const TPoint &aPos, const TSize &aSize) |
|
249 { |
|
250 CTBlankWindow::ConstructL(parent); |
|
251 iWin.SetColor(TRgb(128,128,128)); |
|
252 iWin.SetVisible(EFalse); |
|
253 SetExt(aPos,aSize); |
|
254 iWin.Activate(); |
|
255 User::LeaveIfError(iAnimBitmap1.Load(ANIM_BITMAP,EMbmTanimAnim1)); |
|
256 User::LeaveIfError(iAnimBitmap2.Load(ANIM_BITMAP,EMbmTanimAnim2)); |
|
257 User::LeaveIfError(iAnim.Construct(iWin, TPoint(10,10), &iAnimBitmap1, &iAnimBitmap2, &iAnimBitmap1, 1, iFont)); |
|
258 iWin.SetVisible(ETrue); |
|
259 } |
|
260 |
|
261 void CTAnimWindow2::ConstructExtLD(CTWinBase &aParent, const TPoint &aPos, const TSize &aSize) |
|
262 // |
|
263 // Call ConstructL, SetExt and either of these fail destroy this and leave |
|
264 // |
|
265 { |
|
266 TRAPD(err,ConstructL(aParent, aPos, aSize)); |
|
267 if (err!=KErrNone) |
|
268 { |
|
269 delete this; |
|
270 User::Leave(err); |
|
271 } |
|
272 } |
|
273 |
|
274 // |
|
275 // End of CTAnimWindow class // |
|
276 // |
|
277 |
|
278 CTAnimWindowGroup::CTAnimWindowGroup(CTClient *aClient) : CTWindowGroup(aClient) |
|
279 { |
|
280 } |
|
281 |
|
282 void CTAnimWindowGroup::CursorKeyL(TInt xMove,TInt yMove,TInt modifiers) |
|
283 { |
|
284 if (iCursorMode==0) |
|
285 iCurWin->AdjustSizeL(xMove,yMove,modifiers); |
|
286 else if (iCurWin->SubType()==69) |
|
287 { |
|
288 if (iCursorMode==1) |
|
289 ((CTAnimWindow1 *)iCurWin)->AdjustAnimRect(xMove,yMove,modifiers); |
|
290 else |
|
291 ((CTAnimWindow1 *)iCurWin)->AdjustPolyRectL(xMove,yMove,modifiers); |
|
292 } |
|
293 } |
|
294 |
|
295 void CTAnimWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime) |
|
296 { |
|
297 if (aKey.iModifiers&EModifierCtrl) |
|
298 { |
|
299 TInt type=0; |
|
300 switch(aKey.iCode) |
|
301 { |
|
302 case 1: |
|
303 type=1; |
|
304 break; |
|
305 case 2: |
|
306 type=2; |
|
307 break; |
|
308 } |
|
309 if (type!=0) |
|
310 { |
|
311 TPoint pos; |
|
312 TSize size; |
|
313 pos.iX=iCurWin->Size().iWidth>>2; |
|
314 pos.iY=iCurWin->Size().iHeight>>2; |
|
315 size.iWidth=iCurWin->Size().iWidth>>1; |
|
316 size.iHeight=iCurWin->Size().iHeight>>1; |
|
317 SetCurrentWindow(((CTAnimClient *)iClient)->CreateTestWindowL(pos,size,iCurWin,type)); |
|
318 return; |
|
319 } |
|
320 } |
|
321 if (aKey.iModifiers&EModifierFunc) |
|
322 { |
|
323 switch(aKey.iCode) |
|
324 { |
|
325 case 'x': |
|
326 ((CTAnimClient *)iClient)->ExitL(); |
|
327 break; |
|
328 } |
|
329 } |
|
330 else switch(aKey.iCode) |
|
331 { |
|
332 case ' ': |
|
333 iCursorMode=(iCursorMode+1)%3; |
|
334 break; |
|
335 case 8: |
|
336 CTWin::Delete(iCurWin); |
|
337 break; |
|
338 case 9: |
|
339 if (aKey.iModifiers&EModifierShift) |
|
340 SetCurrentWindow(iCurWin->Prev()); |
|
341 else |
|
342 SetCurrentWindow(iCurWin->Next()); |
|
343 break; |
|
344 case 13: |
|
345 if (iCurWin->SubType()==69) |
|
346 ((CTAnimWindow1 *)iCurWin)->ToggleMask(); |
|
347 break; |
|
348 case EKeyLeftArrow: |
|
349 CursorKeyL(-Xmove,0,aKey.iModifiers); |
|
350 break; |
|
351 case EKeyRightArrow: |
|
352 CursorKeyL(Xmove,0,aKey.iModifiers); |
|
353 break; |
|
354 case EKeyUpArrow: |
|
355 CursorKeyL(0,-Ymove,aKey.iModifiers); |
|
356 break; |
|
357 case EKeyDownArrow: |
|
358 CursorKeyL(0,Ymove,aKey.iModifiers); |
|
359 break; |
|
360 default: |
|
361 iCurWin->WinKeyL(aKey,aTime); |
|
362 break; |
|
363 } |
|
364 } |
|
365 |
|
366 // |
|
367 |
|
368 CTAnimClient::CTAnimClient() |
|
369 { |
|
370 } |
|
371 |
|
372 CTBaseWin *CTAnimClient::CreateTestWindowL(TPoint pos,TSize size,CTWinBase *parent, TInt type) |
|
373 { |
|
374 CTBaseWin *win; |
|
375 if (type==1) |
|
376 { |
|
377 win=new(ELeave) CTAnimWindow1(iAnimDll); |
|
378 win->ConstructExtLD(*parent,pos,size); |
|
379 win->Activate(); |
|
380 } |
|
381 else |
|
382 { |
|
383 win=new(ELeave) CTAnimWindow2(iAnimDll); |
|
384 win->ConstructExtLD(*parent,pos,size); |
|
385 } |
|
386 win->AssignGC(*iGc); |
|
387 return(win); |
|
388 } |
|
389 |
|
390 CTAnimClient::~CTAnimClient() |
|
391 { |
|
392 DestroyWindows(); |
|
393 iAnimDll.Close(); |
|
394 } |
|
395 |
|
396 void CTAnimClient::ErrorTests() |
|
397 { |
|
398 RAnimDll animDll=RAnimDll(iWs); |
|
399 if (animDll.Load(NONEXISTENT_DLL_NAME)!=KErrNotFound) |
|
400 AnimPanic(EAnimPanicBadLoadFailed); |
|
401 animDll.Close(); // Close should be harmless, but unnecassary |
|
402 RAnimDll animDll2=RAnimDll(iWs); |
|
403 if (animDll2.Load(NONEXISTENT_DLL_NAME)!=KErrNotFound) |
|
404 AnimPanic(EAnimPanicBadLoadFailed); |
|
405 } |
|
406 |
|
407 void CTAnimClient::ConstructL() |
|
408 { |
|
409 CTClient::ConstructL(); |
|
410 |
|
411 iGroup=new(ELeave) CTAnimWindowGroup(this); |
|
412 iGroup->ConstructL(); |
|
413 |
|
414 ErrorTests(); |
|
415 |
|
416 iAnimDll=RAnimDll(iWs); |
|
417 User::LeaveIfError(iAnimDll.Load(ANIM_DLL_NAME)); |
|
418 |
|
419 CreateTestWindowL(TPoint(30,20),TSize(220,140),iGroup, 1); |
|
420 CreateTestWindowL(TPoint(260,60),TSize(60,40),iGroup, 2); |
|
421 iGroup->SetCurrentWindow(iGroup->Child()); |
|
422 } |
|
423 |
|
424 void CTAnimClient::ExitL() |
|
425 { |
|
426 CActiveScheduler::Stop(); |
|
427 User::Leave(0); // Signals RunL not to do another Request() |
|
428 } |
|
429 |
|
430 GLDEF_C CTClient *CreateClientL() |
|
431 { |
|
432 return(new(ELeave) CTAnimClient()); |
|
433 } |
|
434 |
|
435 GLDEF_C TInt E32Main() |
|
436 { |
|
437 return(TestLibStartUp(CreateClientL)); |
|
438 } |