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