diff -r bf7481649c98 -r 7f25ef56562d windowing/windowserver/test/tauto/mwsgraphicscontexttodirectgdimappings.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/windowing/windowserver/test/tauto/mwsgraphicscontexttodirectgdimappings.h Wed Jun 23 19:41:15 2010 +0300 @@ -0,0 +1,81 @@ +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#ifndef __MWSGRAPHICSCONTEXTTODIRECTGDIMAPPINGS_H__ +#define __MWSGRAPHICSCONTEXTTODIRECTGDIMAPPINGS_H__ + +#include +#include +#include + +class MWsGraphicsContextToDirectGdiMappings + { +public: + static DirectGdi::TFillRule Convert(MWsGraphicsContext::TFillRule aFillRule) { return (DirectGdi::TFillRule)aFillRule; } + static DirectGdi::TPenStyle Convert(MWsGraphicsContext::TPenStyle aPenStyle) { return (DirectGdi::TPenStyle)aPenStyle; } + static DirectGdi::TBrushStyle Convert(MWsGraphicsContext::TBrushStyle aBrushStyle) { return (DirectGdi::TBrushStyle)aBrushStyle; } + static DirectGdi::TTextAlign Convert(MWsGraphicsContext::TTextAlign aTextAlign) { return (DirectGdi::TTextAlign)aTextAlign; } + static DirectGdi::TFontUnderline Convert(MWsGraphicsContext::TFontUnderline aFontUnderline) { return (DirectGdi::TFontUnderline)aFontUnderline; } + static DirectGdi::TFontStrikethrough Convert(MWsGraphicsContext::TFontStrikethrough aFontStrikethrough) { return (DirectGdi::TFontStrikethrough)aFontStrikethrough; } + static const DirectGdi::TTextParameters* Convert(const MWsGraphicsContext::TTextParameters* aParam) { return reinterpret_cast(aParam); } + static DirectGdi::TDrawMode LossyConvert(MWsGraphicsContext::TDrawMode aDrawMode) + {return (aDrawMode==MWsGraphicsContext::EDrawModeWriteAlpha ? DirectGdi::EDrawModeWriteAlpha : DirectGdi::EDrawModePEN);} + }; + + +template +class TArrayWrapper : public TArray + { +public: + TArrayWrapper(const T* aArray, TInt aCount); +private: + static TInt Count(const CBase* aPtr); + static const TAny* At(const CBase* aPtr, TInt aIndex); +private: + const T* iArray; + const TInt iCount; + }; + +template +TArrayWrapper::TArrayWrapper(const T* aArray, TInt aCount) + : TArray(TArrayWrapper::Count, TArrayWrapper::At, reinterpret_cast(this)), iArray(aArray), iCount(aCount) + { + //reinterpret_cast above since this class doesn't derive from CBase but TArray is + //only silly requiring CBase as opposed to TAny, so this is safe + ASSERT(iArray); + } + +template +TInt TArrayWrapper::Count(const CBase* aPtr) + { + //reinterpret_cast since this class doesn't derive from CBase but TArray is + //only silly requiring CBase as opposed to TAny, so this is safe + const TArrayWrapper* self = reinterpret_cast(aPtr); + return self->iCount; + } + +template +const TAny* TArrayWrapper::At(const CBase* aPtr, TInt aIndex) + { + //reinterpret_cast since this class doesn't derive from CBase but TArray is + //only silly requiring CBase as opposed to TAny, so this is safe + const TArrayWrapper* self = reinterpret_cast(aPtr); + if(!Rng(0, aIndex, self->iCount - 1)) + User::Panic(_L("USER"), 130); //out of bounds (RArray/RPointerArray) + return self->iArray + aIndex; + } + + +#endif //__MWSGRAPHICSCONTEXTTODIRECTGDIMAPPINGS_H__