sl@0: /* sl@0: * Copyright (c) 1997-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: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "TESTPANI.H" sl@0: sl@0: // *************************************************************************** sl@0: // MDEMPICTUREHEADERFACTORY IMPLEMENTATION sl@0: // *************************************************************************** sl@0: sl@0: EXPORT_C MDemPictureFactory::MDemPictureFactory() sl@0: // Fix to force GCC to export the vtable. sl@0: // sl@0: {} sl@0: sl@0: sl@0: EXPORT_C void MDemPictureFactory::NewPictureL(TPictureHeader& aHeader,const CStreamStore& aDeferredPictureStore)const sl@0: // From the picture header, instantiates the correct concrete picture, and sl@0: // restores it frorm the specified stream. sl@0: // sl@0: { sl@0: if (aHeader.iPictureType==KUidXzePictureType) sl@0: aHeader.iPicture=CXzePicture::NewL(aDeferredPictureStore,aHeader.iPicture.AsId()); sl@0: else if(aHeader.iPictureType==KUidXzeDoorType) sl@0: aHeader.iPicture=CXzeDoor::NewL(aDeferredPictureStore,aHeader.iPicture.AsId()); sl@0: else sl@0: Panic(EPictureTypeNotSupportedByHeader); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: // *************************************************************************** sl@0: // TEST PICTURE IMPLEMENTATION sl@0: // *************************************************************************** sl@0: EXPORT_C CXzePicture* CXzePicture::NewL(TChar aLabel) sl@0: {return new(ELeave) CXzePicture(aLabel);} sl@0: sl@0: sl@0: EXPORT_C CXzePicture* CXzePicture::NewL(const CStreamStore& aStore,TStreamId aId) sl@0: // Restoring NewL. sl@0: // sl@0: { sl@0: CXzePicture* self=new(ELeave) CXzePicture(); sl@0: CleanupStack::PushL(self); sl@0: self->RestoreL(aStore,aId); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: EXPORT_C CXzePicture::CXzePicture(TChar aLabel) sl@0: // Sets the startup attributes of this picture sl@0: // sl@0: : iLabel(aLabel) sl@0: {ResetToOriginal();} sl@0: sl@0: sl@0: EXPORT_C CXzePicture::CXzePicture() sl@0: // Sets the startup attributes of this picture sl@0: // sl@0: // sl@0: {ResetToOriginal();} sl@0: sl@0: sl@0: EXPORT_C CXzePicture::~CXzePicture() sl@0: {} sl@0: sl@0: sl@0: EXPORT_C void CXzePicture::ExternalizeL(RWriteStream& aStream)const sl@0: // Save this picture. sl@0: // Typically called from the base class StoreL(); sl@0: // sl@0: {aStream.WriteUint32L(iLabel);} sl@0: sl@0: sl@0: EXPORT_C void CXzePicture::InternalizeL(RReadStream& aStream) sl@0: // Load this picture sl@0: // sl@0: {iLabel=(TChar)aStream.ReadUint32L();} sl@0: sl@0: sl@0: EXPORT_C void CXzePicture::RestoreL(const CStreamStore& aStore,TStreamId aStreamId) sl@0: // Create a read-stream over aStore, and open it over the specified stream ID. sl@0: // Internalize picture from this stream. sl@0: // sl@0: { sl@0: RStoreReadStream stream; sl@0: stream.OpenLC(aStore,aStreamId); sl@0: stream>> *this; sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CXzePicture::Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,MGraphicsDeviceMap* aMap) const sl@0: // Draw this simple picture. sl@0: // sl@0: { sl@0: aGc.Reset(); sl@0: aGc.SetClippingRect(aClipRect); sl@0: TSize size; // Size of graphics device in pixels sl@0: GetSizeInPixels(aMap,size); sl@0: TRect box; // The rectangle that exactly fits the picture sl@0: box.iTl=aTopLeft; sl@0: box.iBr.iX=aTopLeft.iX+size.iWidth; sl@0: box.iBr.iY=aTopLeft.iY+size.iHeight; sl@0: TRgb white(255,255,255); sl@0: // First draw outer box and fill in rest of box. sl@0: aGc.SetBrushColor(white); sl@0: aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: aGc.DrawRect(box); sl@0: // Now draw label sl@0: CFont* font; sl@0: TFontSpec fontSpec(_L("Arial"),213); sl@0: if (aMap->GetNearestFontInTwips(font,fontSpec)<0) sl@0: { sl@0: return; sl@0: } sl@0: aGc.UseFont(font); sl@0: TBuf<1> label; label.Append(iLabel); sl@0: TInt baselineOffset=(box.Height()+font->AscentInPixels())/2; sl@0: aGc.SetBrushStyle(CGraphicsContext::ENullBrush); sl@0: aGc.DrawText(label,box,baselineOffset,CGraphicsContext::ECenter); sl@0: aGc.DiscardFont(); sl@0: aMap->ReleaseFont(font); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CXzePicture::GetOriginalSizeInTwips(TSize& aSize)const sl@0: // sl@0: {aSize=iOriginalSizeInTwips;} sl@0: sl@0: sl@0: EXPORT_C CXzeDoor* CXzeDoor::NewL(TChar aLabel,TBool aAlwaysFailToDetach) sl@0: {return new(ELeave) CXzeDoor(aLabel,aAlwaysFailToDetach);} sl@0: sl@0: sl@0: EXPORT_C CXzeDoor* CXzeDoor::NewL(const CStreamStore& aStore,TStreamId aId) sl@0: // Restoring NewL. sl@0: // sl@0: { sl@0: CXzeDoor* self=new(ELeave) CXzeDoor(EFalse); sl@0: CleanupStack::PushL(self); sl@0: self->RestoreL(aStore,aId); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: EXPORT_C CXzeDoor::CXzeDoor(TChar aLabel,TBool aAlwaysFailToDetach) sl@0: // Sets the startup attributes of this picture sl@0: // sl@0: : CXzePicture(aLabel), iAlwaysFailToDetach(aAlwaysFailToDetach) sl@0: {ResetToOriginal();} sl@0: sl@0: sl@0: EXPORT_C CXzeDoor::CXzeDoor(TBool aAlwaysFailToDetach) sl@0: // Sets the startup attributes of this picture sl@0: // sl@0: // sl@0: : iAlwaysFailToDetach(aAlwaysFailToDetach) sl@0: {ResetToOriginal();} sl@0: sl@0: sl@0: EXPORT_C void CXzeDoor::DetachFromStoreL(TDetach /*aDegree*/) sl@0: // sl@0: // sl@0: { sl@0: if (iAlwaysFailToDetach) sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: EXPORT_C void CXzeDoor::ExternalizeL(RWriteStream& aStream)const sl@0: // Save this picture. sl@0: // Typically called from the base class StoreL(); sl@0: // sl@0: { sl@0: CXzePicture::ExternalizeL(aStream); sl@0: aStream.WriteUint8L((TUint8)iAlwaysFailToDetach!=EFalse); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CXzeDoor::InternalizeL(RReadStream& aStream) sl@0: // Load this picture sl@0: // sl@0: { sl@0: CXzePicture::InternalizeL(aStream); sl@0: iAlwaysFailToDetach=TBool(aStream.ReadUint8L()); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CXzeDoor::RestoreL(const CStreamStore& aStore,TStreamId aStreamId) sl@0: // Create a read-stream over aStore, and open it over the specified stream ID. sl@0: // Internalize picture from this stream. sl@0: // sl@0: { sl@0: RStoreReadStream stream; sl@0: stream.OpenLC(aStore,aStreamId); sl@0: stream>> *this; sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C CTestPicture* CTestPicture::NewL() sl@0: {return new(ELeave) CTestPicture();} sl@0: sl@0: sl@0: EXPORT_C CTestPicture::CTestPicture() sl@0: {ResetToOriginal();} sl@0: sl@0: sl@0: EXPORT_C void CTestPicture::GetOriginalSizeInTwips(TSize& aSize)const sl@0: // sl@0: {aSize=iOriginalSizeInTwips;} sl@0: sl@0: sl@0: EXPORT_C void CTestPicture::Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,MGraphicsDeviceMap* /*aMap*/) const sl@0: // draw a simple object sl@0: { sl@0: aGc.Reset(); sl@0: aGc.SetClippingRect(aClipRect); sl@0: TSize size; // Size in pixels sl@0: TSize sizeInner; // In pixels sl@0: TRect box; sl@0: GetSizeInPixels(aGc.Device(),size); sl@0: box.iTl=aTopLeft; sl@0: box.iBr.iX=aTopLeft.iX+size.iWidth; sl@0: box.iBr.iY=aTopLeft.iY+size.iHeight; sl@0: TRgb black(0,0,0); sl@0: TRgb white(255,255,255); sl@0: // First draw outer box and fill in rest of box. sl@0: aGc.SetBrushColor(white); sl@0: aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: aGc.DrawRect(box); sl@0: // Inner box. sl@0: sizeInner.iWidth=size.iWidth/3; sl@0: sizeInner.iHeight=size.iHeight/3; sl@0: box.iTl.iX+=sizeInner.iWidth; sl@0: box.iTl.iY+=sizeInner.iHeight; sl@0: box.iBr.iX-=sizeInner.iWidth; sl@0: box.iBr.iY-=+sizeInner.iHeight; sl@0: aGc.SetBrushColor(black); sl@0: aGc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush); sl@0: aGc.DrawRect(box); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CTestPicture::ExternalizeL(RWriteStream& /*aStream*/)const sl@0: {} sl@0: sl@0: sl@0: //////////////////////////////////////////////////////////////////////// sl@0: sl@0: EXPORT_C CDummyField::CDummyField() sl@0: { sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CDummyField::Value(TPtr& aValueText) sl@0: { sl@0: if (aValueText.MaxLength() < 3) sl@0: return 3; sl@0: else sl@0: { sl@0: aValueText = _L("XXX"); sl@0: return 0; sl@0: } sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CDummyField::ExternalizeL(RWriteStream& aStream)const sl@0: { sl@0: aStream.WriteUint8L(0); // empty streams cause problems sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CDummyField::InternalizeL(RReadStream& aStream) sl@0: { sl@0: TUint8 dummy=aStream.ReadUint8L(); sl@0: dummy=0; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TUid CDummyField::Type() const sl@0: { sl@0: return KNullUid; sl@0: }