|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #ifndef BITGDITOMWSGRAPHICSCONTEXTMAPPINGS_H_ |
|
17 #define BITGDITOMWSGRAPHICSCONTEXTMAPPINGS_H_ |
|
18 |
|
19 #include <gdi.h> |
|
20 #include <graphics/wsgraphicscontext.h> |
|
21 |
|
22 class BitGdiToMWsGraphicsContextMappings |
|
23 { |
|
24 public: |
|
25 static MWsGraphicsContext::TFillRule Convert(CGraphicsContext::TFillRule aFillRule) { return (MWsGraphicsContext::TFillRule)aFillRule; } |
|
26 static MWsGraphicsContext::TPenStyle Convert(CGraphicsContext::TPenStyle aPenStyle) { return (MWsGraphicsContext::TPenStyle)aPenStyle; } |
|
27 static MWsGraphicsContext::TBrushStyle Convert(CGraphicsContext::TBrushStyle aBrushStyle) { return (MWsGraphicsContext::TBrushStyle)aBrushStyle; } |
|
28 static MWsGraphicsContext::TTextAlign Convert(CGraphicsContext::TTextAlign aTextAlign) { return (MWsGraphicsContext::TTextAlign)aTextAlign; } |
|
29 static MWsGraphicsContext::TFontUnderline Convert(TFontUnderline aFontUnderline) { return (MWsGraphicsContext::TFontUnderline)aFontUnderline; } |
|
30 static MWsGraphicsContext::TFontStrikethrough Convert(TFontStrikethrough aFontStrikethrough) { return (MWsGraphicsContext::TFontStrikethrough)aFontStrikethrough; } |
|
31 static const MWsGraphicsContext::TTextParameters* Convert(CGraphicsContext::TTextParameters* aParam) { return reinterpret_cast<MWsGraphicsContext::TTextParameters*>(aParam); } |
|
32 static MWsGraphicsContext::TDrawMode LossyConvert(CGraphicsContext::TDrawMode aDrawMode) |
|
33 { |
|
34 if(aDrawMode == CGraphicsContext::EDrawModePEN) |
|
35 return MWsGraphicsContext::EDrawModePEN; |
|
36 if(aDrawMode == CGraphicsContext::EDrawModeWriteAlpha) |
|
37 return MWsGraphicsContext::EDrawModeWriteAlpha; |
|
38 return MWsGraphicsContext::EDrawModePEN; |
|
39 } |
|
40 }; |
|
41 |
|
42 |
|
43 template<class T> |
|
44 class TArrayWrapper : public TArray<T> |
|
45 { |
|
46 public: |
|
47 TArrayWrapper(const T* aArray, TInt aCount); |
|
48 private: |
|
49 static TInt Count(const CBase* aPtr); |
|
50 static const TAny* At(const CBase* aPtr, TInt aIndex); |
|
51 private: |
|
52 const T* iArray; |
|
53 const TInt iCount; |
|
54 }; |
|
55 |
|
56 template<class T> |
|
57 TArrayWrapper<T>::TArrayWrapper(const T* aArray, TInt aCount) |
|
58 : TArray<T>(TArrayWrapper::Count, TArrayWrapper::At, reinterpret_cast<const CBase*>(this)), iArray(aArray), iCount(aCount) |
|
59 { |
|
60 //reinterpret_cast above since this class doesn't derive from CBase but TArray is |
|
61 //only silly requiring CBase as opposed to TAny, so this is safe |
|
62 ASSERT(iArray); |
|
63 } |
|
64 |
|
65 template<class T> |
|
66 TInt TArrayWrapper<T>::Count(const CBase* aPtr) |
|
67 { |
|
68 //reinterpret_cast since this class doesn't derive from CBase but TArray is |
|
69 //only silly requiring CBase as opposed to TAny, so this is safe |
|
70 const TArrayWrapper* self = reinterpret_cast<const TArrayWrapper*>(aPtr); |
|
71 return self->iCount; |
|
72 } |
|
73 |
|
74 template<class T> |
|
75 const TAny* TArrayWrapper<T>::At(const CBase* aPtr, TInt aIndex) |
|
76 { |
|
77 //reinterpret_cast since this class doesn't derive from CBase but TArray is |
|
78 //only silly requiring CBase as opposed to TAny, so this is safe |
|
79 const TArrayWrapper* self = reinterpret_cast<const TArrayWrapper*>(aPtr); |
|
80 if(!Rng(0, aIndex, self->iCount - 1)) |
|
81 User::Panic(_L("USER"), 130); //out of bounds (RArray/RPointerArray) |
|
82 return self->iArray + aIndex; |
|
83 } |
|
84 |
|
85 #endif //BITGDITOMWSGRAPHICSCONTEXTMAPPINGS_H |
|
86 |