|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef MWSGRAPHICSCONTEXTTOBITGDIMAPPINGS_H |
|
21 #define MWSGRAPHICSCONTEXTTOBITGDIMAPPINGS_H |
|
22 |
|
23 #include <gdi.h> |
|
24 #include <graphics/wsgraphicscontext.h> |
|
25 |
|
26 class MWsGraphicsContextToBitGdiMappings |
|
27 { |
|
28 public: |
|
29 static CGraphicsContext::TFillRule Convert(MWsGraphicsContext::TFillRule aFillRule) { return (CGraphicsContext::TFillRule)aFillRule; } |
|
30 static CGraphicsContext::TPenStyle Convert(MWsGraphicsContext::TPenStyle aPenStyle) { return (CGraphicsContext::TPenStyle)aPenStyle; } |
|
31 static CGraphicsContext::TBrushStyle Convert(MWsGraphicsContext::TBrushStyle aBrushStyle) { return (CGraphicsContext::TBrushStyle)aBrushStyle; } |
|
32 static CGraphicsContext::TTextAlign Convert(MWsGraphicsContext::TTextAlign aTextAlign) { return (CGraphicsContext::TTextAlign)aTextAlign; } |
|
33 static TFontUnderline Convert(MWsGraphicsContext::TFontUnderline aFontUnderline) { return (TFontUnderline)aFontUnderline; } |
|
34 static TFontStrikethrough Convert(MWsGraphicsContext::TFontStrikethrough aFontStrikethrough) { return (TFontStrikethrough)aFontStrikethrough; } |
|
35 static CGraphicsContext::TDrawMode LossyConvert(MWsGraphicsContext::TDrawMode aDrawMode) |
|
36 { |
|
37 if(aDrawMode == MWsGraphicsContext::EDrawModePEN) |
|
38 return CGraphicsContext::EDrawModePEN; |
|
39 if(aDrawMode == MWsGraphicsContext::EDrawModeWriteAlpha) |
|
40 return CGraphicsContext::EDrawModeWriteAlpha; |
|
41 return CGraphicsContext::EDrawModePEN; |
|
42 } |
|
43 static TInt LossyConvertPenSize(const TSize& aSize) { return aSize.iWidth; } |
|
44 |
|
45 }; |
|
46 |
|
47 |
|
48 template<class T> |
|
49 class TArrayWrapper : public TArray<T> |
|
50 { |
|
51 public: |
|
52 TArrayWrapper(const T* aArray, TInt aCount); |
|
53 private: |
|
54 static TInt Count(const CBase* aPtr); |
|
55 static const TAny* At(const CBase* aPtr, TInt aIndex); |
|
56 private: |
|
57 const T* iArray; |
|
58 const TInt iCount; |
|
59 }; |
|
60 |
|
61 template<class T> |
|
62 TArrayWrapper<T>::TArrayWrapper(const T* aArray, TInt aCount) |
|
63 : TArray<T>(TArrayWrapper::Count, TArrayWrapper::At, reinterpret_cast<const CBase*>(this)), iArray(aArray), iCount(aCount) |
|
64 { |
|
65 //reinterpret_cast above since this class doesn't derive from CBase but TArray is |
|
66 //only silly requiring CBase as opposed to TAny, so this is safe |
|
67 ASSERT(iArray); |
|
68 } |
|
69 |
|
70 template<class T> |
|
71 TInt TArrayWrapper<T>::Count(const CBase* aPtr) |
|
72 { |
|
73 //reinterpret_cast since this class doesn't derive from CBase but TArray is |
|
74 //only silly requiring CBase as opposed to TAny, so this is safe |
|
75 const TArrayWrapper* self = reinterpret_cast<const TArrayWrapper*>(aPtr); |
|
76 return self->iCount; |
|
77 } |
|
78 |
|
79 template<class T> |
|
80 const TAny* TArrayWrapper<T>::At(const CBase* aPtr, TInt aIndex) |
|
81 { |
|
82 //reinterpret_cast since this class doesn't derive from CBase but TArray is |
|
83 //only silly requiring CBase as opposed to TAny, so this is safe |
|
84 const TArrayWrapper* self = reinterpret_cast<const TArrayWrapper*>(aPtr); |
|
85 if(!Rng(0, aIndex, self->iCount - 1)) |
|
86 User::Panic(_L("USER"), 130); //out of bounds (RArray/RPointerArray) |
|
87 return self->iArray + aIndex; |
|
88 } |
|
89 |
|
90 |
|
91 #endif //MWSGRAPHICSCONTEXTTOBITGDIMAPPINGS_H |
|
92 |