Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Test code to tun ANIMDLL.DLL
21 #include "../tlib/testbase.h"
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")
31 EAnimPanicBadLoadFailed,
36 class TestAnim : public RAnim
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);
47 class CTAnimWindow2 : public CTBlankWindow
50 CTAnimWindow2(RAnimDll &aAnimDll);
52 void ConstructL(CTWinBase &parent, const TPoint &aPos, const TSize &aSize);
53 void ConstructExtLD(CTWinBase &aParent, const TPoint &aPos, const TSize &aSize);
56 CFbsBitmap iAnimBitmap1;
57 CFbsBitmap iAnimBitmap2;
60 class CTAnimWindow1 : public CTTitledWindow
63 CTAnimWindow1(RAnimDll &aAnimDll);
65 void ConstructL(CTWinBase &parent);
67 void AdjustAnimRect(TInt xMove,TInt yMove,TInt modifiers);
68 void AdjustPolyRectL(TInt xMove,TInt yMove,TInt modifiers);
75 CFbsBitmap iAnimBitmap1;
76 CFbsBitmap iAnimBitmap2;
80 class CTAnimWindowGroup : public CTWindowGroup
83 CTAnimWindowGroup(CTClient *aClient);
84 void CursorKeyL(TInt xMove,TInt yMove,TInt modifiers);
85 void KeyL(const TKeyEvent &aKey, const TTime &aTime);
89 class CTAnimClient : public CTClient
95 void KeyL(const TKeyEvent &aKey,const TTime &aTime);
98 CTBaseWin *CreateTestWindowL(TPoint pos,TSize size,CTWinBase *parent, TInt aType);
107 void AnimPanic(TInt aPanic)
109 User::Panic(_L("ANIM"),aPanic);
116 TestAnim::TestAnim(RAnimDll &aDll) : RAnim(aDll)
120 TInt TestAnim::Construct(RWindowBase &aWin, const TPoint &aPos, CFbsBitmap *aBit1,CFbsBitmap *aBit2,CFbsBitmap *aMask, TInt aInterval, CFbsFont *aFont)
122 TPckgBuf<CTAParams> params;
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));
132 void TestAnim::Set(const TPoint &aPos, TInt aInterval)
134 TPckgBuf<CTAParams> params;
136 params().interval=aInterval;
137 Command(EADllOpcodeMove,params);
140 void TestAnim::TextPos(const TPoint &aPos)
142 TPckgBuf<TPoint> params;
144 Command(EADllTextPos,params);
147 void TestAnim::SetPolyRectL(const TRect &aRect)
149 TPckgC<TRect> params(aRect);
150 User::LeaveIfError(CommandReply(EADllOpcodePolyLineRect,params));
153 void TestAnim::ToggleMask()
155 Command(EADllToggleBitmapMask);
159 // Individual window sub-classes
162 CTAnimWindow1::CTAnimWindow1(RAnimDll &aAnimDll) : CTTitledWindow(),
167 CTAnimWindow1::~CTAnimWindow1()
172 void CTAnimWindow1::ConstructL(CTWinBase &parent)
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));
185 void CTAnimWindow1::Draw()
189 CTTitledWindow::Draw();
190 iGc->SetPenColor(TRgb::Gray16(8));
191 TInt hgt=iSize.iHeight-iTitleHeight;
192 for(i=0;i<iSize.iWidth;i+=30)
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));
201 void CTAnimWindow1::AdjustAnimRect(TInt xMove,TInt yMove,TInt modifiers)
203 if (modifiers&EModifierCtrl) // 4 times the movement
208 iAnimPos+=TPoint(xMove,yMove);
209 iAnim.Set(iAnimPos,5);
212 void CTAnimWindow1::AdjustPolyRectL(TInt xMove,TInt yMove,TInt modifiers)
214 if (modifiers&EModifierCtrl) // 4 times the movement
219 if (modifiers&EModifierShift) // 4 times the movement
220 iAnimPolyRect.Grow(xMove,yMove);
222 iAnimPolyRect.Move(TPoint(xMove,yMove));
223 iAnim.SetPolyRectL(iAnimPolyRect);
226 void CTAnimWindow1::ToggleMask()
231 TInt CTAnimWindow1::SubType()
238 CTAnimWindow2::CTAnimWindow2(RAnimDll &aAnimDll) : CTBlankWindow(),
243 CTAnimWindow2::~CTAnimWindow2()
248 void CTAnimWindow2::ConstructL(CTWinBase &parent, const TPoint &aPos, const TSize &aSize)
250 CTBlankWindow::ConstructL(parent);
251 iWin.SetColor(TRgb(128,128,128));
252 iWin.SetVisible(EFalse);
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);
261 void CTAnimWindow2::ConstructExtLD(CTWinBase &aParent, const TPoint &aPos, const TSize &aSize)
263 // Call ConstructL, SetExt and either of these fail destroy this and leave
266 TRAPD(err,ConstructL(aParent, aPos, aSize));
275 // End of CTAnimWindow class //
278 CTAnimWindowGroup::CTAnimWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
282 void CTAnimWindowGroup::CursorKeyL(TInt xMove,TInt yMove,TInt modifiers)
285 iCurWin->AdjustSizeL(xMove,yMove,modifiers);
286 else if (iCurWin->SubType()==69)
289 ((CTAnimWindow1 *)iCurWin)->AdjustAnimRect(xMove,yMove,modifiers);
291 ((CTAnimWindow1 *)iCurWin)->AdjustPolyRectL(xMove,yMove,modifiers);
295 void CTAnimWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime)
297 if (aKey.iModifiers&EModifierCtrl)
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));
321 if (aKey.iModifiers&EModifierFunc)
326 ((CTAnimClient *)iClient)->ExitL();
330 else switch(aKey.iCode)
333 iCursorMode=(iCursorMode+1)%3;
336 CTWin::Delete(iCurWin);
339 if (aKey.iModifiers&EModifierShift)
340 SetCurrentWindow(iCurWin->Prev());
342 SetCurrentWindow(iCurWin->Next());
345 if (iCurWin->SubType()==69)
346 ((CTAnimWindow1 *)iCurWin)->ToggleMask();
349 CursorKeyL(-Xmove,0,aKey.iModifiers);
352 CursorKeyL(Xmove,0,aKey.iModifiers);
355 CursorKeyL(0,-Ymove,aKey.iModifiers);
358 CursorKeyL(0,Ymove,aKey.iModifiers);
361 iCurWin->WinKeyL(aKey,aTime);
368 CTAnimClient::CTAnimClient()
372 CTBaseWin *CTAnimClient::CreateTestWindowL(TPoint pos,TSize size,CTWinBase *parent, TInt type)
377 win=new(ELeave) CTAnimWindow1(iAnimDll);
378 win->ConstructExtLD(*parent,pos,size);
383 win=new(ELeave) CTAnimWindow2(iAnimDll);
384 win->ConstructExtLD(*parent,pos,size);
390 CTAnimClient::~CTAnimClient()
396 void CTAnimClient::ErrorTests()
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);
407 void CTAnimClient::ConstructL()
409 CTClient::ConstructL();
411 iGroup=new(ELeave) CTAnimWindowGroup(this);
412 iGroup->ConstructL();
416 iAnimDll=RAnimDll(iWs);
417 User::LeaveIfError(iAnimDll.Load(ANIM_DLL_NAME));
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());
424 void CTAnimClient::ExitL()
426 CActiveScheduler::Stop();
427 User::Leave(0); // Signals RunL not to do another Request()
430 GLDEF_C CTClient *CreateClientL()
432 return(new(ELeave) CTAnimClient());
435 GLDEF_C TInt E32Main()
437 return(TestLibStartUp(CreateClientL));