|
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 #include "graphicscontextstate.h" |
|
17 #include "cliwin.h" |
|
18 |
|
19 /*------------------------------------------------------------------------------ |
|
20 Description: Resets internal status of the graphics context to pre-defined values. |
|
21 -----------------------------------------------------------------------------*/ |
|
22 void TInternalGcStatus::ResetInternalStatus(CWsClientWindow* aWin) |
|
23 { |
|
24 iDrawMode = CGraphicsContext::EDrawModePEN; |
|
25 iPenColor = KRgbBlack; |
|
26 iBrushColor = aWin ? aWin->BackColor() : KRgbWhite; |
|
27 iPenStyle = CGraphicsContext::ESolidPen; |
|
28 iBrushStyle = CGraphicsContext::ENullBrush; |
|
29 iPenSize = TSize(1,1); |
|
30 iFontHandle = NULL; |
|
31 iUnderline = EUnderlineOff; |
|
32 iStrikethrough = EStrikethroughOff; |
|
33 iBrushPatternHandle = NULL; |
|
34 iBrushOrigin = TPoint(0,0); |
|
35 iCharExcessWidth = 0; |
|
36 iCharNumChars = 0; |
|
37 iWordExcessWidth = 0; |
|
38 iWordNumChars = 0; |
|
39 iOrigin = TPoint(0,0); |
|
40 iShadowColor = KRgbGray; |
|
41 } |
|
42 |
|
43 /*------------------------------------------------------------------------------ |
|
44 Description: Helper function to retrieve current data from the given buffer and |
|
45 set graphics context. |
|
46 -----------------------------------------------------------------------------*/ |
|
47 void TInternalGcStatus::InternalizeGcAttributesL(MWsGraphicsContext* aGc, RReadStream& aReadStream) |
|
48 { |
|
49 aGc->SetDrawMode((MWsGraphicsContext::TDrawMode)(aReadStream.ReadUint8L())); |
|
50 |
|
51 MWsGraphicsContext::TBrushStyle brushStyle = (MWsGraphicsContext::TBrushStyle) (aReadStream.ReadUint8L()); |
|
52 aGc->SetPenStyle((MWsGraphicsContext::TPenStyle) (aReadStream.ReadUint8L())); |
|
53 |
|
54 TRgb penColor; |
|
55 penColor.InternalizeL(aReadStream); |
|
56 aGc->SetPenColor(penColor); |
|
57 |
|
58 TRgb brushColor; |
|
59 brushColor.InternalizeL(aReadStream); |
|
60 aGc->SetBrushColor(brushColor); |
|
61 |
|
62 TSize size; |
|
63 aReadStream >> size; |
|
64 aGc->SetPenSize(size); |
|
65 |
|
66 aGc->ResetBrushPattern(); |
|
67 TInt brushHandle = aReadStream.ReadInt32L(); |
|
68 if(brushHandle) |
|
69 { |
|
70 aGc->SetBrushPattern(brushHandle); |
|
71 if (!aGc->HasBrushPattern() && brushStyle == MWsGraphicsContext::EPatternedBrush) |
|
72 { |
|
73 // Panic may occur if trying to set EPatternedBrush when a bitmap has not been |
|
74 // successfully set, so revert to null brush. |
|
75 brushStyle = MWsGraphicsContext::ENullBrush; |
|
76 } |
|
77 } |
|
78 // Wait until any brush pattern has been set before setting the brush style. |
|
79 aGc->SetBrushStyle(brushStyle); |
|
80 |
|
81 TInt wordExcessWidth = aReadStream.ReadUint32L(); |
|
82 TInt wordNumChars = aReadStream.ReadUint32L(); |
|
83 aGc->SetWordJustification(wordExcessWidth, wordNumChars); |
|
84 |
|
85 TInt charExcessWidth = aReadStream.ReadUint32L(); |
|
86 TInt charNumChars = aReadStream.ReadUint32L(); |
|
87 aGc->SetCharJustification(charExcessWidth, charNumChars); |
|
88 |
|
89 TRgb shadowColor; |
|
90 shadowColor.InternalizeL(aReadStream); |
|
91 aGc->SetTextShadowColor(shadowColor); |
|
92 |
|
93 TPoint origin; |
|
94 aReadStream >> origin; |
|
95 aGc->SetOrigin(origin); |
|
96 |
|
97 TPoint brushOrigin; |
|
98 aReadStream >> brushOrigin; |
|
99 aGc->SetBrushOrigin(brushOrigin); |
|
100 |
|
101 aGc->SetUnderlineStyle((MWsGraphicsContext::TFontUnderline) (aReadStream.ReadUint8L())); |
|
102 aGc->SetStrikethroughStyle((MWsGraphicsContext::TFontStrikethrough) (aReadStream.ReadUint8L())); |
|
103 |
|
104 aGc->ResetFont(); |
|
105 TInt fontHandle = aReadStream.ReadInt32L(); |
|
106 if(fontHandle) |
|
107 { |
|
108 CFbsBitGcFont font; |
|
109 TInt res = font.Duplicate(fontHandle); |
|
110 if(res == KErrNone) |
|
111 { |
|
112 aGc->SetFont(&font); |
|
113 font.Reset(); |
|
114 } |
|
115 } |
|
116 } |
|
117 |
|
118 /*------------------------------------------------------------------------------ |
|
119 Description: Helper function to save graphics context information into a given buffer. |
|
120 -----------------------------------------------------------------------------*/ |
|
121 void TInternalGcStatus::ExternalizeGcAttributesL(RWriteStream& aWriteStream) |
|
122 { |
|
123 aWriteStream.WriteUint8L(iDrawMode); |
|
124 aWriteStream.WriteUint8L(iBrushStyle); |
|
125 aWriteStream.WriteUint8L(iPenStyle); |
|
126 iPenColor.ExternalizeL(aWriteStream); |
|
127 iBrushColor.ExternalizeL(aWriteStream); |
|
128 aWriteStream << iPenSize; |
|
129 aWriteStream.WriteInt32L(iBrushPatternHandle); |
|
130 aWriteStream.WriteUint32L(iWordExcessWidth); |
|
131 aWriteStream.WriteUint32L(iWordNumChars); |
|
132 aWriteStream.WriteUint32L(iCharExcessWidth); |
|
133 aWriteStream.WriteUint32L(iCharNumChars); |
|
134 iShadowColor.ExternalizeL(aWriteStream); |
|
135 aWriteStream << iOrigin; |
|
136 aWriteStream << iBrushOrigin; |
|
137 aWriteStream.WriteUint8L(iUnderline); |
|
138 aWriteStream.WriteUint8L(iStrikethrough); |
|
139 aWriteStream.WriteInt32L(iFontHandle); |
|
140 } |
|
141 |