First public contribution.
1 // Copyright (c) 2007-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "tcontextbase.h"
20 CTBitGdiContext::CTBitGdiContext() :
26 CTBitGdiContext* CTBitGdiContext::NewL(CFbsBitmapDevice* aDevice, TBool aActivate)
28 CTBitGdiContext* self = new (ELeave) CTBitGdiContext;
29 CleanupStack::PushL (self);
30 self->ConstructL (aDevice, aActivate);
35 void CTBitGdiContext::ConstructL(CFbsBitmapDevice* aDevice, TBool aActivate)
39 User::LeaveIfError(aDevice->CreateContext (iGc));
43 iGc = CFbsBitGc::NewL();
47 CTBitGdiContext::~CTBitGdiContext()
52 TInt CTBitGdiContext::Activate(CBitmapDevice *aDevice)
54 CFbsDevice* device = (CFbsDevice *)aDevice;
55 iGc->Activate(device);
59 void CTBitGdiContext::SetOrigin(const TPoint& aOrigin)
61 iGc->SetOrigin (aOrigin);
64 void CTBitGdiContext::SetClippingRegion(const TRegion& aRegion)
66 TInt result = iGc->SetClippingRegion (aRegion);
70 void CTBitGdiContext::ResetClippingRegion()
72 iGc->CancelClipping();
75 void CTBitGdiContext::SetDrawMode(DirectGdi::TDrawMode aMode)
77 CGraphicsContext::TDrawMode mode = CGraphicsContext::EDrawModePEN;
78 if (aMode == DirectGdi::EDrawModeWriteAlpha)
80 mode = CGraphicsContext::EDrawModeWriteAlpha;
82 iGc->SetDrawMode(mode);
85 void CTBitGdiContext::SetPenColor(const TRgb& aColor)
87 iGc->SetPenColor (aColor);
90 void CTBitGdiContext::SetPenStyle(DirectGdi::TPenStyle aStyle)
92 // The CGraphicsContext::TPenStyle enumeration has the same values as the
93 // DirectGdi::TPenStyle. If these change then this function will need to be updated.
94 iGc->SetPenStyle(static_cast<CGraphicsContext::TPenStyle>(aStyle));
97 void CTBitGdiContext::SetPenSize(const TSize& aSize)
99 iGc->SetPenSize (aSize);
102 void CTBitGdiContext::SetTextShadowColor(const TRgb& aColor)
104 iGc->SetShadowColor(aColor);
107 void CTBitGdiContext::SetBrushColor(const TRgb& aColor)
109 iGc->SetBrushColor (aColor);
112 void CTBitGdiContext::SetBrushStyle(DirectGdi::TBrushStyle aStyle)
114 // The CGraphicsContext::TBrushStyle enumeration has the same values as the
115 // DirectGdi::TBrushStyle. If these change then this function will need to be updated.
116 iGc->SetBrushStyle(static_cast<CGraphicsContext::TBrushStyle>(aStyle));
119 void CTBitGdiContext::SetBrushOrigin(const TPoint& aOrigin)
121 iGc->SetBrushOrigin (aOrigin);
124 void CTBitGdiContext::SetBrushPattern(const CFbsBitmap& aPattern)
126 iGc->UseBrushPattern (&aPattern);
129 void CTBitGdiContext::SetBrushPattern(TInt aHandle)
131 TInt result = iGc->UseBrushPattern(aHandle);
135 void CTBitGdiContext::ResetBrushPattern()
137 iGc->DiscardBrushPattern ();
140 void CTBitGdiContext::SetFont(const CFont* aFont)
142 iGc->UseFont (aFont);
145 void CTBitGdiContext::ResetFont()
150 void CTBitGdiContext::Reset()
155 TRgb CTBitGdiContext::BrushColor()
157 return iGc->BrushColor ();
160 TRgb CTBitGdiContext::PenColor()
162 return iGc->PenColor ();
165 TRgb CTBitGdiContext::TextShadowColor()
168 iGc->GetShadowColor(shadowColor);
172 void CTBitGdiContext::Clear(const TRect& aRect)
177 void CTBitGdiContext::Clear()
182 void CTBitGdiContext::MoveTo(const TPoint& aPoint)
184 iGc->MoveTo (aPoint);
187 void CTBitGdiContext::MoveBy(const TPoint& aVector)
189 iGc->MoveBy (aVector);
192 void CTBitGdiContext::Plot(const TPoint& aPoint)
197 void CTBitGdiContext::DrawLine(const TPoint& aStart, const TPoint& aEnd)
199 iGc->DrawLine (aStart, aEnd);
202 void CTBitGdiContext::DrawLineTo(const TPoint& aPoint)
204 iGc->DrawLineTo (aPoint);
207 void CTBitGdiContext::DrawLineBy(const TPoint& aVector)
209 iGc->DrawLineBy (aVector);
212 void CTBitGdiContext::DrawRect(const TRect& aRect)
214 iGc->DrawRect (aRect);
217 void CTBitGdiContext::DrawRoundRect(const TRect& aRect,
218 const TSize& aCornerSize)
220 iGc->DrawRoundRect (aRect, aCornerSize);
223 void CTBitGdiContext::DrawPolyLine(const CArrayFix<TPoint>& aPointList)
225 iGc->DrawPolyLine(&aPointList);
228 void CTBitGdiContext::DrawPolyLineNoEndPoint(const CArrayFix<TPoint>& aPointList)
230 iGc->DrawPolyLineNoEndPoint(&aPointList);
233 void CTBitGdiContext::DrawPolygon(const CArrayFix<TPoint>& aPoints, DirectGdi::TFillRule aRule)
235 TInt result = iGc->DrawPolygon(&aPoints, static_cast<CGraphicsContext::TFillRule>(aRule));
239 void CTBitGdiContext::DrawArc(const TRect& aRect, const TPoint& aStart,
242 iGc->DrawArc (aRect, aStart, aEnd);
245 void CTBitGdiContext::DrawPie(const TRect& aRect, const TPoint& aStart,
248 iGc->DrawPie (aRect, aStart, aEnd);
251 void CTBitGdiContext::DrawEllipse(const TRect& aRect)
253 iGc->DrawEllipse (aRect);
256 void CTBitGdiContext::BitBltMasked(const TPoint& aDestPos,
257 const CFbsBitmap& aBitmap, const TRect& aSourceRect,
258 const CFbsBitmap& aAlpha, const TPoint& aAlphaPos)
260 // This overload of BitBltMasked maps to AlphaBlendBitmaps in BitGDI, which has the same signiature.
261 TInt result = iGc->AlphaBlendBitmaps(aDestPos, &aBitmap, aSourceRect, &aAlpha, aAlphaPos);
265 void CTBitGdiContext::BitBlt(const TPoint& aPoint, const CFbsBitmap& aBitmap)
267 iGc->BitBlt (aPoint, &aBitmap);
270 void CTBitGdiContext::DrawBitmap(const TRect& aDestRect,
271 const CFbsBitmap& aSource)
273 iGc->DrawBitmap (aDestRect, &aSource);
276 void CTBitGdiContext::BitBlt(const TPoint& aDestPos,
277 const CFbsBitmap& aBitmap, const TRect& aSrcRect)
279 iGc->BitBlt (aDestPos, &aBitmap, aSrcRect);
282 void CTBitGdiContext::BitBltMasked(const TPoint& aDestPos,
283 const CFbsBitmap& aBitmap, const TRect& aSrcRect,
284 const CFbsBitmap& aMask, TBool aInvertMask)
286 iGc->BitBltMasked (aDestPos, &aBitmap, aSrcRect, &aMask, aInvertMask);
289 void CTBitGdiContext::DrawBitmap(const TRect& aDestRect,
290 const CFbsBitmap& aBitmap, const TRect& aSrcRect)
292 iGc->DrawBitmap (aDestRect, &aBitmap, aSrcRect);
295 void CTBitGdiContext::DrawBitmapMasked(const TRect& aDestRect,
296 const CFbsBitmap& aBitmap, const TRect& aSrcRect,
297 const CFbsBitmap& aMask, TBool aInvertMask)
299 iGc->DrawBitmapMasked (aDestRect, &aBitmap, aSrcRect, &aMask, aInvertMask);
302 void CTBitGdiContext::CopyRect(const TPoint& aOffset, const TRect& aRect)
304 iGc->CopyRect (aOffset, aRect);
307 TBool CTBitGdiContext::HasBrushPattern() const
309 return iGc->IsBrushPatternUsed ();
312 TBool CTBitGdiContext::HasFont() const
314 return iGc->IsFontUsed ();
317 void CTBitGdiContext::ExternalizeL(RWriteStream& aWriteStream)
319 iGc->ExternalizeL (aWriteStream);
322 void CTBitGdiContext::InternalizeL(RReadStream& aReadStream)
324 iGc->InternalizeL (aReadStream);
327 void CTBitGdiContext::SetCharJustification(TInt aExcessWidth, TInt aNumGaps)
329 iGc->SetCharJustification (aExcessWidth, aNumGaps);
332 void CTBitGdiContext::SetWordJustification(TInt aExcessWidth, TInt aNumChars)
334 iGc->SetWordJustification (aExcessWidth, aNumChars);
337 void CTBitGdiContext::SetUnderlineStyle(DirectGdi::TFontUnderline aUnderlineStyle)
339 iGc->SetUnderlineStyle (static_cast<TFontUnderline>(aUnderlineStyle));
342 void CTBitGdiContext::SetStrikethroughStyle(DirectGdi::TFontStrikethrough aStrikethroughStyle)
344 iGc->SetStrikethroughStyle (static_cast<TFontStrikethrough>(aStrikethroughStyle));
347 void CTBitGdiContext::UpdateJustification(const TDesC& aText, const DirectGdi::TTextParameters* aParam)
349 iGc->UpdateJustification(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam));
352 void CTBitGdiContext::UpdateJustificationVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, TBool aUp)
354 iGc->UpdateJustificationVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aUp);
357 void CTBitGdiContext::SetFontNoDuplicate(const CFont* /*aFont*/)
361 void CTBitGdiContext::SetError(TInt aErr)
363 if (KErrNone == iError)
370 TInt CTBitGdiContext::GetError()
378 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam)
380 iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam));
383 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TPoint& aPosition)
385 iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aPosition);
388 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox)
390 iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox);
393 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TInt aBaselineOffset,
394 DirectGdi::TTextAlign aAlignment, TInt aMargin)
396 iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aBaselineOffset, static_cast<CGraphicsContext::TTextAlign>(aAlignment), aMargin);
399 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TInt aBaselineOffset,
400 TInt aTextWidth, DirectGdi::TTextAlign aAlignment, TInt aMargin)
402 iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aBaselineOffset, aTextWidth, static_cast<CGraphicsContext::TTextAlign>(aAlignment), aMargin);
405 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, TBool aUp)
407 iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aUp);
410 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TPoint& aPosition, TBool aUp)
412 iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aPosition, aUp);
415 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TBool aUp)
417 iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aUp);
420 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TInt aBaselineOffset,
421 TBool aUp, DirectGdi::TTextAlign aVerticalAlignment, TInt aMargin)
423 iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aBaselineOffset, aUp,
424 static_cast<CGraphicsContext::TTextAlign>(aVerticalAlignment), aMargin);
427 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TInt aBaselineOffset,
428 TInt aTextWidth, TBool aUp, DirectGdi::TTextAlign aVerticalAlignment, TInt aMargin)
430 iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aBaselineOffset, aTextWidth, aUp,
431 static_cast<CGraphicsContext::TTextAlign>(aVerticalAlignment), aMargin);
434 void CTBitGdiContext::DrawResource(const TPoint& aPos,
435 const TDrawableSourceAndEquivRotatedBmps& aSource,
436 DirectGdi::TGraphicsRotation aRotation)
440 case DirectGdi::EGraphicsRotation90:
441 iGc->BitBlt(aPos, aSource.iBmpRot90);
444 case DirectGdi::EGraphicsRotation180:
445 iGc->BitBlt(aPos, aSource.iBmpRot180);
448 case DirectGdi::EGraphicsRotation270:
449 iGc->BitBlt(aPos, aSource.iBmpRot270);
452 default: // DirectGdi::EGraphicsRotationNone
453 iGc->BitBlt(aPos, aSource.iBmpRotNone);
458 void CTBitGdiContext::DrawResource(const TRect& aDestRect,
459 const TDrawableSourceAndEquivRotatedBmps& aSource,
460 DirectGdi::TGraphicsRotation aRotation)
464 case DirectGdi::EGraphicsRotation90:
465 iGc->DrawBitmap(aDestRect, aSource.iBmpRot90);
468 case DirectGdi::EGraphicsRotation180:
469 iGc->DrawBitmap(aDestRect, aSource.iBmpRot180);
472 case DirectGdi::EGraphicsRotation270:
473 iGc->DrawBitmap(aDestRect, aSource.iBmpRot270);
476 default: // DirectGdi::EGraphicsRotationNone
477 iGc->DrawBitmap(aDestRect, aSource.iBmpRotNone);
482 void CTBitGdiContext::DrawResource(const TRect& aDestRect,
483 const TDrawableSourceAndEquivRotatedBmps& aSource,
484 const TRect& aSrcRect,
485 DirectGdi::TGraphicsRotation aRotation)
489 case DirectGdi::EGraphicsRotation90:
491 // Adjust the src rect to take account of the rotated bitmap
492 TRect rect = aSrcRect;
493 rect.iBr.iX = aSrcRect.iTl.iX + aSrcRect.Height();
494 rect.iBr.iY = aSrcRect.iTl.iY + aSrcRect.Width();
495 iGc->DrawBitmap(aDestRect, aSource.iBmpRot90, rect);
499 case DirectGdi::EGraphicsRotation180:
500 iGc->DrawBitmap(aDestRect, aSource.iBmpRot180, aSrcRect);
503 case DirectGdi::EGraphicsRotation270:
505 // Adjust the src rect to take account of the rotated bitmap
506 TRect rect = aSrcRect;
507 rect.iBr.iX = aSrcRect.iTl.iX + aSrcRect.Height();
508 rect.iBr.iY = aSrcRect.iTl.iY + aSrcRect.Width();
509 iGc->DrawBitmap(aDestRect, aSource.iBmpRot270, rect);
513 default: // DirectGdi::EGraphicsRotationNone
514 iGc->DrawBitmap(aDestRect, aSource.iBmpRotNone, aSrcRect);
519 void CTBitGdiContext::DrawResource(const TRect& aDestRect,
520 const TDrawableSourceAndEquivRotatedBmps& aSource,
521 const TDesC8& /*aParam*/)
523 // NB we only support drawing drawable sources as images currently
524 iGc->DrawBitmap(aDestRect, aSource.iBmpRotNone);
527 TInt CTBitGdiContext::GetInterface(TUid /*aInterfaceId*/, TAny*& aInterface)
530 return KErrNotSupported;
533 void CTBitGdiContext::CopySettings(const CTContextBase& aGc)
535 CTBitGdiContext* gc = (CTBitGdiContext*)&aGc;
536 iGc->CopySettings(*(gc->iGc));