sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "directgdigcwrapper.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "mwsgraphicscontexttodirectgdimappings.h" sl@0: #include "panic.h" sl@0: sl@0: CDirectGdiGcWrapper* CDirectGdiGcWrapper::NewL() sl@0: { sl@0: CDirectGdiGcWrapper* self = new(ELeave) CDirectGdiGcWrapper; sl@0: CleanupStack::PushL(self); sl@0: CDirectGdiDriver* driver = CDirectGdiDriver::Static(); sl@0: User::LeaveIfNull(driver); sl@0: self->iContext = CDirectGdiContext::NewL(*driver); sl@0: self->iErrorCode = KErrNone; sl@0: self->iGcBuf = CBufSeg::NewL(512); sl@0: //MWsFader sl@0: //Default in BitGdi was 128 for the blackMap and 255 for the whiteMap sl@0: //SetFadingParameters shows how the fade color is computed sl@0: self->iFadeColor.SetInternal(0x80FFFFFF); sl@0: sl@0: self->iLut = PtrTo16BitNormalisationTable(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CDirectGdiGcWrapper::~CDirectGdiGcWrapper() sl@0: { sl@0: delete iContext; sl@0: delete iGcBuf; sl@0: for (TInt i = 0; i < iDrawableSources.Count(); ++i) sl@0: { sl@0: iDrawableSources[i]->Close(); sl@0: } sl@0: iDrawableSources.ResetAndDestroy(); sl@0: iClippingRegion.Close(); sl@0: } sl@0: sl@0: TAny* CDirectGdiGcWrapper::ResolveObjectInterface(TUint aTypeId) sl@0: { sl@0: switch(aTypeId) sl@0: { sl@0: case MWsGraphicsContext::EWsObjectInterfaceId: sl@0: return static_cast(this); sl@0: case MWsFader::EWsObjectInterfaceId: sl@0: return static_cast(this); sl@0: case MWsDrawableSourceProvider::EWsObjectInterfaceId: sl@0: return static_cast(this); sl@0: case MWsTextCursor::EWsObjectInterfaceId: sl@0: return static_cast(this); sl@0: } sl@0: return NULL; sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap) sl@0: { sl@0: iContext->BitBlt(aDestPos, aSourceBitmap); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect) sl@0: { sl@0: iContext->BitBlt(aDestPos, aSourceBitmap, aSourceRect); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask) sl@0: { sl@0: iContext->BitBltMasked(aDestPos, aSourceBitmap, aSourceRect, aMaskBitmap, aInvertMask); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, const TPoint& aMaskPos) sl@0: { sl@0: iContext->BitBltMasked(aDestPos, aSourceBitmap, aSourceRect, aMaskBitmap, aMaskPos); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::ResetClippingRegion() sl@0: { sl@0: iContext->ResetClippingRegion(); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::Clear() sl@0: { sl@0: iContext->Clear(); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::Clear(const TRect& aRect) sl@0: { sl@0: iContext->Clear(aRect); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::ResetBrushPattern() sl@0: { sl@0: iContext->ResetBrushPattern(); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::ResetFont() sl@0: { sl@0: iContext->ResetFont(); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd) sl@0: { sl@0: iContext->DrawArc(aRect, aStart, aEnd); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd) sl@0: { sl@0: iContext->DrawPie(aRect, aStart, aEnd); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap) sl@0: { sl@0: iContext->DrawBitmap(aDestRect, aSourceBitmap); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect) sl@0: { sl@0: iContext->DrawBitmap(aDestRect, aSourceBitmap, aSourceRect); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask) sl@0: { sl@0: iContext->DrawBitmapMasked(aDestRect, aSourceBitmap, aSourceRect, aMaskBitmap, aInvertMask); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawRoundRect(const TRect& aRect, const TSize& aEllipse) sl@0: { sl@0: iContext->DrawRoundRect(aRect, aEllipse); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawPolyLine(const TArray& aPointList) sl@0: { sl@0: iContext->DrawPolyLine(aPointList); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawPolyLineNoEndPoint(const TArray& aPointList) sl@0: { sl@0: iContext->DrawPolyLineNoEndPoint(aPointList); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawPolygon(const TArray& aPointList, TFillRule aFillRule) sl@0: { sl@0: iContext->DrawPolygon(aPointList, MWsGraphicsContextToDirectGdiMappings::Convert(aFillRule)); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawEllipse(const TRect& aRect) sl@0: { sl@0: iContext->DrawEllipse(aRect); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawLine(const TPoint& aStart, const TPoint& aEnd) sl@0: { sl@0: iContext->DrawLine(aStart, aEnd); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawLineTo(const TPoint& aPoint) sl@0: { sl@0: iContext->DrawLineTo(aPoint); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawLineBy(const TPoint& aVector) sl@0: { sl@0: iContext->DrawLineBy(aVector); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawRect(const TRect& aRect) sl@0: { sl@0: iContext->DrawRect(aRect); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam) sl@0: { sl@0: iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam)); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TPoint& aPosition) sl@0: { sl@0: iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aPosition); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect) sl@0: { sl@0: iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipFillRect, TInt aBaselineOffset, TTextAlign aHrz, TInt aMargin) sl@0: { sl@0: iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipFillRect, aBaselineOffset, MWsGraphicsContextToDirectGdiMappings::Convert(aHrz), aMargin); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, TBool aUp) sl@0: { sl@0: iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aUp); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TPoint& aPosition, TBool aUp) sl@0: { sl@0: iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aPosition, aUp); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TBool aUp) sl@0: { sl@0: iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aUp); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TInt aBaselineOffset, TBool aUp, TTextAlign aVert, TInt aMargin) sl@0: { sl@0: iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aBaselineOffset, aUp, MWsGraphicsContextToDirectGdiMappings::Convert(aVert), aMargin); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TInt aBaselineOffset, TInt aTextWidth, TBool aUp, TTextAlign aVert, TInt aMargin) sl@0: { sl@0: iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aBaselineOffset, aTextWidth, aUp, MWsGraphicsContextToDirectGdiMappings::Convert(aVert), aMargin); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::MoveTo(const TPoint& aPoint) sl@0: { sl@0: iContext->MoveTo(aPoint); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::MoveBy(const TPoint& aVector) sl@0: { sl@0: iContext->MoveBy(aVector); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::Plot(const TPoint& aPoint) sl@0: { sl@0: iContext->Plot(aPoint); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::Reset() sl@0: { sl@0: iContext->Reset(); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetBrushColor(const TRgb& aColor) sl@0: { sl@0: iContext->SetBrushColor(aColor); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetBrushOrigin(const TPoint& aOrigin) sl@0: { sl@0: iContext->SetBrushOrigin(aOrigin); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetBrushStyle(TBrushStyle aBrushStyle) sl@0: { sl@0: iContext->SetBrushStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aBrushStyle)); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetClippingRegion(const TRegion& aRegion) sl@0: { sl@0: CDirectGdiDriver* driver = CDirectGdiDriver::Static(); sl@0: driver->GetError(); //make sure that an error has been received sl@0: iContext->SetClippingRegion(aRegion); sl@0: TInt err = driver->GetError(); sl@0: SetError(err); sl@0: if(err == KErrNone) sl@0: { sl@0: iClippingRegion.Copy(aRegion); sl@0: } sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetDrawMode(TDrawMode aDrawMode) sl@0: { sl@0: iContext->SetDrawMode(MWsGraphicsContextToDirectGdiMappings::LossyConvert(aDrawMode)); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetOrigin(const TPoint& aPoint) sl@0: { sl@0: iContext->SetOrigin(aPoint); sl@0: iOrigin = aPoint; sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetPenColor(const TRgb& aColor) sl@0: { sl@0: iContext->SetPenColor(aColor); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetPenStyle(TPenStyle aPenStyle) sl@0: { sl@0: iContext->SetPenStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aPenStyle)); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetPenSize(const TSize& aSize) sl@0: { sl@0: iContext->SetPenSize(aSize); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetTextShadowColor(const TRgb& aColor) sl@0: { sl@0: iContext->SetTextShadowColor(aColor); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetCharJustification(TInt aExcessWidth, TInt aNumChars) sl@0: { sl@0: iContext->SetCharJustification(aExcessWidth, aNumChars); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetWordJustification(TInt aExcessWidth, TInt aNumGaps) sl@0: { sl@0: iContext->SetWordJustification(aExcessWidth, aNumGaps); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetUnderlineStyle(TFontUnderline aUnderlineStyle) sl@0: { sl@0: iContext->SetUnderlineStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aUnderlineStyle)); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle) sl@0: { sl@0: iContext->SetStrikethroughStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aStrikethroughStyle)); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetBrushPattern(const CFbsBitmap& aBitmap) sl@0: { sl@0: iContext->SetBrushPattern(aBitmap); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetBrushPattern(TInt aFbsBitmapHandle) sl@0: { sl@0: iContext->SetBrushPattern(aFbsBitmapHandle); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetFont(const CFont* aFont) sl@0: { sl@0: iContext->SetFont(aFont); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::CopyRect(const TPoint& aOffset, const TRect& aRect) sl@0: { sl@0: iContext->CopyRect(aOffset, aRect); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::UpdateJustification(const TDesC& aText, const TTextParameters* aParam) sl@0: { sl@0: iContext->UpdateJustification(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam)); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::UpdateJustificationVertical(const TDesC& aText, const TTextParameters* aParam, TBool aUp) sl@0: { sl@0: iContext->UpdateJustificationVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aUp); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::SetFontNoDuplicate(const CFont* aFont) sl@0: { sl@0: iContext->SetFontNoDuplicate(static_cast(aFont)); sl@0: } sl@0: sl@0: TBool CDirectGdiGcWrapper::HasBrushPattern() const sl@0: { sl@0: return iContext->HasBrushPattern(); sl@0: } sl@0: sl@0: TBool CDirectGdiGcWrapper::HasFont() const sl@0: { sl@0: return iContext->HasFont(); sl@0: } sl@0: sl@0: TRgb CDirectGdiGcWrapper::BrushColor() const sl@0: { sl@0: return iContext->BrushColor(); sl@0: } sl@0: sl@0: TRgb CDirectGdiGcWrapper::PenColor() const sl@0: { sl@0: return iContext->PenColor(); sl@0: } sl@0: sl@0: TRgb CDirectGdiGcWrapper::TextShadowColor() const sl@0: { sl@0: return iContext->TextShadowColor(); sl@0: } sl@0: sl@0: TInt CDirectGdiGcWrapper::CreateDrawableSource(const TSgDrawableId& aDrawableId, TAny*& aSource) sl@0: { sl@0: CDirectGdiDriver* driver = CDirectGdiDriver::Static(); sl@0: if (!driver) sl@0: { sl@0: return KErrNotReady; sl@0: } sl@0: RDirectGdiDrawableSource* drawableSource = new RDirectGdiDrawableSource(*driver); sl@0: if (!drawableSource) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: //check usage flags if the drawable is an RSgImage sl@0: RSgImage image; sl@0: TInt res = image.Open(aDrawableId); sl@0: if (res == KErrNone) sl@0: { sl@0: TSgImageInfo info; sl@0: res = image.GetInfo(info); sl@0: image.Close(); sl@0: if (res == KErrNone && !(info.iUsage & ESgUsageWindowGcSource)) sl@0: { sl@0: res = KErrNotSupported; sl@0: } sl@0: sl@0: if (res != KErrNone) sl@0: { sl@0: delete drawableSource; sl@0: return res; sl@0: } sl@0: } sl@0: sl@0: RSgDrawable drawable; sl@0: res = drawable.Open(aDrawableId, ESgDoNotRestrictUsage); sl@0: if (res != KErrNone) sl@0: { sl@0: delete drawableSource; sl@0: return res; sl@0: } sl@0: res = drawableSource->Create(drawable); sl@0: drawable.Close(); sl@0: if (res != KErrNone) sl@0: { sl@0: delete drawableSource; sl@0: return res; sl@0: } sl@0: res = iDrawableSources.InsertInAddressOrder(drawableSource); sl@0: if (res != KErrNone) sl@0: { sl@0: drawableSource->Close(); sl@0: delete drawableSource; sl@0: return res; sl@0: } sl@0: aSource = drawableSource; sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::CloseDrawableSource(TAny* aSource) sl@0: { sl@0: RDirectGdiDrawableSource* drawableSource = static_cast(aSource); sl@0: TInt index = iDrawableSources.FindInAddressOrder(drawableSource); sl@0: if (index != KErrNotFound) sl@0: { sl@0: drawableSource->Close(); sl@0: delete drawableSource; sl@0: iDrawableSources.Remove(index); sl@0: } sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TPoint& aPos, CWindowGc::TGraphicsRotation aRotation) sl@0: { sl@0: const RDirectGdiDrawableSource* drawableSource = static_cast(aSource); sl@0: TInt index = iDrawableSources.FindInAddressOrder(drawableSource); sl@0: if (index == KErrNotFound) sl@0: { sl@0: STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource); sl@0: return; sl@0: } sl@0: iContext->DrawResource(aPos, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRect, CWindowGc::TGraphicsRotation aRotation) sl@0: { sl@0: const RDirectGdiDrawableSource* drawableSource = static_cast(aSource); sl@0: TInt index = iDrawableSources.FindInAddressOrder(drawableSource); sl@0: if (index == KErrNotFound) sl@0: { sl@0: STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource); sl@0: return; sl@0: } sl@0: iContext->DrawResource(aRect, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRectDest, const TRect& aRectSrc, CWindowGc::TGraphicsRotation aRotation) sl@0: { sl@0: const RDirectGdiDrawableSource* drawableSource = static_cast(aSource); sl@0: TInt index = iDrawableSources.FindInAddressOrder(drawableSource); sl@0: if (index == KErrNotFound) sl@0: { sl@0: STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource); sl@0: return; sl@0: } sl@0: iContext->DrawResource(aRectDest, *drawableSource, aRectSrc, (DirectGdi::TGraphicsRotation)aRotation); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRect, const TDesC8& aDes) sl@0: { sl@0: const RDirectGdiDrawableSource* drawableSource = static_cast(aSource); sl@0: TInt index = iDrawableSources.FindInAddressOrder(drawableSource); sl@0: if (index == KErrNotFound) sl@0: { sl@0: STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource); sl@0: return; sl@0: } sl@0: iContext->DrawResource(aRect, *drawableSource, aDes); sl@0: } sl@0: sl@0: /** sl@0: Sets the error code. If the error code is already set to a value other sl@0: than KErrNone, the error code will not be modified. sl@0: sl@0: @param aErr The error code to set. sl@0: sl@0: @post The error code has been set. sl@0: */ sl@0: void CDirectGdiGcWrapper::SetError(TInt aError) sl@0: { sl@0: if (aError != KErrNone && iErrorCode == KErrNone) sl@0: { sl@0: iErrorCode = aError; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Returns the first error code (set as the result of calling some CDirectGdiGcWrapper API), if any, sl@0: since the last call to this function or, if it has not previously been called, since sl@0: the CDirectGdiGcWrapper was constructed. Calling this function clears the error code. sl@0: sl@0: @post The error code has been reset after being read. sl@0: sl@0: @return The first error code, if any, since the last call to this function or, sl@0: if it has not previously been called, since the CDirectGdiGcWrapper was constructed. sl@0: KErrNone will indicate that no such error has occurred. sl@0: */ sl@0: TInt CDirectGdiGcWrapper::GetError() sl@0: { sl@0: TInt err = iErrorCode; sl@0: iErrorCode = KErrNone; sl@0: return err; sl@0: } sl@0: sl@0: TPoint CDirectGdiGcWrapper::Origin() const sl@0: { sl@0: return iOrigin; sl@0: } sl@0: sl@0: const TRegion& CDirectGdiGcWrapper::ClippingRegion() sl@0: { sl@0: return iClippingRegion; sl@0: } sl@0: sl@0: TInt CDirectGdiGcWrapper::Push() sl@0: { sl@0: // the buf format is len+data where data is written by the GC's ExternalizeL() sl@0: iGcBuf->Reset(); sl@0: CBufBase& buf = *iGcBuf; sl@0: const TInt start = buf.Size(); sl@0: RBufWriteStream out(buf,start); sl@0: TRAPD(err,out.WriteInt32L(0)); sl@0: if(!err) sl@0: { sl@0: TRAP(err,iContext->ExternalizeL(out)); sl@0: } sl@0: if(err) //rollback addition sl@0: { sl@0: buf.Delete(start,buf.Size()-start); sl@0: } sl@0: else //fixup len sl@0: { sl@0: TRAP_IGNORE(out.CommitL();) // can't see this failing sl@0: TPckgBuf pckg(buf.Size()-sizeof(TInt32)-start); sl@0: buf.Write(start,pckg); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::Pop() sl@0: { sl@0: CBufBase& buf = *iGcBuf; sl@0: TInt ofs = 0; sl@0: FOREVER sl@0: { sl@0: TInt chunk = 0; sl@0: RBufReadStream in(buf,ofs); sl@0: TRAPD(err,chunk = in.ReadInt32L()); sl@0: if(err) sl@0: { sl@0: STD_ASSERT_DEBUG(err != 0, EPluginPanicPopGcSettings); sl@0: return; sl@0: } sl@0: if(ofs+sizeof(TInt32)+chunk >= buf.Size()) // the last chunk? sl@0: { sl@0: TRAP_IGNORE(iContext->InternalizeL(in)); sl@0: buf.Delete(ofs,buf.Size()-ofs); sl@0: return; sl@0: } sl@0: ofs += chunk + sizeof(TInt32); sl@0: } sl@0: } sl@0: sl@0: //Default method of fading simply uses bitgdi to perform fading sl@0: void CDirectGdiGcWrapper::FadeArea(const TRegion& aRegion) sl@0: { sl@0: if (!&aRegion || aRegion.CheckError()) sl@0: return; sl@0: sl@0: iContext->Reset(); sl@0: iContext->SetClippingRegion(aRegion); sl@0: iContext->SetPenStyle(DirectGdi::ENullPen); sl@0: iContext->SetBrushStyle(DirectGdi::ESolidBrush); sl@0: iContext->SetBrushColor(iFadeColor); sl@0: iContext->DrawRect(aRegion.BoundingRect()); sl@0: } sl@0: sl@0: //Default method of fading expects two TUint8's describing the black/white map sl@0: //as possible fading parameters sl@0: void CDirectGdiGcWrapper::SetFadingParameters(const TDesC8& aData) sl@0: { sl@0: TPckgBuf buf; sl@0: buf.Copy(aData); sl@0: TFadingParams parameters = buf(); sl@0: sl@0: //Situations where blackMap > whiteMap are NOT supported sl@0: if (parameters.blackMap > parameters.whiteMap) sl@0: { sl@0: TUint8 oldMap = parameters.blackMap; sl@0: parameters.blackMap = parameters.whiteMap; sl@0: parameters.whiteMap = oldMap; sl@0: } sl@0: sl@0: //CFbsBitGc::FadeArea() does the following per color component: sl@0: // dst = dst * (whiteMap - blackMap) + blackMap; sl@0: sl@0: //To achieve the same effect using MWsGraphicsContext we draw a rectangle sl@0: //with specific intensity and alpha values: sl@0: // dst = dst * (1 - alpha) + intensity * alpha; sl@0: //Thus: sl@0: // alpha = 1 - whiteMap + blackMap; sl@0: // intensity = blackMap / alpha; sl@0: sl@0: // alpha = 1 - whiteMap + blackMap; sl@0: TInt alpha = 255 - parameters.whiteMap + parameters.blackMap; sl@0: // intensity = blackMap / alpha; sl@0: TInt i = (parameters.blackMap * iLut[alpha]) >> 8; sl@0: sl@0: iFadeColor.SetInternal(i << 16 | i << 8 | i | alpha << 24); sl@0: } sl@0: sl@0: void CDirectGdiGcWrapper::DrawTextCursor(const TTextCursorInfo& aTextCursorInfo) sl@0: { sl@0: /* sl@0: * This function is written with the following assumption: sl@0: * The UI Toolkit uses text entry windows with a white background sl@0: * and black text, but always requests a white text cursor. sl@0: * sl@0: * We therefore ignore the KRgbWhite text cursor cursor supplied sl@0: * and use a Black overprinting strategy instead. sl@0: */ sl@0: STD_ASSERT_ALWAYS( sl@0: aTextCursorInfo.iTextCursorType == TTextCursor::ETypeRectangle || sl@0: aTextCursorInfo.iTextCursorType == TTextCursor::ETypeHollowRectangle, sl@0: EPluginPanicInvalidCursorType sl@0: ); sl@0: sl@0: TRegionFix<1> fullWindowRegion; sl@0: const TRegion* clippingRegion = &aTextCursorInfo.iRegion; sl@0: if (aTextCursorInfo.iRegion.CheckError()) sl@0: { sl@0: fullWindowRegion.AddRect(aTextCursorInfo.iWindow->AbsRect()); sl@0: clippingRegion = &fullWindowRegion; sl@0: } sl@0: sl@0: if (clippingRegion->IsEmpty()) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: iContext->SetDrawMode(DirectGdi::EDrawModePEN); sl@0: switch (aTextCursorInfo.iTextCursorType) sl@0: { sl@0: case TTextCursor::ETypeRectangle: sl@0: { sl@0: iContext->SetBrushStyle(DirectGdi::ESolidBrush); sl@0: iContext->SetPenStyle(DirectGdi::ENullPen); sl@0: iContext->SetBrushColor(KRgbBlack); sl@0: } sl@0: break; sl@0: case TTextCursor::ETypeHollowRectangle: sl@0: { sl@0: iContext->SetBrushStyle(DirectGdi::ENullBrush); sl@0: iContext->SetPenStyle(DirectGdi::ESolidPen); sl@0: iContext->SetPenColor(KRgbBlack); sl@0: } sl@0: break; sl@0: } sl@0: iContext->SetClippingRegion(*clippingRegion); sl@0: /* sl@0: * During Sprite drawing, the GC gets reset. Possibly other code could sl@0: * have done this also. So make sure we setup the origin so that window-relative sl@0: * co-ordinates work as expected; iCursorRect is in window co-ordinates. sl@0: */ sl@0: iContext->SetOrigin(aTextCursorInfo.iWindow->Origin()); sl@0: iContext->DrawRect(aTextCursorInfo.iCursorRect); sl@0: }