sl@0: // Copyright (c) 1995-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: // Test code to tun ANIMDLL.DLL sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "../tlib/testbase.h" sl@0: #include "TANIM.H" sl@0: #include "ANIMDLL.H" sl@0: sl@0: #define NONEXISTENT_DLL_NAME _L("Z:\\NONEXISTENT.DLL") sl@0: #define ANIM_BITMAP _L("Z:\\WSTEST\\TANIM.MBM") sl@0: #define ANIM_DLL_NAME _L("ANIDLL.DLL") sl@0: sl@0: enum TAnimPanic sl@0: { sl@0: EAnimPanicBadLoadFailed, sl@0: }; sl@0: sl@0: class CTAnimClient; sl@0: sl@0: class TestAnim : public RAnim sl@0: { sl@0: public: sl@0: TestAnim(RAnimDll &aDll); sl@0: TInt Construct(RWindowBase &aWin,const TPoint &aPos,CFbsBitmap *aBit1,CFbsBitmap *aBit2,CFbsBitmap *aMask,TInt aInterval, CFbsFont *aFont); sl@0: void Set(const TPoint &aPos, TInt aInterval); sl@0: void TextPos(const TPoint &aPos); sl@0: void SetPolyRectL(const TRect &aRect); sl@0: void ToggleMask(); sl@0: }; sl@0: sl@0: class CTAnimWindow2 : public CTBlankWindow sl@0: { sl@0: public: sl@0: CTAnimWindow2(RAnimDll &aAnimDll); sl@0: ~CTAnimWindow2(); sl@0: void ConstructL(CTWinBase &parent, const TPoint &aPos, const TSize &aSize); sl@0: void ConstructExtLD(CTWinBase &aParent, const TPoint &aPos, const TSize &aSize); sl@0: private: sl@0: TestAnim iAnim; sl@0: CFbsBitmap iAnimBitmap1; sl@0: CFbsBitmap iAnimBitmap2; sl@0: }; sl@0: sl@0: class CTAnimWindow1 : public CTTitledWindow sl@0: { sl@0: public: sl@0: CTAnimWindow1(RAnimDll &aAnimDll); sl@0: ~CTAnimWindow1(); sl@0: void ConstructL(CTWinBase &parent); sl@0: void Draw(); sl@0: void AdjustAnimRect(TInt xMove,TInt yMove,TInt modifiers); sl@0: void AdjustPolyRectL(TInt xMove,TInt yMove,TInt modifiers); sl@0: void ToggleMask(); sl@0: TInt SubType(); sl@0: private: sl@0: TestAnim iAnim; sl@0: TPoint iAnimPos; sl@0: TRect iAnimPolyRect; sl@0: CFbsBitmap iAnimBitmap1; sl@0: CFbsBitmap iAnimBitmap2; sl@0: CFbsBitmap iMask; sl@0: }; sl@0: sl@0: class CTAnimWindowGroup : public CTWindowGroup sl@0: { sl@0: public: sl@0: CTAnimWindowGroup(CTClient *aClient); sl@0: void CursorKeyL(TInt xMove,TInt yMove,TInt modifiers); sl@0: void KeyL(const TKeyEvent &aKey, const TTime &aTime); sl@0: TInt iCursorMode; sl@0: }; sl@0: sl@0: class CTAnimClient : public CTClient sl@0: { sl@0: public: sl@0: CTAnimClient(); sl@0: ~CTAnimClient(); sl@0: void ConstructL(); sl@0: void KeyL(const TKeyEvent &aKey,const TTime &aTime); sl@0: void ExitL(); sl@0: void ErrorTests(); sl@0: CTBaseWin *CreateTestWindowL(TPoint pos,TSize size,CTWinBase *parent, TInt aType); sl@0: private: sl@0: TInt iNum; sl@0: RAnimDll iAnimDll; sl@0: }; sl@0: sl@0: const TInt Xmove=8; sl@0: const TInt Ymove=6; sl@0: sl@0: void AnimPanic(TInt aPanic) sl@0: { sl@0: User::Panic(_L("ANIM"),aPanic); sl@0: } sl@0: sl@0: // sl@0: // Anim class sl@0: // sl@0: sl@0: TestAnim::TestAnim(RAnimDll &aDll) : RAnim(aDll) sl@0: { sl@0: } sl@0: sl@0: TInt TestAnim::Construct(RWindowBase &aWin, const TPoint &aPos, CFbsBitmap *aBit1,CFbsBitmap *aBit2,CFbsBitmap *aMask, TInt aInterval, CFbsFont *aFont) sl@0: { sl@0: TPckgBuf params; sl@0: params().pos=aPos; sl@0: params().interval=aInterval; sl@0: params().bit1=aBit1->Handle(); sl@0: params().bit2=aBit2->Handle(); sl@0: params().mask=aMask->Handle(); sl@0: params().font=aFont->Handle(); sl@0: return(RAnim::Construct(aWin,0,params)); sl@0: } sl@0: sl@0: void TestAnim::Set(const TPoint &aPos, TInt aInterval) sl@0: { sl@0: TPckgBuf params; sl@0: params().pos=aPos; sl@0: params().interval=aInterval; sl@0: Command(EADllOpcodeMove,params); sl@0: } sl@0: sl@0: void TestAnim::TextPos(const TPoint &aPos) sl@0: { sl@0: TPckgBuf params; sl@0: params()=aPos; sl@0: Command(EADllTextPos,params); sl@0: } sl@0: sl@0: void TestAnim::SetPolyRectL(const TRect &aRect) sl@0: { sl@0: TPckgC params(aRect); sl@0: User::LeaveIfError(CommandReply(EADllOpcodePolyLineRect,params)); sl@0: } sl@0: sl@0: void TestAnim::ToggleMask() sl@0: { sl@0: Command(EADllToggleBitmapMask); sl@0: } sl@0: sl@0: // sl@0: // Individual window sub-classes sl@0: // sl@0: sl@0: CTAnimWindow1::CTAnimWindow1(RAnimDll &aAnimDll) : CTTitledWindow(), sl@0: iAnim(aAnimDll) sl@0: { sl@0: } sl@0: sl@0: CTAnimWindow1::~CTAnimWindow1() sl@0: { sl@0: iAnim.Close(); sl@0: } sl@0: sl@0: void CTAnimWindow1::ConstructL(CTWinBase &parent) sl@0: { sl@0: CTTitledWindow::ConstructL(parent); sl@0: User::LeaveIfError(iAnimBitmap1.Load(ANIM_BITMAP,EMbmTanimAnim1)); sl@0: User::LeaveIfError(iAnimBitmap2.Load(ANIM_BITMAP,EMbmTanimAnim2)); sl@0: User::LeaveIfError(iMask.Load(ANIM_BITMAP,EMbmTanimMask)); sl@0: iAnimPos=TPoint(10,10); sl@0: User::LeaveIfError(iAnim.Construct(iWin, iAnimPos,&iAnimBitmap1,&iAnimBitmap2,&iMask,1,iFont)); sl@0: iAnimPolyRect=TRect(TPoint(10,40),TSize(50,50)); sl@0: iAnim.SetPolyRectL(iAnimPolyRect); sl@0: iAnim.TextPos(TPoint(20,50)); sl@0: } sl@0: sl@0: void CTAnimWindow1::Draw() sl@0: { sl@0: TInt i; sl@0: sl@0: CTTitledWindow::Draw(); sl@0: iGc->SetPenColor(TRgb::Gray16(8)); sl@0: TInt hgt=iSize.iHeight-iTitleHeight; sl@0: for(i=0;iDrawLine(TPoint(i,iTitleHeight),TPoint(iSize.iWidth,iTitleHeight+(hgt*i)/iSize.iWidth)); sl@0: iGc->DrawLine(TPoint(iSize.iWidth-i,iTitleHeight+hgt),TPoint(iSize.iWidth,iTitleHeight+(hgt*i)/iSize.iWidth)); sl@0: iGc->DrawLine(TPoint(iSize.iWidth-i,iTitleHeight+hgt),TPoint(0,iTitleHeight+hgt-(hgt*i)/iSize.iWidth)); sl@0: iGc->DrawLine(TPoint(i,iTitleHeight),TPoint(0,iTitleHeight+hgt-(hgt*i)/iSize.iWidth)); sl@0: } sl@0: } sl@0: sl@0: void CTAnimWindow1::AdjustAnimRect(TInt xMove,TInt yMove,TInt modifiers) sl@0: { sl@0: if (modifiers&EModifierCtrl) // 4 times the movement sl@0: { sl@0: xMove<<=2; sl@0: yMove<<=2; sl@0: } sl@0: iAnimPos+=TPoint(xMove,yMove); sl@0: iAnim.Set(iAnimPos,5); sl@0: } sl@0: sl@0: void CTAnimWindow1::AdjustPolyRectL(TInt xMove,TInt yMove,TInt modifiers) sl@0: { sl@0: if (modifiers&EModifierCtrl) // 4 times the movement sl@0: { sl@0: xMove<<=2; sl@0: yMove<<=2; sl@0: } sl@0: if (modifiers&EModifierShift) // 4 times the movement sl@0: iAnimPolyRect.Grow(xMove,yMove); sl@0: else sl@0: iAnimPolyRect.Move(TPoint(xMove,yMove)); sl@0: iAnim.SetPolyRectL(iAnimPolyRect); sl@0: } sl@0: sl@0: void CTAnimWindow1::ToggleMask() sl@0: { sl@0: iAnim.ToggleMask(); sl@0: } sl@0: sl@0: TInt CTAnimWindow1::SubType() sl@0: { sl@0: return(69); sl@0: } sl@0: sl@0: // CTAnimWindow2 // sl@0: sl@0: CTAnimWindow2::CTAnimWindow2(RAnimDll &aAnimDll) : CTBlankWindow(), sl@0: iAnim(aAnimDll) sl@0: { sl@0: } sl@0: sl@0: CTAnimWindow2::~CTAnimWindow2() sl@0: { sl@0: iAnim.Close(); sl@0: } sl@0: sl@0: void CTAnimWindow2::ConstructL(CTWinBase &parent, const TPoint &aPos, const TSize &aSize) sl@0: { sl@0: CTBlankWindow::ConstructL(parent); sl@0: iWin.SetColor(TRgb(128,128,128)); sl@0: iWin.SetVisible(EFalse); sl@0: SetExt(aPos,aSize); sl@0: iWin.Activate(); sl@0: User::LeaveIfError(iAnimBitmap1.Load(ANIM_BITMAP,EMbmTanimAnim1)); sl@0: User::LeaveIfError(iAnimBitmap2.Load(ANIM_BITMAP,EMbmTanimAnim2)); sl@0: User::LeaveIfError(iAnim.Construct(iWin, TPoint(10,10), &iAnimBitmap1, &iAnimBitmap2, &iAnimBitmap1, 1, iFont)); sl@0: iWin.SetVisible(ETrue); sl@0: } sl@0: sl@0: void CTAnimWindow2::ConstructExtLD(CTWinBase &aParent, const TPoint &aPos, const TSize &aSize) sl@0: // sl@0: // Call ConstructL, SetExt and either of these fail destroy this and leave sl@0: // sl@0: { sl@0: TRAPD(err,ConstructL(aParent, aPos, aSize)); sl@0: if (err!=KErrNone) sl@0: { sl@0: delete this; sl@0: User::Leave(err); sl@0: } sl@0: } sl@0: sl@0: // sl@0: // End of CTAnimWindow class // sl@0: // sl@0: sl@0: CTAnimWindowGroup::CTAnimWindowGroup(CTClient *aClient) : CTWindowGroup(aClient) sl@0: { sl@0: } sl@0: sl@0: void CTAnimWindowGroup::CursorKeyL(TInt xMove,TInt yMove,TInt modifiers) sl@0: { sl@0: if (iCursorMode==0) sl@0: iCurWin->AdjustSizeL(xMove,yMove,modifiers); sl@0: else if (iCurWin->SubType()==69) sl@0: { sl@0: if (iCursorMode==1) sl@0: ((CTAnimWindow1 *)iCurWin)->AdjustAnimRect(xMove,yMove,modifiers); sl@0: else sl@0: ((CTAnimWindow1 *)iCurWin)->AdjustPolyRectL(xMove,yMove,modifiers); sl@0: } sl@0: } sl@0: sl@0: void CTAnimWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime) sl@0: { sl@0: if (aKey.iModifiers&EModifierCtrl) sl@0: { sl@0: TInt type=0; sl@0: switch(aKey.iCode) sl@0: { sl@0: case 1: sl@0: type=1; sl@0: break; sl@0: case 2: sl@0: type=2; sl@0: break; sl@0: } sl@0: if (type!=0) sl@0: { sl@0: TPoint pos; sl@0: TSize size; sl@0: pos.iX=iCurWin->Size().iWidth>>2; sl@0: pos.iY=iCurWin->Size().iHeight>>2; sl@0: size.iWidth=iCurWin->Size().iWidth>>1; sl@0: size.iHeight=iCurWin->Size().iHeight>>1; sl@0: SetCurrentWindow(((CTAnimClient *)iClient)->CreateTestWindowL(pos,size,iCurWin,type)); sl@0: return; sl@0: } sl@0: } sl@0: if (aKey.iModifiers&EModifierFunc) sl@0: { sl@0: switch(aKey.iCode) sl@0: { sl@0: case 'x': sl@0: ((CTAnimClient *)iClient)->ExitL(); sl@0: break; sl@0: } sl@0: } sl@0: else switch(aKey.iCode) sl@0: { sl@0: case ' ': sl@0: iCursorMode=(iCursorMode+1)%3; sl@0: break; sl@0: case 8: sl@0: CTWin::Delete(iCurWin); sl@0: break; sl@0: case 9: sl@0: if (aKey.iModifiers&EModifierShift) sl@0: SetCurrentWindow(iCurWin->Prev()); sl@0: else sl@0: SetCurrentWindow(iCurWin->Next()); sl@0: break; sl@0: case 13: sl@0: if (iCurWin->SubType()==69) sl@0: ((CTAnimWindow1 *)iCurWin)->ToggleMask(); sl@0: break; sl@0: case EKeyLeftArrow: sl@0: CursorKeyL(-Xmove,0,aKey.iModifiers); sl@0: break; sl@0: case EKeyRightArrow: sl@0: CursorKeyL(Xmove,0,aKey.iModifiers); sl@0: break; sl@0: case EKeyUpArrow: sl@0: CursorKeyL(0,-Ymove,aKey.iModifiers); sl@0: break; sl@0: case EKeyDownArrow: sl@0: CursorKeyL(0,Ymove,aKey.iModifiers); sl@0: break; sl@0: default: sl@0: iCurWin->WinKeyL(aKey,aTime); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: // sl@0: sl@0: CTAnimClient::CTAnimClient() sl@0: { sl@0: } sl@0: sl@0: CTBaseWin *CTAnimClient::CreateTestWindowL(TPoint pos,TSize size,CTWinBase *parent, TInt type) sl@0: { sl@0: CTBaseWin *win; sl@0: if (type==1) sl@0: { sl@0: win=new(ELeave) CTAnimWindow1(iAnimDll); sl@0: win->ConstructExtLD(*parent,pos,size); sl@0: win->Activate(); sl@0: } sl@0: else sl@0: { sl@0: win=new(ELeave) CTAnimWindow2(iAnimDll); sl@0: win->ConstructExtLD(*parent,pos,size); sl@0: } sl@0: win->AssignGC(*iGc); sl@0: return(win); sl@0: } sl@0: sl@0: CTAnimClient::~CTAnimClient() sl@0: { sl@0: DestroyWindows(); sl@0: iAnimDll.Close(); sl@0: } sl@0: sl@0: void CTAnimClient::ErrorTests() sl@0: { sl@0: RAnimDll animDll=RAnimDll(iWs); sl@0: if (animDll.Load(NONEXISTENT_DLL_NAME)!=KErrNotFound) sl@0: AnimPanic(EAnimPanicBadLoadFailed); sl@0: animDll.Close(); // Close should be harmless, but unnecassary sl@0: RAnimDll animDll2=RAnimDll(iWs); sl@0: if (animDll2.Load(NONEXISTENT_DLL_NAME)!=KErrNotFound) sl@0: AnimPanic(EAnimPanicBadLoadFailed); sl@0: } sl@0: sl@0: void CTAnimClient::ConstructL() sl@0: { sl@0: CTClient::ConstructL(); sl@0: sl@0: iGroup=new(ELeave) CTAnimWindowGroup(this); sl@0: iGroup->ConstructL(); sl@0: sl@0: ErrorTests(); sl@0: sl@0: iAnimDll=RAnimDll(iWs); sl@0: User::LeaveIfError(iAnimDll.Load(ANIM_DLL_NAME)); sl@0: sl@0: CreateTestWindowL(TPoint(30,20),TSize(220,140),iGroup, 1); sl@0: CreateTestWindowL(TPoint(260,60),TSize(60,40),iGroup, 2); sl@0: iGroup->SetCurrentWindow(iGroup->Child()); sl@0: } sl@0: sl@0: void CTAnimClient::ExitL() sl@0: { sl@0: CActiveScheduler::Stop(); sl@0: User::Leave(0); // Signals RunL not to do another Request() sl@0: } sl@0: sl@0: GLDEF_C CTClient *CreateClientL() sl@0: { sl@0: return(new(ELeave) CTAnimClient()); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: return(TestLibStartUp(CreateClientL)); sl@0: }