1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/nga/SERVER/openwfc/gc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1586 @@
1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// GC and Graphics functions
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <s32mem.h>
1.23 +#include "gc.h"
1.24 +#include "backedupwindow.h"
1.25 +#include "windowgroup.h"
1.26 +#include "ScrDev.H"
1.27 +#include "wstop.h"
1.28 +#include "panics.h"
1.29 +#include "graphics/WSGRAPHICDRAWER.H"
1.30 +#include "wsfont.h"
1.31 +
1.32 +class TPlacedAttributes;
1.33 +
1.34 +CFbsBitmap *CWsGc::iScratchBitmap=NULL;
1.35 +CFbsBitmap *CWsGc::iScratchMaskBitmap=NULL;
1.36 +
1.37 +GLREF_C TInt ExternalizeRegionL(RWriteStream& aWriteStream, const RWsRegion& aRegion);
1.38 +
1.39 +/*CWsGc*/
1.40 +
1.41 +CWsGc* CWsGc::NewL(CWsClient *aOwner)
1.42 + {
1.43 + CWsGc* self = new(ELeave) CWsGc(aOwner);
1.44 + CleanupStack::PushL(self);
1.45 + self->ConstructL();
1.46 + CleanupStack::Pop(self);
1.47 + return self;
1.48 + }
1.49 +
1.50 +void CWsGc::InitStaticsL()
1.51 + {
1.52 + iScratchBitmap=new(ELeave) CFbsBitmap();
1.53 + iScratchMaskBitmap=new(ELeave) CFbsBitmap();
1.54 + }
1.55 +
1.56 +void CWsGc::DeleteStatics()
1.57 + {
1.58 + delete iScratchBitmap;
1.59 + delete iScratchMaskBitmap;
1.60 + }
1.61 +
1.62 +CWsGc::CWsGc(CWsClient *owner) : CWsObject(owner,WS_HANDLE_GC)
1.63 + {
1.64 + __DECLARE_NAME(_S("CWsGc"));
1.65 + }
1.66 +
1.67 +void CWsGc::ConstructL()
1.68 + {
1.69 + NewObjL();
1.70 + iBackedUpWinGc=CFbsBitGc::NewL();
1.71 + iInternalStatus.ResetInternalStatus(iWin);
1.72 + }
1.73 +
1.74 +void CWsGc::Activate(CWsClientWindow *win)
1.75 + {
1.76 + if (iWin!=NULL)
1.77 + {
1.78 + if (CWsClient::iCurrentCommand.iOpcode==0)
1.79 + {
1.80 + WS_PANIC_ALWAYS(EWsPanicDrawCommandsInvalidState);
1.81 + }
1.82 + else
1.83 + {
1.84 + OwnerPanic(EWservPanicGcActive);
1.85 + }
1.86 + }
1.87 +
1.88 + iWin = win;
1.89 + if (iWin->Redraw()->OutputDevice()) // Activated on a backed up window
1.90 + iBackedUpWinGc->ActivateNoJustAutoUpdate(iWin->Redraw()->OutputDevice());
1.91 + iWin->GcActivated(this);
1.92 + iInternalStatus.iBrushColor = iWin->BackColor();
1.93 + if (iWin->Redraw()->OutputDevice())
1.94 + iBackedUpWinGc->SetBrushColor(iInternalStatus.iBrushColor);
1.95 + iOrigin.SetXY(0,0);
1.96 + ResetClippingRect();
1.97 + if(iWsOwner)
1.98 + {
1.99 + CWsWindowGroup *winGp = iWin->WinGroup();
1.100 + if(!winGp->Device())
1.101 + OwnerPanic(EWservPanicGroupWinScreenDeviceDeleted);
1.102 + SetReply(winGp->Device()->ClientDevicePointer());
1.103 + }
1.104 + }
1.105 +
1.106 +void CWsGc::Activate(const TInt &aHandle)
1.107 + {
1.108 + CWsClientWindow *win;
1.109 + iWsOwner->HandleToClientWindow(aHandle,&win);
1.110 + if (!win->BaseParent())
1.111 + OwnerPanic(EWservPanicParentDeleted);
1.112 + Activate(win);
1.113 + }
1.114 +
1.115 +void CWsGc::Reactivate()
1.116 + {
1.117 + WS_ASSERT_DEBUG(iWin != NULL, EWsPanicDrawCommandsInvalidState);
1.118 + if (iWin->Redraw()->OutputDevice()) // Activated on a backed up window
1.119 + iBackedUpWinGc->ActivateNoJustAutoUpdate(iWin->Redraw()->OutputDevice());
1.120 + }
1.121 +
1.122 +CWsGc::~CWsGc()
1.123 + {
1.124 + if (iWin!=NULL)
1.125 + Deactivate();
1.126 + delete iBackedUpWinGc;
1.127 + delete iPolyPoints;
1.128 + }
1.129 +
1.130 +void CWsGc::Deactivate()
1.131 + {
1.132 + if (iWin) // Protect against deactivating an already deactivated GC, this is allowed to aid clean up code.
1.133 + {
1.134 + CWsFontCache::Instance()->ReleaseFont(iFont);
1.135 + iBackedUpWinGc->Reset();
1.136 + iInternalStatus.ResetInternalStatus(iWin);
1.137 + iWin->GcDeactivated(this);
1.138 + CancelClippingRegion();
1.139 + iWin->Redraw()->GcDeactivate(this);
1.140 + iWin=NULL;
1.141 + }
1.142 + }
1.143 +
1.144 +void CWsGc::SetClippingRect(const TRect &aRect)
1.145 + {
1.146 + iClippingRect=aRect;
1.147 + iClippingRect.Move(iOrigin);
1.148 + iClippingRectSet=ETrue;
1.149 + }
1.150 +
1.151 +void CWsGc::ResetClippingRect()
1.152 + {
1.153 + iClippingRectSet=EFalse;
1.154 + }
1.155 +
1.156 +void CWsGc::SetClippingRegionL(TInt aRegionCount)
1.157 + {
1.158 + RWsRegion *newRegion=GetRegionFromClientL(iWsOwner, aRegionCount);
1.159 + CancelClippingRegion();
1.160 + iUserDefinedClippingRegion=newRegion;
1.161 +
1.162 + if (iUserDefinedClippingRegion)
1.163 + {
1.164 + iUserDefinedClippingRegion->Offset(iOrigin);
1.165 + }
1.166 + }
1.167 +
1.168 +void CWsGc::CancelClippingRegion()
1.169 + {
1.170 + if (iUserDefinedClippingRegion)
1.171 + {
1.172 + iUserDefinedClippingRegion->Destroy();
1.173 + iUserDefinedClippingRegion=NULL;
1.174 + }
1.175 + }
1.176 +
1.177 +void CWsGc::CheckPolyData(const TAny* aDataPtr, TInt aHeaderSize, TInt aNumPoints)
1.178 + {
1.179 + TInt maxDataLen;
1.180 + if (CWsClient::iCurrentCommand.iOpcode>0)
1.181 + {
1.182 + maxDataLen=CWsClient::EndOfCommandBuffer()-static_cast<const TUint8*>(aDataPtr);
1.183 + }
1.184 + else // Playing back from redraw store??
1.185 + {
1.186 + maxDataLen=CWsClient::iCurrentCommand.iCmdLength;
1.187 + }
1.188 + const TInt dataSize=aHeaderSize+aNumPoints*sizeof(TPoint);
1.189 + if (dataSize>maxDataLen)
1.190 + GcOwnerPanic(EWservPanicBadPolyData);
1.191 + }
1.192 +
1.193 +void CWsGc::DoDrawPolygon(const TWsGcCmdDrawPolygon *aDrawPolygon)
1.194 + {
1.195 + CheckPolyData(aDrawPolygon,sizeof(TWsGcCmdDrawPolygon),aDrawPolygon->numPoints);
1.196 + iBackedUpWinGc->DrawPolygon((TPoint *)(aDrawPolygon+1),aDrawPolygon->numPoints,aDrawPolygon->fillRule);
1.197 + }
1.198 +
1.199 +void CWsGc::StartSegmentedDrawPolygonL(const TWsGcCmdStartSegmentedDrawPolygon* aDrawPolygon)
1.200 + {
1.201 + WS_ASSERT_DEBUG(iWin->Redraw()->OutputDevice(), EWsPanicWindowType);
1.202 + if (iPolyPoints || !Rng(0, aDrawPolygon->totalNumPoints, KMaxTInt/2 - 1)) // Restarting without finishing old polygon or invalid size
1.203 + GcOwnerPanic(EWservPanicBadPolyData);
1.204 + iPolyPoints=(TPoint *)User::AllocL(aDrawPolygon->totalNumPoints*sizeof(TPoint));
1.205 + iPolyPointListSize=aDrawPolygon->totalNumPoints;
1.206 + }
1.207 +
1.208 +void CWsGc::SegmentedDrawPolygonData(const TWsGcCmdSegmentedDrawPolygonData* aDrawPolygon)
1.209 + {
1.210 + WS_ASSERT_DEBUG(iWin->Redraw()->OutputDevice(), EWsPanicWindowType);
1.211 + if (aDrawPolygon->index<0 || (aDrawPolygon->index+aDrawPolygon->numPoints)>iPolyPointListSize)
1.212 + GcOwnerPanic(EWservPanicBadPolyData);
1.213 + Mem::Copy(iPolyPoints+aDrawPolygon->index,aDrawPolygon+1,aDrawPolygon->numPoints*sizeof(TPoint));
1.214 + }
1.215 +
1.216 +void CWsGc::EndSegmentedPolygon()
1.217 + {
1.218 + delete iPolyPoints;
1.219 + iPolyPoints=NULL;
1.220 + iPolyPointListSize = 0;
1.221 + }
1.222 +
1.223 +void CWsGc::DoDrawPolyLine(const TWsGcCmdDrawPolyLine *aDrawPolyLine, TBool aContinued)
1.224 + {
1.225 + TInt numPoints=aDrawPolyLine->numPoints;
1.226 + CheckPolyData(aDrawPolyLine,sizeof(TWsGcCmdDrawPolyLine),numPoints);
1.227 + const TPoint *points=(TPoint *)(aDrawPolyLine+1);
1.228 + if (aContinued)
1.229 + {
1.230 + numPoints++;
1.231 + points=&aDrawPolyLine->last;
1.232 + }
1.233 + if (aDrawPolyLine->more) // more to come so don't draw the end point
1.234 + iBackedUpWinGc->DrawPolyLineNoEndPoint(points,numPoints);
1.235 + else
1.236 + iBackedUpWinGc->DrawPolyLine(points,numPoints);
1.237 + }
1.238 +
1.239 +void CWsGc::GcOwnerPanic(TClientPanic aPanic)
1.240 + {
1.241 + iBackedUpWinGc->SetClippingRegion(NULL);
1.242 + EndSegmentedPolygon();
1.243 + iWin->WsOwner()->PPanic(aPanic);
1.244 + }
1.245 +
1.246 +TPtrC CWsGc::BufferTPtr(TText* aStart,TInt aLen)
1.247 + {
1.248 + TPtrC gcPtr;
1.249 + if (!CWsClient::BufferTPtrGc(aStart,aLen,gcPtr))
1.250 + GcOwnerPanic(EWservPanicBufferPtr);
1.251 + return(gcPtr);
1.252 + }
1.253 +
1.254 +void CWsGc::DoDrawCommand(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
1.255 + {
1.256 + WS_ASSERT_DEBUG(iWin,EWsPanicWindowNull);
1.257 + WS_ASSERT_DEBUG(iWin->Redraw()->OutputDevice(), EWsPanicWindowType); // Must be activated on a backed up window
1.258 +
1.259 + if (iUserDefinedClippingRegion)
1.260 + {
1.261 + if (iUserDefinedClippingRegion->Count()==0)
1.262 + return;
1.263 + if (iUserDefinedClippingRegion->IsContainedBy(TRect(TPoint(0,0), iBackedUpWinGc->Device()->SizeInPixels())))
1.264 + {
1.265 + iBackedUpWinGc->SetClippingRegion(iUserDefinedClippingRegion);
1.266 + }
1.267 + }
1.268 + CGraphicsContext::TTextParameters contextParam;
1.269 + switch(aOpcode)
1.270 + {
1.271 + case EWsGcOpDrawWsGraphic:
1.272 + case EWsGcOpDrawWsGraphicPtr:
1.273 + {
1.274 + // CWsGc doesn't support CRPs. CPlaybackGc does. This means backedup windows
1.275 + // don't get to play with them yet.
1.276 + break;
1.277 + }
1.278 + case EWsGcOpMapColorsLocal:
1.279 + GcOwnerPanic(EWservPanicOpcode); //deprecated, the client should never generate this op
1.280 + break;
1.281 + case EWsGcOpDrawPolyLineLocalBufLen:
1.282 + iBackedUpWinGc->DrawPolyLine(pData.DrawPolyLineLocalBufLen->points,pData.DrawPolyLineLocalBufLen->length);
1.283 + break;
1.284 + case EWsGcOpDrawPolyLineLocal:
1.285 + iBackedUpWinGc->DrawPolyLine(pData.PointList);
1.286 + break;
1.287 + case EWsGcOpDrawPolygonLocalBufLen:
1.288 + iBackedUpWinGc->DrawPolygon(pData.DrawPolygonLocalBufLen->points,pData.DrawPolygonLocalBufLen->length,pData.DrawPolygonLocalBufLen->fillRule);
1.289 + break;
1.290 + case EWsGcOpDrawPolygonLocal:
1.291 + iBackedUpWinGc->DrawPolygon(pData.DrawPolygonLocal->pointList,pData.DrawPolygonLocal->fillRule);
1.292 + break;
1.293 + case EWsGcOpDrawBitmapLocal:
1.294 + iBackedUpWinGc->DrawBitmap(pData.BitmapLocal->pos, pData.BitmapLocal->bitmap);
1.295 + break;
1.296 + case EWsGcOpDrawBitmap2Local:
1.297 + iBackedUpWinGc->DrawBitmap(pData.Bitmap2Local->rect, pData.Bitmap2Local->bitmap);
1.298 + break;
1.299 + case EWsGcOpDrawBitmap3Local:
1.300 + iBackedUpWinGc->DrawBitmap(pData.Bitmap3Local->rect, pData.Bitmap3Local->bitmap, pData.Bitmap3Local->srcRect);
1.301 + break;
1.302 + case EWsGcOpDrawBitmapMaskedLocal:
1.303 + iBackedUpWinGc->DrawBitmapMasked(pData.iBitmapMaskedLocal->iRect, pData.iBitmapMaskedLocal->iBitmap, pData.iBitmapMaskedLocal->iSrcRect, pData.iBitmapMaskedLocal->iMaskBitmap,pData.iBitmapMaskedLocal->iInvertMask);
1.304 + break;
1.305 + case EWsGcOpAlphaBlendBitmapsLocal:
1.306 + iBackedUpWinGc->AlphaBlendBitmaps(pData.AlphaBlendBitmapsLocal->point,pData.AlphaBlendBitmapsLocal->iBitmap,
1.307 + pData.AlphaBlendBitmapsLocal->source, pData.AlphaBlendBitmapsLocal->iAlpha,
1.308 + pData.AlphaBlendBitmapsLocal->alphaPoint);
1.309 +
1.310 + break;
1.311 + case EWsGcOpDrawText:
1.312 + iBackedUpWinGc->DrawText(BufferTPtr((TText *)(pData.DrawText+1),pData.DrawText->length),pData.DrawText->pos);
1.313 + break;
1.314 + case EWsGcOpDrawBoxTextOptimised1:
1.315 + iBackedUpWinGc->DrawText(BufferTPtr((TText *)(pData.BoxTextO1+1),pData.BoxTextO1->length),pData.BoxTextO1->box,
1.316 + pData.BoxTextO1->baselineOffset,CGraphicsContext::ELeft,0);
1.317 + break;
1.318 + case EWsGcOpDrawBoxTextOptimised2:
1.319 + iBackedUpWinGc->DrawText(BufferTPtr((TText *)(pData.BoxTextO2+1),pData.BoxTextO2->length),pData.BoxTextO2->box,
1.320 + pData.BoxTextO2->baselineOffset,pData.BoxTextO2->horiz,pData.BoxTextO2->leftMrg);
1.321 + break;
1.322 + case EWsGcOpDrawTextPtr:
1.323 + iBackedUpWinGc->DrawText(*pData.DrawTextPtr->text,pData.DrawTextPtr->pos);
1.324 + break;
1.325 + case EWsGcOpDrawTextPtr1:
1.326 + iBackedUpWinGc->DrawText(*pData.DrawTextPtr->text);
1.327 + break;
1.328 + case EWsGcOpDrawBoxText:
1.329 + iBackedUpWinGc->DrawText(BufferTPtr((TText *)(pData.BoxText+1),pData.BoxText->length),pData.BoxText->box,pData.BoxText->baselineOffset,pData.BoxText->width,pData.BoxText->horiz,pData.BoxText->leftMrg);
1.330 + break;
1.331 + case EWsGcOpDrawBoxTextPtr:
1.332 + iBackedUpWinGc->DrawText(*pData.DrawBoxTextPtr->text,pData.DrawBoxTextPtr->box,pData.DrawBoxTextPtr->baselineOffset,pData.DrawBoxTextPtr->width,pData.DrawBoxTextPtr->horiz,pData.DrawBoxTextPtr->leftMrg);
1.333 + break;
1.334 + case EWsGcOpDrawBoxTextPtr1:
1.335 + iBackedUpWinGc->DrawText(*pData.DrawBoxTextPtr->text,pData.DrawBoxTextPtr->box);
1.336 + break;
1.337 + case EWsGcOpDrawTextVertical:
1.338 + iBackedUpWinGc->DrawTextVertical(BufferTPtr((TText *)(pData.DrawTextVertical+1),pData.DrawTextVertical->length),pData.DrawTextVertical->pos
1.339 + ,pData.DrawTextVertical->up);
1.340 + break;
1.341 + case EWsGcOpDrawTextVerticalPtr:
1.342 + iBackedUpWinGc->DrawTextVertical(*pData.DrawTextVerticalPtr->text,pData.DrawTextVerticalPtr->pos,pData.DrawTextVerticalPtr->up);
1.343 + break;
1.344 + case EWsGcOpDrawTextVerticalPtr1:
1.345 + iBackedUpWinGc->DrawTextVertical(*pData.DrawTextVerticalPtr->text,pData.DrawTextVerticalPtr->up);
1.346 + break;
1.347 + case EWsGcOpDrawBoxTextVertical:
1.348 + iBackedUpWinGc->DrawTextVertical(BufferTPtr((TText *)(pData.DrawBoxTextVertical+1),pData.DrawBoxTextVertical->length),
1.349 + pData.DrawBoxTextVertical->box, pData.DrawBoxTextVertical->baselineOffset,
1.350 + pData.DrawBoxTextVertical->up,(CGraphicsContext::TTextAlign)pData.DrawBoxTextVertical->vert,pData.DrawBoxTextVertical->margin);
1.351 + break;
1.352 + case EWsGcOpDrawBoxTextVerticalPtr:
1.353 + iBackedUpWinGc->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->baselineOffset
1.354 + ,pData.DrawBoxTextVerticalPtr->width,pData.DrawBoxTextVerticalPtr->up,pData.DrawBoxTextVerticalPtr->vert,pData.DrawBoxTextVerticalPtr->margin);
1.355 + break;
1.356 + case EWsGcOpDrawBoxTextVerticalPtr1:
1.357 + iBackedUpWinGc->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->up);
1.358 + break;
1.359 + case EWsGcOpDrawTextLocal:
1.360 + iBackedUpWinGc->DrawText(*pData.DrawTextLocal->desc,pData.DrawTextLocal->pos);
1.361 + break;
1.362 + case EWsGcOpDrawBoxTextLocal:
1.363 + iBackedUpWinGc->DrawText(*pData.BoxTextLocal->desc,pData.BoxTextLocal->box,pData.BoxTextLocal->baselineOffset,
1.364 + pData.BoxTextLocal->horiz,pData.BoxTextLocal->leftMrg);
1.365 + break;
1.366 + /************* DrawText in Context function calls*********************************************/
1.367 + case EWsGcOpDrawTextInContext:
1.368 + contextParam.iStart = pData.DrawTextInContext->start;
1.369 + contextParam.iEnd = pData.DrawTextInContext->end;
1.370 + if(contextParam.iStart < contextParam.iEnd)
1.371 + {
1.372 + iBackedUpWinGc->DrawText(BufferTPtr((TText *)(pData.DrawTextInContext+1),pData.DrawTextInContext->length),&contextParam,pData.DrawTextInContext->pos);
1.373 + }
1.374 + else
1.375 + {
1.376 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.377 + }
1.378 + break;
1.379 + case EWsGcOpDrawBoxTextInContextOptimised1:
1.380 + contextParam.iStart = pData.BoxTextInContextO1->start;
1.381 + contextParam.iEnd = pData.BoxTextInContextO1->end;
1.382 + if(contextParam.iStart < contextParam.iEnd)
1.383 + {
1.384 + iBackedUpWinGc->DrawText(BufferTPtr((TText *)(pData.BoxTextInContextO1+1),pData.BoxTextInContextO1->length),&contextParam,pData.BoxTextInContextO1->box,
1.385 + pData.BoxTextInContextO1->baselineOffset,CGraphicsContext::ELeft,0);
1.386 + }
1.387 + else
1.388 + {
1.389 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.390 + }
1.391 + break;
1.392 + case EWsGcOpDrawBoxTextInContextOptimised2:
1.393 + contextParam.iStart = pData.BoxTextInContextO2->start;
1.394 + contextParam.iEnd = pData.BoxTextInContextO2->end;
1.395 + if(contextParam.iStart < contextParam.iEnd)
1.396 + {
1.397 + iBackedUpWinGc->DrawText(BufferTPtr((TText *)(pData.BoxTextInContextO2+1),pData.BoxTextInContextO2->length),&contextParam,pData.BoxTextInContextO2->box,
1.398 + pData.BoxTextInContextO2->baselineOffset,pData.BoxTextInContextO2->horiz,pData.BoxTextInContextO2->leftMrg);
1.399 + }
1.400 + else
1.401 + {
1.402 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.403 + }
1.404 + break;
1.405 + case EWsGcOpDrawTextInContextPtr:
1.406 + contextParam.iStart = pData.DrawTextInContextPtr->start;
1.407 + contextParam.iEnd = pData.DrawTextInContextPtr->end;
1.408 + if(contextParam.iStart < contextParam.iEnd)
1.409 + {
1.410 + iBackedUpWinGc->DrawText(*pData.DrawTextInContextPtr->text,&contextParam,pData.DrawTextInContextPtr->pos);
1.411 + }
1.412 + else
1.413 + {
1.414 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.415 + }
1.416 + break;
1.417 + case EWsGcOpDrawTextInContextPtr1:
1.418 + contextParam.iStart = pData.DrawTextInContextPtr->start;
1.419 + contextParam.iEnd = pData.DrawTextInContextPtr->end;
1.420 + if(contextParam.iStart < contextParam.iEnd)
1.421 + {
1.422 + iBackedUpWinGc->DrawText(*pData.DrawTextInContextPtr->text,&contextParam);
1.423 + }
1.424 + else
1.425 + {
1.426 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.427 + }
1.428 + break;
1.429 + case EWsGcOpDrawBoxTextInContext:
1.430 + contextParam.iStart = pData.BoxTextInContext->start;
1.431 + contextParam.iEnd = pData.BoxTextInContext->end;
1.432 + if(contextParam.iStart < contextParam.iEnd)
1.433 + {
1.434 + iBackedUpWinGc->DrawText(BufferTPtr((TText *)(pData.BoxTextInContext+1),pData.BoxTextInContext->length),&contextParam,
1.435 + pData.BoxTextInContext->box,pData.BoxTextInContext->baselineOffset,pData.BoxTextInContext->width,pData.BoxTextInContext->horiz,pData.BoxTextInContext->leftMrg);
1.436 + }
1.437 + else
1.438 + {
1.439 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.440 + }
1.441 + break;
1.442 + case EWsGcOpDrawBoxTextInContextPtr:
1.443 + contextParam.iStart = pData.DrawBoxTextInContextPtr->start;
1.444 + contextParam.iEnd = pData.DrawBoxTextInContextPtr->end;
1.445 + if(contextParam.iStart < contextParam.iEnd)
1.446 + {
1.447 + iBackedUpWinGc->DrawText(*pData.DrawBoxTextInContextPtr->text,&contextParam,pData.DrawBoxTextInContextPtr->box,pData.DrawBoxTextInContextPtr->baselineOffset,pData.DrawBoxTextInContextPtr->width,pData.DrawBoxTextInContextPtr->horiz,pData.DrawBoxTextInContextPtr->leftMrg);
1.448 + }
1.449 + else
1.450 + {
1.451 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.452 + }
1.453 + break;
1.454 + case EWsGcOpDrawBoxTextInContextPtr1:
1.455 + contextParam.iStart = pData.DrawBoxTextInContextPtr->start;
1.456 + contextParam.iEnd = pData.DrawBoxTextInContextPtr->end;
1.457 + if(contextParam.iStart < contextParam.iEnd)
1.458 + {
1.459 + iBackedUpWinGc->DrawText(*pData.DrawBoxTextInContextPtr->text,&contextParam,pData.DrawBoxTextInContextPtr->box);
1.460 + }
1.461 + else
1.462 + {
1.463 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.464 + }
1.465 + break;
1.466 + case EWsGcOpDrawTextInContextVertical:
1.467 + contextParam.iStart = pData.DrawTextInContextVertical->start;
1.468 + contextParam.iEnd = pData.DrawTextInContextVertical->end;
1.469 + if(contextParam.iStart < contextParam.iEnd)
1.470 + {
1.471 + iBackedUpWinGc->DrawTextVertical(BufferTPtr((TText *)(pData.DrawTextInContextVertical+1),pData.DrawTextInContextVertical->length),&contextParam,pData.DrawTextInContextVertical->pos
1.472 + ,pData.DrawTextInContextVertical->up);
1.473 + }
1.474 + else
1.475 + {
1.476 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.477 + }
1.478 + break;
1.479 + case EWsGcOpDrawTextInContextVerticalPtr:
1.480 + contextParam.iStart = pData.DrawTextInContextVerticalPtr->start;
1.481 + contextParam.iEnd = pData.DrawTextInContextVerticalPtr->end;
1.482 + if(contextParam.iStart < contextParam.iEnd)
1.483 + {
1.484 + iBackedUpWinGc->DrawTextVertical(*pData.DrawTextInContextVerticalPtr->text,&contextParam,pData.DrawTextInContextVerticalPtr->pos,pData.DrawTextInContextVerticalPtr->up);
1.485 + }
1.486 + else
1.487 + {
1.488 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.489 + }
1.490 + break;
1.491 + case EWsGcOpDrawTextInContextVerticalPtr1:
1.492 + contextParam.iStart = pData.DrawTextInContextVerticalPtr->start;
1.493 + contextParam.iEnd = pData.DrawTextInContextVerticalPtr->end;
1.494 + if(contextParam.iStart < contextParam.iEnd)
1.495 + {
1.496 + iBackedUpWinGc->DrawTextVertical(*pData.DrawTextInContextVerticalPtr->text,&contextParam,pData.DrawTextInContextVerticalPtr->up);
1.497 + }
1.498 + else
1.499 + {
1.500 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.501 + }
1.502 + break;
1.503 + case EWsGcOpDrawBoxTextInContextVertical:
1.504 + contextParam.iStart = pData.DrawBoxTextInContextVertical->start;
1.505 + contextParam.iEnd = pData.DrawBoxTextInContextVertical->end;
1.506 + if(contextParam.iStart < contextParam.iEnd)
1.507 + {
1.508 + iBackedUpWinGc->DrawTextVertical(BufferTPtr((TText *)(pData.DrawBoxTextInContextVertical+1),pData.DrawBoxTextInContextVertical->length),&contextParam,
1.509 + pData.DrawBoxTextInContextVertical->box,pData.DrawBoxTextInContextVertical->baselineOffset,
1.510 + pData.DrawBoxTextInContextVertical->up,(CGraphicsContext::TTextAlign)pData.DrawBoxTextInContextVertical->vert,pData.DrawBoxTextInContextVertical->margin);
1.511 + }
1.512 + else
1.513 + {
1.514 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.515 + }
1.516 + break;
1.517 + case EWsGcOpDrawBoxTextInContextVerticalPtr:
1.518 + contextParam.iStart = pData.DrawBoxTextInContextVerticalPtr->start;
1.519 + contextParam.iEnd = pData.DrawBoxTextInContextVerticalPtr->end;
1.520 + if(contextParam.iStart < contextParam.iEnd)
1.521 + {
1.522 + iBackedUpWinGc->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,&contextParam,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->baselineOffset
1.523 + ,pData.DrawBoxTextVerticalPtr->width,pData.DrawBoxTextVerticalPtr->up,pData.DrawBoxTextVerticalPtr->vert,pData.DrawBoxTextVerticalPtr->margin);
1.524 + }
1.525 + else
1.526 + {
1.527 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.528 + }
1.529 + break;
1.530 + case EWsGcOpDrawBoxTextInContextVerticalPtr1:
1.531 + contextParam.iStart = pData.DrawBoxTextInContextVerticalPtr->start;
1.532 + contextParam.iEnd = pData.DrawBoxTextInContextVerticalPtr->end;
1.533 + if(contextParam.iStart < contextParam.iEnd)
1.534 + {
1.535 + iBackedUpWinGc->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,&contextParam,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->up);
1.536 + }
1.537 + else
1.538 + {
1.539 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.540 + }
1.541 + break;
1.542 + case EWsGcOpDrawTextInContextLocal:
1.543 + contextParam.iStart = pData.DrawTextInContextLocal->start;
1.544 + contextParam.iEnd = pData.DrawTextInContextLocal->end;
1.545 + if(contextParam.iStart < contextParam.iEnd)
1.546 + {
1.547 + iBackedUpWinGc->DrawText(*pData.DrawTextInContextLocal->desc,&contextParam,pData.DrawTextInContextLocal->pos);
1.548 + }
1.549 + else
1.550 + {
1.551 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.552 + }
1.553 + break;
1.554 + case EWsGcOpDrawBoxTextInContextLocal:
1.555 + contextParam.iStart = pData.BoxTextInContextLocal->start;
1.556 + contextParam.iEnd = pData.BoxTextInContextLocal->end;
1.557 + if(contextParam.iStart < contextParam.iEnd)
1.558 + {
1.559 + iBackedUpWinGc->DrawText(*pData.BoxTextInContextLocal->desc,pData.BoxTextInContextLocal->box,pData.BoxTextInContextLocal->baselineOffset,
1.560 + pData.BoxTextInContextLocal->horiz,pData.BoxTextInContextLocal->leftMrg);
1.561 + }
1.562 + else
1.563 + {
1.564 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.565 + }
1.566 + break;
1.567 + case EWsGcOpDrawLine:
1.568 + iBackedUpWinGc->DrawLine(pData.DrawLine->pnt1,pData.DrawLine->pnt2);
1.569 + break;
1.570 + case EWsGcOpDrawTo:
1.571 + iBackedUpWinGc->DrawLine(iLinePos,*pData.Point);
1.572 + break;
1.573 + case EWsGcOpDrawBy:
1.574 + iBackedUpWinGc->DrawLine(iLinePos,iLinePos+(*pData.Point));
1.575 + break;
1.576 + case EWsGcOpPlot:
1.577 + iBackedUpWinGc->Plot(*pData.Point);
1.578 + break;
1.579 + case EWsGcOpMoveTo:
1.580 + case EWsGcOpMoveBy:
1.581 + break;
1.582 + case EWsGcOpGdiBlt2Local:
1.583 + iBackedUpWinGc->BitBlt(pData.GdiBlt2Local->pos,pData.GdiBlt2Local->bitmap);
1.584 + break;
1.585 + case EWsGcOpGdiBlt3Local:
1.586 + iBackedUpWinGc->BitBlt(pData.GdiBlt3Local->pos,pData.GdiBlt3Local->bitmap, pData.GdiBlt3Local->rect);
1.587 + break;
1.588 + case EWsGcOpGdiBltMaskedLocal:
1.589 + iBackedUpWinGc->BitBltMasked(pData.GdiBltMaskedLocal->pos,pData.GdiBltMaskedLocal->bitmap,
1.590 + pData.GdiBltMaskedLocal->rect,pData.GdiBltMaskedLocal->maskBitmap,
1.591 + pData.GdiBltMaskedLocal->invertMask);
1.592 + break;
1.593 + case EWsGcOpGdiWsBlt2:
1.594 + case EWsGcOpGdiWsBlt3:
1.595 + case EWsGcOpGdiWsBltMasked:
1.596 + case EWsGcOpGdiWsAlphaBlendBitmaps:
1.597 + case EWsGcOpWsDrawBitmapMasked:
1.598 + {
1.599 + CFbsBitmap* scratchBimap=iScratchBitmap;
1.600 + CFbsBitmap* scratchMaskBimap=iScratchMaskBitmap;
1.601 + TInt maskHandle=0;
1.602 + TInt handle=WsBitmapHandle(aOpcode,pData, maskHandle);
1.603 + CWsClient* owner=iWin->WsOwner(); // We can't just use iWsOwner - it can be null for stored commands
1.604 + if (owner!=NULL)
1.605 + {
1.606 + DWsBitmap *bitmap=(DWsBitmap *)owner->HandleToObj(handle, WS_HANDLE_BITMAP);
1.607 + if (!bitmap)
1.608 + GcOwnerPanic(EWservPanicBitmap);
1.609 + scratchBimap=bitmap->FbsBitmap();
1.610 + if (aOpcode==EWsGcOpGdiWsBltMasked || aOpcode==EWsGcOpGdiWsAlphaBlendBitmaps || aOpcode==EWsGcOpWsDrawBitmapMasked)
1.611 + {
1.612 + DWsBitmap *bitmap2=(DWsBitmap *)owner->HandleToObj(maskHandle, WS_HANDLE_BITMAP);
1.613 + if (!bitmap2)
1.614 + GcOwnerPanic(EWservPanicBitmap);
1.615 + scratchMaskBimap=bitmap2->FbsBitmap();
1.616 + }
1.617 + }
1.618 + else
1.619 + {
1.620 + GcOwnerPanic(EWservPanicBitmap);
1.621 + }
1.622 + switch(aOpcode)
1.623 + {
1.624 + case EWsGcOpGdiWsBlt2:
1.625 + iBackedUpWinGc->BitBlt(pData.GdiBlt2->pos,scratchBimap);
1.626 + break;
1.627 + case EWsGcOpGdiWsBlt3:
1.628 + iBackedUpWinGc->BitBlt(pData.GdiBlt3->pos,scratchBimap, pData.GdiBlt3->rect);
1.629 + break;
1.630 + case EWsGcOpGdiWsBltMasked:
1.631 + {
1.632 + iBackedUpWinGc->BitBltMasked(pData.GdiBltMasked->destination,scratchBimap,
1.633 + pData.GdiBltMasked->source, scratchMaskBimap,
1.634 + pData.GdiBltMasked->invertMask);
1.635 + }
1.636 + break;
1.637 + case EWsGcOpGdiWsAlphaBlendBitmaps:
1.638 + {
1.639 + iBackedUpWinGc->AlphaBlendBitmaps(pData.AlphaBlendBitmaps->point,scratchBimap,
1.640 + pData.AlphaBlendBitmaps->source, scratchMaskBimap,
1.641 + pData.AlphaBlendBitmaps->alphaPoint);
1.642 + }
1.643 + break;
1.644 + case EWsGcOpWsDrawBitmapMasked:
1.645 + {
1.646 + iBackedUpWinGc->DrawBitmapMasked(pData.iBitmapMasked->iRect,scratchBimap,
1.647 + pData.iBitmapMasked->iSrcRect,scratchMaskBimap,
1.648 + pData.iBitmapMasked->iInvertMask);
1.649 + }
1.650 + break;
1.651 + }
1.652 + break;
1.653 + }
1.654 + case EWsGcOpGdiBlt2:
1.655 + case EWsGcOpGdiBlt3:
1.656 + case EWsGcOpGdiBltMasked:
1.657 + case EWsGcOpGdiAlphaBlendBitmaps:
1.658 + case EWsGcOpDrawBitmap:
1.659 + case EWsGcOpDrawBitmap2:
1.660 + case EWsGcOpDrawBitmap3:
1.661 + case EWsGcOpDrawBitmapMasked:
1.662 + {
1.663 + TInt maskHandle=0;
1.664 + TInt ret = iScratchBitmap->Duplicate(FbsBitmapHandle(aOpcode, pData,maskHandle));
1.665 + if(ret == KErrNoMemory)
1.666 + break;
1.667 + if (ret !=KErrNone)
1.668 + GcOwnerPanic(EWservPanicBitmap);
1.669 +
1.670 + switch(aOpcode)
1.671 + {
1.672 + case EWsGcOpGdiBlt2:
1.673 + iBackedUpWinGc->BitBlt(pData.GdiBlt2->pos,iScratchBitmap);
1.674 + break;
1.675 + case EWsGcOpGdiBlt3:
1.676 + iBackedUpWinGc->BitBlt(pData.GdiBlt3->pos,iScratchBitmap, pData.GdiBlt3->rect);
1.677 + break;
1.678 + case EWsGcOpGdiBltMasked:
1.679 + {
1.680 + TInt ret = iScratchMaskBitmap->Duplicate(pData.GdiBltMasked->maskHandle);
1.681 + if(ret == KErrNoMemory)
1.682 + break;
1.683 + if (ret !=KErrNone)
1.684 + GcOwnerPanic(EWservPanicBitmap);
1.685 +
1.686 + iBackedUpWinGc->BitBltMasked(pData.GdiBltMasked->destination,iScratchBitmap,
1.687 + pData.GdiBltMasked->source, iScratchMaskBitmap,
1.688 + pData.GdiBltMasked->invertMask);
1.689 + iScratchMaskBitmap->Reset();
1.690 + }
1.691 + break;
1.692 + case EWsGcOpGdiAlphaBlendBitmaps:
1.693 + {
1.694 + TInt ret = iScratchMaskBitmap->Duplicate(pData.AlphaBlendBitmaps->alphaHandle);
1.695 + if (ret == KErrNoMemory)
1.696 + break;
1.697 + if (ret != KErrNone)
1.698 + GcOwnerPanic(EWservPanicBitmap);
1.699 +
1.700 + iBackedUpWinGc->AlphaBlendBitmaps(pData.AlphaBlendBitmaps->point, iScratchBitmap,
1.701 + pData.AlphaBlendBitmaps->source, iScratchMaskBitmap,
1.702 + pData.AlphaBlendBitmaps->alphaPoint);
1.703 + iScratchMaskBitmap->Reset();
1.704 + break;
1.705 + }
1.706 + case EWsGcOpDrawBitmap:
1.707 + iBackedUpWinGc->DrawBitmap(pData.Bitmap->pos, iScratchBitmap);
1.708 + break;
1.709 + case EWsGcOpDrawBitmap2:
1.710 + iBackedUpWinGc->DrawBitmap(pData.Bitmap2->rect, iScratchBitmap);
1.711 + break;
1.712 + case EWsGcOpDrawBitmap3:
1.713 + iBackedUpWinGc->DrawBitmap(pData.Bitmap3->rect, iScratchBitmap, pData.Bitmap3->srcRect);
1.714 + break;
1.715 + case EWsGcOpDrawBitmapMasked:
1.716 + {
1.717 + TInt ret = iScratchMaskBitmap->Duplicate(pData.iBitmapMasked->iMaskHandle);
1.718 + if (ret == KErrNoMemory)
1.719 + break;
1.720 + if (ret != KErrNone)
1.721 + GcOwnerPanic(EWservPanicBitmap);
1.722 +
1.723 + iBackedUpWinGc->DrawBitmapMasked(pData.iBitmapMasked->iRect, iScratchBitmap,
1.724 + pData.iBitmapMasked->iSrcRect, iScratchMaskBitmap,
1.725 + pData.iBitmapMasked->iInvertMask);
1.726 + iScratchMaskBitmap->Reset();
1.727 + }
1.728 + break;
1.729 + }
1.730 + iScratchBitmap->Reset();
1.731 + break;
1.732 + }
1.733 + case EWsGcOpDrawSegmentedPolygon:
1.734 + iBackedUpWinGc->DrawPolygon(iPolyPoints,iPolyPointListSize,pData.DrawSegmentedPolygon->fillRule);
1.735 + break;
1.736 + case EWsGcOpDrawPolygon:
1.737 + DoDrawPolygon(pData.Polygon);
1.738 + break;
1.739 + case EWsGcOpDrawPolyLine:
1.740 + DoDrawPolyLine(pData.PolyLine, EFalse);
1.741 + break;
1.742 + case EWsGcOpDrawPolyLineContinued:
1.743 + DoDrawPolyLine(pData.PolyLine, ETrue);
1.744 + break;
1.745 + case EWsGcOpClear:
1.746 + iBackedUpWinGc->Clear(TRect(iWin->Size()));
1.747 + break;
1.748 + case EWsGcOpClearRect:
1.749 + iBackedUpWinGc->Clear(*pData.Rect);
1.750 + break;
1.751 + case EWsGcOpDrawRect:
1.752 + iBackedUpWinGc->DrawRect(*pData.Rect);
1.753 + break;
1.754 + case EWsGcOpDrawEllipse:
1.755 + iBackedUpWinGc->DrawEllipse(*pData.Rect);
1.756 + break;
1.757 + case EWsGcOpDrawRoundRect:
1.758 + iBackedUpWinGc->DrawRoundRect(*pData.Rect,pData.RoundRect->ellipse);
1.759 + break;
1.760 + case EWsGcOpDrawArc:
1.761 + iBackedUpWinGc->DrawArc(*pData.Rect,pData.ArcOrPie->start,pData.ArcOrPie->end);
1.762 + break;
1.763 + case EWsGcOpDrawPie:
1.764 + iBackedUpWinGc->DrawPie(*pData.Rect,pData.ArcOrPie->start,pData.ArcOrPie->end);
1.765 + break;
1.766 + case EWsGcOpCopyRect:
1.767 + iBackedUpWinGc->CopyRect(pData.CopyRect->pos,*pData.Rect);
1.768 + break;
1.769 + case EWsGcOpMapColors:
1.770 + GcOwnerPanic(EWservPanicOpcode); //deprecated, the client should never generate this op
1.771 + break;
1.772 +
1.773 + default:
1.774 + GcOwnerPanic(EWservPanicOpcode);
1.775 + }
1.776 + iBackedUpWinGc->SetClippingRegion(NULL);
1.777 + }
1.778 +
1.779 +TInt CWsGc::WsBitmapHandle(TInt aOpcode, const TWsGcCmdUnion &pData, TInt& aMaskHandle)
1.780 + {
1.781 + TInt handle=0;
1.782 + switch(aOpcode)
1.783 + {
1.784 + case EWsGcOpGdiWsBlt2:
1.785 + handle=pData.GdiBlt2->handle;
1.786 + break;
1.787 + case EWsGcOpGdiWsBlt3:
1.788 + handle=pData.GdiBlt3->handle;
1.789 + break;
1.790 + case EWsGcOpGdiWsBltMasked:
1.791 + handle=pData.GdiBltMasked->handle;
1.792 + aMaskHandle = pData.GdiBltMasked->maskHandle;
1.793 + break;
1.794 + case EWsGcOpGdiWsAlphaBlendBitmaps:
1.795 + handle=pData.AlphaBlendBitmaps->bitmapHandle;
1.796 + aMaskHandle = pData.AlphaBlendBitmaps->alphaHandle;
1.797 + break;
1.798 + case EWsGcOpWsDrawBitmapMasked:
1.799 + handle=pData.iBitmapMasked->iHandle;
1.800 + aMaskHandle=pData.iBitmapMasked->iMaskHandle;
1.801 + break;
1.802 + default:
1.803 + OwnerPanic(EWservPanicOpcode);
1.804 + }
1.805 + return handle;
1.806 + }
1.807 +
1.808 +TInt CWsGc::FbsBitmapHandle(TInt aOpcode, const TWsGcCmdUnion &pData, TInt& aMaskHandle)
1.809 + {
1.810 + TInt handle=0;
1.811 + aMaskHandle=0;
1.812 + switch(aOpcode)
1.813 + {
1.814 + case EWsGcOpGdiBlt2:
1.815 + handle=pData.GdiBlt2->handle;
1.816 + break;
1.817 + case EWsGcOpGdiBlt3:
1.818 + handle=pData.GdiBlt3->handle;
1.819 + break;
1.820 + case EWsGcOpGdiBltMasked:
1.821 + handle=pData.GdiBltMasked->handle;
1.822 + aMaskHandle=pData.GdiBltMasked->maskHandle;
1.823 + break;
1.824 + case EWsGcOpGdiAlphaBlendBitmaps:
1.825 + handle=pData.AlphaBlendBitmaps->bitmapHandle;
1.826 + aMaskHandle=pData.AlphaBlendBitmaps->alphaHandle;
1.827 + break;
1.828 + case EWsGcOpDrawBitmap:
1.829 + handle=pData.Bitmap->handle;
1.830 + break;
1.831 + case EWsGcOpDrawBitmap2:
1.832 + handle=pData.Bitmap2->handle;
1.833 + break;
1.834 + case EWsGcOpDrawBitmap3:
1.835 + handle=pData.Bitmap3->handle;
1.836 + break;
1.837 + case EWsGcOpDrawBitmapMasked:
1.838 + handle=pData.iBitmapMasked->iHandle;
1.839 + aMaskHandle=pData.iBitmapMasked->iMaskHandle;
1.840 + break;
1.841 + default:
1.842 + OwnerPanic(EWservPanicOpcode);
1.843 + }
1.844 + return handle;
1.845 + }
1.846 +
1.847 +TInt CWsGc::WsDrawableSourceHandle(TInt aOpcode, const TWsGcCmdUnion &aData)
1.848 + {
1.849 + TInt handle=0;
1.850 + switch(aOpcode)
1.851 + {
1.852 + case EWsGcOpDrawResourceToPos:
1.853 + handle=aData.DrawWsResourceToPos->wsHandle;
1.854 + break;
1.855 + case EWsGcOpDrawResourceToRect:
1.856 + handle=aData.DrawWsResourceToRect->wsHandle;
1.857 + break;
1.858 + case EWsGcOpDrawResourceFromRectToRect:
1.859 + handle=aData.DrawWsResourceFromRectToRect->wsHandle;
1.860 + break;
1.861 + case EWsGcOpDrawResourceWithData:
1.862 + handle=aData.DrawWsResourceWithData->wsHandle;
1.863 + break;
1.864 + default:
1.865 + OwnerPanic(EWservPanicOpcode);
1.866 + }
1.867 + return handle;
1.868 + }
1.869 +
1.870 +void CWsGc::UpdateJustification(TText* aText,TInt aLen)
1.871 + {
1.872 + iBackedUpWinGc->UpdateJustification(BufferTPtr(aText,aLen));
1.873 + }
1.874 +
1.875 +void CWsGc::UpdateJustification(TText* aText,TInt aLen,CGraphicsContext::TTextParameters* aParam)
1.876 + {
1.877 + iBackedUpWinGc->UpdateJustification(BufferTPtr(aText,aLen),aParam);
1.878 + }
1.879 +
1.880 +void CWsGc::DoDrawing2(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
1.881 + {
1.882 + WS_ASSERT_DEBUG(iWin->Redraw()->OutputDevice(), EWsPanicWindowType);
1.883 +
1.884 + iBackedUpWinGc->SetUserDisplayMode(iWin->DisplayMode());
1.885 + if (iClippingRectSet)
1.886 + {
1.887 + iBackedUpWinGc->SetOrigin(TPoint(0,0));
1.888 + iBackedUpWinGc->SetClippingRect(iClippingRect);
1.889 + }
1.890 + iBackedUpWinGc->SetOrigin(iOrigin);
1.891 + iInternalStatus.iOrigin = iOrigin;
1.892 +
1.893 + DoDrawCommand(aOpcode,pData);
1.894 +
1.895 + iBackedUpWinGc->SetUserDisplayMode(ENone);
1.896 + iBackedUpWinGc->CancelClippingRect();
1.897 + CGraphicsContext::TTextParameters contextParam;
1.898 + switch(aOpcode)
1.899 + {
1.900 + case EWsGcOpDrawLine:
1.901 + iLinePos=pData.DrawLine->pnt2;
1.902 + break;
1.903 + case EWsGcOpDrawTo:
1.904 + case EWsGcOpMoveTo:
1.905 + case EWsGcOpPlot:
1.906 + iLinePos=(*pData.Point);
1.907 + break;
1.908 + case EWsGcOpDrawBy:
1.909 + case EWsGcOpMoveBy:
1.910 + iLinePos+=(*pData.Point);
1.911 + break;
1.912 + case EWsGcOpDrawSegmentedPolygon:
1.913 + EndSegmentedPolygon();
1.914 + break;
1.915 + case EWsGcOpDrawText:
1.916 + UpdateJustification((TText *)(pData.DrawText+1),pData.DrawText->length);
1.917 + break;
1.918 + case EWsGcOpDrawTextVertical:
1.919 + UpdateJustification((TText *)(pData.DrawTextVertical+1),pData.DrawTextVertical->length);
1.920 + break;
1.921 + case EWsGcOpDrawBoxText:
1.922 + UpdateJustification((TText *)(pData.BoxText+1),pData.BoxText->length);
1.923 + break;
1.924 + case EWsGcOpDrawBoxTextOptimised1:
1.925 + UpdateJustification((TText *)(pData.BoxTextO1+1),pData.BoxTextO1->length);
1.926 + break;
1.927 + case EWsGcOpDrawBoxTextOptimised2:
1.928 + UpdateJustification((TText *)(pData.BoxTextO2+1),pData.BoxTextO2->length);
1.929 + break;
1.930 + case EWsGcOpDrawBoxTextVertical:
1.931 + UpdateJustification((TText *)(pData.DrawBoxTextVertical+1),pData.DrawBoxTextVertical->length);
1.932 + break;
1.933 + case EWsGcOpDrawTextLocal:
1.934 + iBackedUpWinGc->UpdateJustification(*pData.DrawTextLocal->desc);
1.935 + break;
1.936 + case EWsGcOpDrawBoxTextLocal:
1.937 + iBackedUpWinGc->UpdateJustification(*pData.BoxTextLocal->desc);
1.938 + break;
1.939 + case EWsGcOpDrawTextPtr:
1.940 + iBackedUpWinGc->UpdateJustification(*pData.DrawTextPtr->text);
1.941 + break;
1.942 + case EWsGcOpDrawTextVerticalPtr:
1.943 + iBackedUpWinGc->UpdateJustification(*pData.DrawTextVerticalPtr->text);
1.944 + break;
1.945 + case EWsGcOpDrawBoxTextPtr:
1.946 + iBackedUpWinGc->UpdateJustification(*pData.DrawBoxTextPtr->text);
1.947 + break;
1.948 + case EWsGcOpDrawBoxTextVerticalPtr:
1.949 + iBackedUpWinGc->UpdateJustification(*pData.DrawBoxTextVerticalPtr->text);
1.950 + break;
1.951 + /***************DrawTextInContext*****************************************************************/
1.952 + case EWsGcOpDrawTextInContext:
1.953 + contextParam.iStart = pData.DrawTextInContext->start;
1.954 + contextParam.iEnd = pData.DrawTextInContext->end;
1.955 + if(contextParam.iStart < contextParam.iEnd)
1.956 + {
1.957 + UpdateJustification((TText *)(pData.DrawTextInContext+1),pData.DrawTextInContext->length,&contextParam);
1.958 + }
1.959 + else
1.960 + {
1.961 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.962 + }
1.963 + break;
1.964 + case EWsGcOpDrawTextInContextVertical:
1.965 + contextParam.iStart = pData.DrawTextInContext->start;
1.966 + contextParam.iEnd = pData.DrawTextInContext->end;
1.967 + if(contextParam.iStart < contextParam.iEnd)
1.968 + {
1.969 + UpdateJustification((TText *)(pData.DrawTextInContextVertical+1),pData.DrawTextInContextVertical->length,&contextParam);
1.970 + }
1.971 + else
1.972 + {
1.973 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.974 + }
1.975 + break;
1.976 + case EWsGcOpDrawBoxTextInContext:
1.977 + contextParam.iStart = pData.DrawTextInContext->start;
1.978 + contextParam.iEnd = pData.DrawTextInContext->end;
1.979 + if(contextParam.iStart < contextParam.iEnd)
1.980 + {
1.981 + UpdateJustification((TText *)(pData.BoxTextInContext+1),pData.BoxTextInContext->length,&contextParam);
1.982 + }
1.983 + else
1.984 + {
1.985 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.986 + }
1.987 + break;
1.988 + case EWsGcOpDrawBoxTextInContextOptimised1:
1.989 + contextParam.iStart = pData.DrawTextInContext->start;
1.990 + contextParam.iEnd = pData.DrawTextInContext->end;
1.991 + if(contextParam.iStart < contextParam.iEnd)
1.992 + {
1.993 + UpdateJustification((TText *)(pData.BoxTextInContextO1+1),pData.BoxTextInContextO1->length,&contextParam);
1.994 + }
1.995 + else
1.996 + {
1.997 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.998 + }
1.999 + break;
1.1000 + case EWsGcOpDrawBoxTextInContextOptimised2:
1.1001 + contextParam.iStart = pData.DrawTextInContext->start;
1.1002 + contextParam.iEnd = pData.DrawTextInContext->end;
1.1003 + if(contextParam.iStart < contextParam.iEnd)
1.1004 + {
1.1005 + UpdateJustification((TText *)(pData.BoxTextInContextO2+1),pData.BoxTextInContextO2->length,&contextParam);
1.1006 + }
1.1007 + else
1.1008 + {
1.1009 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.1010 + }
1.1011 + break;
1.1012 + case EWsGcOpDrawBoxTextInContextVertical:
1.1013 + contextParam.iStart = pData.DrawTextInContext->start;
1.1014 + contextParam.iEnd = pData.DrawTextInContext->end;
1.1015 + if(contextParam.iStart < contextParam.iEnd)
1.1016 + {
1.1017 + UpdateJustification((TText *)(pData.DrawBoxTextInContextVertical+1),pData.DrawBoxTextInContextVertical->length,&contextParam);
1.1018 + }
1.1019 + else
1.1020 + {
1.1021 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.1022 + }
1.1023 + break;
1.1024 + case EWsGcOpDrawTextInContextLocal:
1.1025 + contextParam.iStart = pData.DrawTextInContext->start;
1.1026 + contextParam.iEnd = pData.DrawTextInContext->end;
1.1027 + if(contextParam.iStart < contextParam.iEnd)
1.1028 + {
1.1029 + iBackedUpWinGc->UpdateJustification(*pData.DrawTextInContextLocal->desc,&contextParam);
1.1030 + }
1.1031 + else
1.1032 + {
1.1033 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.1034 + }
1.1035 + break;
1.1036 + case EWsGcOpDrawBoxTextInContextLocal:
1.1037 + contextParam.iStart = pData.DrawTextInContext->start;
1.1038 + contextParam.iEnd = pData.DrawTextInContext->end;
1.1039 + if(contextParam.iStart < contextParam.iEnd)
1.1040 + {
1.1041 + iBackedUpWinGc->UpdateJustification(*pData.BoxTextInContextLocal->desc,&contextParam);
1.1042 + }
1.1043 + else
1.1044 + {
1.1045 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.1046 + }
1.1047 + break;
1.1048 + case EWsGcOpDrawTextInContextPtr:
1.1049 + contextParam.iStart = pData.DrawTextInContext->start;
1.1050 + contextParam.iEnd = pData.DrawTextInContext->end;
1.1051 + if(contextParam.iStart < contextParam.iEnd)
1.1052 + {
1.1053 + iBackedUpWinGc->UpdateJustification(*pData.DrawTextInContextPtr->text,&contextParam);
1.1054 + }
1.1055 + else
1.1056 + {
1.1057 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.1058 + }
1.1059 + break;
1.1060 + case EWsGcOpDrawTextInContextVerticalPtr:
1.1061 + contextParam.iStart = pData.DrawTextInContext->start;
1.1062 + contextParam.iEnd = pData.DrawTextInContext->end;
1.1063 + if(contextParam.iStart < contextParam.iEnd)
1.1064 + {
1.1065 + iBackedUpWinGc->UpdateJustification(*pData.DrawTextInContextVerticalPtr->text,&contextParam);
1.1066 + }
1.1067 + else
1.1068 + {
1.1069 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.1070 + }
1.1071 + break;
1.1072 + case EWsGcOpDrawBoxTextInContextPtr:
1.1073 + contextParam.iStart = pData.DrawTextInContext->start;
1.1074 + contextParam.iEnd = pData.DrawTextInContext->end;
1.1075 + if(contextParam.iStart < contextParam.iEnd)
1.1076 + {
1.1077 + iBackedUpWinGc->UpdateJustification(*pData.DrawBoxTextInContextPtr->text,&contextParam);
1.1078 + }
1.1079 + else
1.1080 + {
1.1081 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.1082 + }
1.1083 + break;
1.1084 + case EWsGcOpDrawBoxTextInContextVerticalPtr:
1.1085 + contextParam.iStart = pData.DrawTextInContext->start;
1.1086 + contextParam.iEnd = pData.DrawTextInContext->end;
1.1087 + if(contextParam.iStart < contextParam.iEnd)
1.1088 + {
1.1089 + iBackedUpWinGc->UpdateJustification(*pData.DrawBoxTextInContextVerticalPtr->text,&contextParam);
1.1090 + }
1.1091 + else
1.1092 + {
1.1093 + iWin->WsOwner()->PPanic(EWservPanicInvalidParameter);
1.1094 + }
1.1095 + break;
1.1096 + }
1.1097 + }
1.1098 +
1.1099 +void CWsGc::DoDrawing1(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
1.1100 + {
1.1101 + WS_ASSERT_DEBUG(iWin->Redraw()->OutputDevice(), EWsPanicWindowType);
1.1102 +
1.1103 + TWsGcLargeStruct newData;
1.1104 + TWsGcCmdUnion pNewData;
1.1105 + TWsGcOpcodes opcode;
1.1106 + TDesC **string;
1.1107 + TInt toGo;
1.1108 + pNewData.LargeStruct=&newData;
1.1109 + switch (aOpcode)
1.1110 + {
1.1111 + case EWsGcOpDrawTextPtr:
1.1112 + WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdDrawTextPtr), EWsPanicGcStructSizeError);
1.1113 + opcode=EWsGcOpDrawTextPtr1;
1.1114 + toGo=pData.DrawText->length;
1.1115 + pNewData.DrawTextPtr->pos=pData.DrawText->pos;
1.1116 + string=&(pNewData.DrawTextPtr->text);
1.1117 + break;
1.1118 + case EWsGcOpDrawTextVerticalPtr:
1.1119 + WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdDrawTextVerticalPtr), EWsPanicGcStructSizeError);
1.1120 + opcode=EWsGcOpDrawTextVerticalPtr1;
1.1121 + toGo=pData.DrawTextVertical->length;
1.1122 + pNewData.DrawTextVerticalPtr->pos=pData.DrawTextVertical->pos;
1.1123 + pNewData.DrawTextVerticalPtr->up=pData.DrawTextVertical->up;
1.1124 + string=&(pNewData.DrawTextVerticalPtr->text);
1.1125 + break;
1.1126 +
1.1127 + case EWsGcOpDrawBoxTextPtr:
1.1128 + WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdBoxTextPtr), EWsPanicGcStructSizeError);
1.1129 + opcode=EWsGcOpDrawBoxTextPtr1;
1.1130 + toGo=pData.BoxText->length;
1.1131 + pNewData.DrawBoxTextPtr->box=pData.BoxText->box;
1.1132 + pNewData.DrawBoxTextPtr->baselineOffset=pData.BoxText->baselineOffset;
1.1133 + pNewData.DrawBoxTextPtr->horiz=pData.BoxText->horiz;
1.1134 + pNewData.DrawBoxTextPtr->leftMrg=pData.BoxText->leftMrg;
1.1135 + pNewData.DrawBoxTextPtr->width=pData.BoxText->width;
1.1136 + string=&(pNewData.DrawBoxTextPtr->text);
1.1137 + break;
1.1138 +
1.1139 + case EWsGcOpDrawBoxTextVerticalPtr:
1.1140 + WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdBoxTextVerticalPtr), EWsPanicGcStructSizeError);
1.1141 + opcode=EWsGcOpDrawBoxTextVerticalPtr1;
1.1142 + toGo=pData.DrawBoxTextVertical->length;
1.1143 + pNewData.DrawBoxTextVerticalPtr->box=pData.DrawBoxTextVertical->box;
1.1144 + pNewData.DrawBoxTextVerticalPtr->baselineOffset=pData.DrawBoxTextVertical->baselineOffset;
1.1145 + pNewData.DrawBoxTextVerticalPtr->up=pData.DrawBoxTextVertical->up;
1.1146 + pNewData.DrawBoxTextVerticalPtr->vert=pData.DrawBoxTextVertical->vert;
1.1147 + pNewData.DrawBoxTextVerticalPtr->margin=pData.DrawBoxTextVertical->margin;
1.1148 + pNewData.DrawBoxTextVerticalPtr->width=pData.DrawBoxTextVertical->width;
1.1149 + string=&(pNewData.DrawBoxTextVerticalPtr->text);
1.1150 + break;
1.1151 +
1.1152 + case EWsGcOpDrawTextInContextPtr:
1.1153 + WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdDrawTextInContextPtr), EWsPanicGcStructSizeError);
1.1154 + opcode=EWsGcOpDrawTextInContextPtr1;
1.1155 + toGo=pData.DrawTextInContext->length;
1.1156 + pNewData.DrawTextInContextPtr->pos=pData.DrawTextInContext->pos;
1.1157 + pNewData.DrawTextInContextPtr->start=pData.DrawTextInContext->start;
1.1158 + pNewData.DrawTextInContextPtr->end=pData.DrawTextInContext->end;
1.1159 + string=&(pNewData.DrawTextInContextPtr->text);
1.1160 + break;
1.1161 +
1.1162 + case EWsGcOpDrawTextInContextVerticalPtr:
1.1163 + WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdDrawTextInContextVerticalPtr), EWsPanicGcStructSizeError);
1.1164 + opcode=EWsGcOpDrawTextInContextVerticalPtr1;
1.1165 + toGo=pData.DrawTextInContextVertical->length;
1.1166 + pNewData.DrawTextInContextVerticalPtr->pos=pData.DrawTextInContextVerticalPtr->pos;
1.1167 + pNewData.DrawTextInContextVerticalPtr->up=pData.DrawTextInContextVerticalPtr->up;
1.1168 + pNewData.DrawTextInContextVerticalPtr->start=pData.DrawTextInContextVerticalPtr->start;
1.1169 + pNewData.DrawTextInContextVerticalPtr->end=pData.DrawTextInContextVerticalPtr->end;
1.1170 + string=&(pNewData.DrawTextVerticalPtr->text);
1.1171 + break;
1.1172 +
1.1173 + case EWsGcOpDrawBoxTextInContextPtr:
1.1174 + WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdBoxTextInContextPtr), EWsPanicGcStructSizeError);
1.1175 + opcode=EWsGcOpDrawBoxTextInContextPtr1;
1.1176 + toGo=pData.BoxTextInContext->length;
1.1177 + pNewData.DrawBoxTextInContextPtr->box=pData.BoxTextInContext->box;
1.1178 + pNewData.DrawBoxTextInContextPtr->baselineOffset=pData.BoxTextInContext->baselineOffset;
1.1179 + pNewData.DrawBoxTextInContextPtr->horiz=pData.BoxTextInContext->horiz;
1.1180 + pNewData.DrawBoxTextInContextPtr->leftMrg=pData.BoxTextInContext->leftMrg;
1.1181 + pNewData.DrawBoxTextInContextPtr->width=pData.BoxTextInContext->width;
1.1182 + pNewData.DrawBoxTextInContextPtr->start=pData.BoxTextInContext->start;
1.1183 + pNewData.DrawBoxTextInContextPtr->end=pData.BoxTextInContext->end;
1.1184 + string=&(pNewData.DrawBoxTextPtr->text);
1.1185 + break;
1.1186 +
1.1187 + case EWsGcOpDrawBoxTextInContextVerticalPtr:
1.1188 + WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdBoxTextInContextVerticalPtr), EWsPanicGcStructSizeError);
1.1189 + opcode=EWsGcOpDrawBoxTextInContextVerticalPtr1;
1.1190 + toGo=pData.DrawBoxTextInContextVertical->length;
1.1191 + pNewData.DrawBoxTextInContextVerticalPtr->box=pData.DrawBoxTextInContextVertical->box;
1.1192 + pNewData.DrawBoxTextInContextVerticalPtr->baselineOffset=pData.DrawBoxTextInContextVertical->baselineOffset;
1.1193 + pNewData.DrawBoxTextInContextVerticalPtr->up=pData.DrawBoxTextInContextVertical->up;
1.1194 + pNewData.DrawBoxTextInContextVerticalPtr->vert=pData.DrawBoxTextInContextVertical->vert;
1.1195 + pNewData.DrawBoxTextInContextVerticalPtr->margin=pData.DrawBoxTextInContextVertical->margin;
1.1196 + pNewData.DrawBoxTextInContextVerticalPtr->width=pData.DrawBoxTextInContextVertical->width;
1.1197 + pNewData.DrawBoxTextInContextVerticalPtr->start=pData.DrawBoxTextInContextVertical->start;
1.1198 + pNewData.DrawBoxTextInContextVerticalPtr->end=pData.DrawBoxTextInContextVertical->end;
1.1199 + string=&(pNewData.DrawBoxTextInContextVerticalPtr->text);
1.1200 + break;
1.1201 +
1.1202 + default:
1.1203 + DoDrawing2(aOpcode,pData);
1.1204 + return;
1.1205 + }
1.1206 +
1.1207 + TBuf<ETextPtrBufLen> buf;
1.1208 + TInt len=ETextPtrBufLen;
1.1209 + TInt bufOffset=0;
1.1210 + *string=&buf;
1.1211 + while(toGo>0)
1.1212 + {
1.1213 + if (len>toGo)
1.1214 + len=toGo;
1.1215 + iWsOwner->RemoteRead(buf,bufOffset);
1.1216 + DoDrawing2(aOpcode,pNewData);
1.1217 + aOpcode=opcode;
1.1218 + bufOffset+=len;
1.1219 + toGo-=len;
1.1220 + }
1.1221 + }
1.1222 +
1.1223 +void CWsGc::SetGcAttribute(TInt aOpcode, TWsGcCmdUnion pData)
1.1224 + {
1.1225 + switch(aOpcode)
1.1226 + {
1.1227 + case EWsGcOpSetDrawMode:
1.1228 + iInternalStatus.iDrawMode = (CGraphicsContext::TDrawMode) (*pData.UInt);
1.1229 + if (iWin->Redraw()->OutputDevice())
1.1230 + iBackedUpWinGc->SetDrawMode(iInternalStatus.iDrawMode);
1.1231 + break;
1.1232 + case EWsGcOpUseFont:
1.1233 + if (CWsFontCache::Instance()->UseFont(iFont, *pData.UInt))
1.1234 + { // Couldn't cache it
1.1235 + if (iWin->Redraw()->OutputDevice())
1.1236 + {
1.1237 + TInt ret = iBackedUpWinGc->UseFont(*pData.UInt);
1.1238 + if (ret == KErrNoMemory)
1.1239 + return;
1.1240 + if (ret != KErrNone)
1.1241 + GcOwnerPanic(EWservPanicFont);
1.1242 + }
1.1243 + iInternalStatus.iFontHandle = *pData.UInt;
1.1244 + }
1.1245 + else
1.1246 + {
1.1247 + if (iFont==NULL)
1.1248 + {
1.1249 + iInternalStatus.iFontHandle = NULL;
1.1250 + GcOwnerPanic(EWservPanicFont);
1.1251 + }
1.1252 + if (iWin->Redraw()->OutputDevice())
1.1253 + iBackedUpWinGc->UseFontNoDuplicate(iFont);
1.1254 + iInternalStatus.iFontHandle = iFont->Handle();
1.1255 + }
1.1256 + break;
1.1257 + case EWsGcOpDiscardFont:
1.1258 + CWsFontCache::Instance()->ReleaseFont(iFont);
1.1259 + if (iWin->Redraw()->OutputDevice())
1.1260 + iBackedUpWinGc->DiscardFont();
1.1261 + iInternalStatus.iFontHandle = NULL;
1.1262 + break;
1.1263 + case EWsGcOpSetUnderlineStyle:
1.1264 + if (iWin->Redraw()->OutputDevice())
1.1265 + iBackedUpWinGc->SetUnderlineStyle(*pData.SetUnderlineStyle);
1.1266 + iInternalStatus.iUnderline = *pData.SetUnderlineStyle;
1.1267 + break;
1.1268 + case EWsGcOpSetStrikethroughStyle:
1.1269 + if (iWin->Redraw()->OutputDevice())
1.1270 + iBackedUpWinGc->SetStrikethroughStyle(*pData.SetStrikethroughStyle);
1.1271 + iInternalStatus.iStrikethrough = *pData.SetStrikethroughStyle;
1.1272 + break;
1.1273 + case EWsGcOpUseBrushPattern:
1.1274 + if (iWin->Redraw()->OutputDevice())
1.1275 + {
1.1276 + TInt ret = iBackedUpWinGc->UseBrushPattern(*pData.handle);
1.1277 + if (ret == KErrNoMemory)
1.1278 + return;
1.1279 + if (ret != KErrNone)
1.1280 + GcOwnerPanic(EWservPanicBitmap);
1.1281 + }
1.1282 + else
1.1283 + {
1.1284 + // Make sure the bitmap handle is valid
1.1285 + TInt ret = iScratchBitmap->Duplicate(*pData.handle);
1.1286 + if (ret == KErrNoMemory)
1.1287 + return;
1.1288 + if (ret != KErrNone)
1.1289 + GcOwnerPanic(EWservPanicBitmap);
1.1290 + iScratchBitmap->Reset();
1.1291 + }
1.1292 + iInternalStatus.iBrushPatternHandle = *pData.handle;
1.1293 + break;
1.1294 + case EWsGcOpDiscardBrushPattern:
1.1295 + if (iWin->Redraw()->OutputDevice())
1.1296 + iBackedUpWinGc->DiscardBrushPattern();
1.1297 + iInternalStatus.iBrushPatternHandle = NULL;
1.1298 + if (iInternalStatus.iBrushStyle == CGraphicsContext::EPatternedBrush)
1.1299 + iInternalStatus.iBrushStyle = CGraphicsContext::ENullBrush;
1.1300 + break;
1.1301 + case EWsGcOpSetBrushColor:
1.1302 + if (iWin->Redraw()->OutputDevice())
1.1303 + iBackedUpWinGc->SetBrushColor(*pData.rgb);
1.1304 + iInternalStatus.iBrushColor = *pData.rgb;
1.1305 + break;
1.1306 + case EWsGcOpSetPenColor:
1.1307 + if (iWin->Redraw()->OutputDevice())
1.1308 + iBackedUpWinGc->SetPenColor(*pData.rgb);
1.1309 + iInternalStatus.iPenColor = *pData.rgb;
1.1310 + break;
1.1311 + case EWsGcOpSetPenStyle:
1.1312 + iInternalStatus.iPenStyle = (CGraphicsContext::TPenStyle) (*pData.UInt);
1.1313 + if (iWin->Redraw()->OutputDevice())
1.1314 + iBackedUpWinGc->SetPenStyle(iInternalStatus.iPenStyle);
1.1315 + break;
1.1316 + case EWsGcOpSetPenSize:
1.1317 + if (iWin->Redraw()->OutputDevice())
1.1318 + iBackedUpWinGc->SetPenSize(*pData.Size);
1.1319 + iInternalStatus.iPenSize = *pData.Size;
1.1320 + break;
1.1321 + case EWsGcOpSetBrushStyle:
1.1322 + if ((CGraphicsContext::TBrushStyle)*pData.UInt==CGraphicsContext::EPatternedBrush && !iInternalStatus.iBrushPatternHandle)
1.1323 + GcOwnerPanic(EWservPanicNoBrush);
1.1324 + iInternalStatus.iBrushStyle = (CGraphicsContext::TBrushStyle) (*pData.UInt);
1.1325 + if (iWin->Redraw()->OutputDevice())
1.1326 + iBackedUpWinGc->SetBrushStyle(iInternalStatus.iBrushStyle);
1.1327 + break;
1.1328 + case EWsGcOpReset:
1.1329 + CWsFontCache::Instance()->ReleaseFont(iFont);
1.1330 + iBackedUpWinGc->Reset();
1.1331 + iOrigin.SetXY(0,0);
1.1332 + ResetClippingRect();
1.1333 + iInternalStatus.ResetInternalStatus(iWin);
1.1334 + if (iWin->Redraw()->OutputDevice())
1.1335 + iBackedUpWinGc->SetBrushColor(iWin->BackColor());
1.1336 + iInternalStatus.iBrushColor = iWin->BackColor();
1.1337 + break;
1.1338 + case EWsGcOpSetBrushOrigin:
1.1339 + if (iWin->Redraw()->OutputDevice())
1.1340 + iBackedUpWinGc->SetBrushOrigin(*pData.Point);
1.1341 + iInternalStatus.iBrushOrigin = *pData.Point;
1.1342 + break;
1.1343 + case EWsGcOpSetDitherOrigin:
1.1344 + GcOwnerPanic(EWservPanicOpcode); //deprecated, the client should never generate this op
1.1345 + break;
1.1346 + case EWsGcOpSetWordJustification:
1.1347 + if (iWin->Redraw()->OutputDevice())
1.1348 + iBackedUpWinGc->SetWordJustification(pData.SetJustification->excessWidth, pData.SetJustification->numGaps);
1.1349 + iInternalStatus.iWordExcessWidth = pData.SetJustification->excessWidth;
1.1350 + iInternalStatus.iWordNumChars = pData.SetJustification->numGaps;
1.1351 + break;
1.1352 + case EWsGcOpSetCharJustification:
1.1353 + if (iWin->Redraw()->OutputDevice())
1.1354 + iBackedUpWinGc->SetCharJustification(pData.SetJustification->excessWidth, pData.SetJustification->numGaps);
1.1355 + iInternalStatus.iCharExcessWidth = pData.SetJustification->excessWidth;
1.1356 + iInternalStatus.iCharNumChars = pData.SetJustification->numGaps;
1.1357 + break;
1.1358 + case EWsGcOpSetOrigin:
1.1359 + SetOrigin(*pData.Point);
1.1360 + iInternalStatus.iOrigin = *pData.Point;
1.1361 + break;
1.1362 + case EWsGcOpSetOpaque: // deprecated
1.1363 + // do nothing
1.1364 + break;
1.1365 + case EWsGcOpSetShadowColor:
1.1366 + if (iWin->Redraw()->OutputDevice())
1.1367 + iBackedUpWinGc->SetShadowColor(*pData.rgb);
1.1368 + iInternalStatus.iShadowColor = *pData.rgb;
1.1369 + break;
1.1370 + }
1.1371 + }
1.1372 +
1.1373 +void CWsGc::DoDrawing0L(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
1.1374 + {
1.1375 + if (iWin==NULL)
1.1376 + {
1.1377 + OwnerPanic(EWservPanicGcNotActive);
1.1378 + return;
1.1379 + }
1.1380 +
1.1381 + iWin->SetValidRedraw();
1.1382 +
1.1383 + switch(aOpcode)
1.1384 + {
1.1385 + case EWsGcOpStartSegmentedDrawPolygon:
1.1386 +
1.1387 + //tell Redraw Store about the drawing data, so that it is stored and CWsGc::ExternalizeL can be called if required
1.1388 + if (iWin->Redraw()->DrawCommand(this,pData.any))
1.1389 + StartSegmentedDrawPolygonL(pData.StartSegmentedDrawPolygon);
1.1390 + return;
1.1391 + case EWsGcOpSegmentedDrawPolygonData:
1.1392 + //tell Redraw Store about the drawing data, so that it is stored and CWsGc::ExternalizeL can be called if required
1.1393 + if (iWin->Redraw()->DrawCommand(this,pData.any))
1.1394 + SegmentedDrawPolygonData(pData.SegmentedDrawPolygonData);
1.1395 + return;
1.1396 + case EWsGcOpSetClippingRegion:
1.1397 + SetClippingRegionL(*pData.Int);
1.1398 + break;
1.1399 + case EWsGcOpSetClippingRect:
1.1400 + SetClippingRect(*pData.Rect);
1.1401 + break;
1.1402 + case EWsGcOpCancelClippingRect:
1.1403 + ResetClippingRect();
1.1404 + break;
1.1405 + case EWsGcOpCancelClippingRegion:
1.1406 + CancelClippingRegion();
1.1407 + break;
1.1408 + case EWsGcOpSetFaded:
1.1409 + if (iWin->Redraw()->OutputDevice())
1.1410 + iBackedUpWinGc->SetFaded(*pData.Bool);
1.1411 + break;
1.1412 + case EWsGcOpSetFadeParams:
1.1413 + if (iWin->Redraw()->OutputDevice())
1.1414 + iBackedUpWinGc->SetFadingParameters(WservEncoding::ExtractFirst8BitValue(*pData.UInt),WservEncoding::ExtractSecond8BitValue(*pData.UInt));
1.1415 + break;
1.1416 + case EWsGcOpSetDrawMode:
1.1417 + case EWsGcOpUseFont:
1.1418 + case EWsGcOpDiscardFont:
1.1419 + case EWsGcOpUseBrushPattern:
1.1420 + case EWsGcOpDiscardBrushPattern:
1.1421 + case EWsGcOpSetBrushColor:
1.1422 + case EWsGcOpSetPenColor:
1.1423 + case EWsGcOpSetPenStyle:
1.1424 + case EWsGcOpSetPenSize:
1.1425 + case EWsGcOpSetBrushStyle:
1.1426 + case EWsGcOpReset:
1.1427 + case EWsGcOpSetBrushOrigin:
1.1428 + case EWsGcOpSetDitherOrigin:
1.1429 + case EWsGcOpSetUnderlineStyle:
1.1430 + case EWsGcOpSetStrikethroughStyle:
1.1431 + case EWsGcOpSetWordJustification:
1.1432 + case EWsGcOpSetCharJustification:
1.1433 + case EWsGcOpSetOrigin:
1.1434 + case EWsGcOpSetOpaque:
1.1435 + case EWsGcOpSetShadowColor:
1.1436 + {
1.1437 + SetGcAttribute(aOpcode,pData);
1.1438 + break;
1.1439 + }
1.1440 + case EWsGcOpDrawBoxText:
1.1441 + case EWsGcOpDrawBoxTextOptimised1:
1.1442 + case EWsGcOpDrawBoxTextOptimised2:
1.1443 + case EWsGcOpDrawBoxTextPtr:
1.1444 + case EWsGcOpDrawBoxTextPtr1:
1.1445 + case EWsGcOpDrawTextPtr:
1.1446 + case EWsGcOpDrawTextPtr1:
1.1447 + case EWsGcOpDrawText:
1.1448 + case EWsGcOpDrawTextVertical:
1.1449 + case EWsGcOpDrawTextVerticalPtr:
1.1450 + case EWsGcOpDrawTextVerticalPtr1:
1.1451 + case EWsGcOpDrawBoxTextVertical:
1.1452 + case EWsGcOpDrawBoxTextVerticalPtr:
1.1453 + case EWsGcOpDrawBoxTextVerticalPtr1:
1.1454 + case EWsGcOpDrawTextLocal:
1.1455 + case EWsGcOpDrawBoxTextLocal:
1.1456 + {
1.1457 + //Make sure a font is set before any text related opcodes are used.
1.1458 + if (!iInternalStatus.iFontHandle)
1.1459 + OwnerPanic(EWservPanicNoFont);
1.1460 + //fall through
1.1461 + }
1.1462 + default: // Assume remaining functions will draw
1.1463 + {
1.1464 + if (iWin->WinType()!=EWinTypeRoot)
1.1465 + {
1.1466 + if (!iWin->BaseParent())
1.1467 + OwnerPanic(EWservPanicParentDeleted);
1.1468 + if (iWin->WinType()!=EWinTypeClient)
1.1469 + OwnerPanic(EWservPanicReadOnlyDrawable);
1.1470 + }
1.1471 + if (iWin->Redraw()->DrawCommand(this,pData.any))
1.1472 + DoDrawing1(aOpcode,pData);
1.1473 + return;
1.1474 + }
1.1475 + }
1.1476 + iWin->Redraw()->GcAttributeChange(this,pData.any);
1.1477 + }
1.1478 +
1.1479 +void CWsGc::CommandL(TInt aOpcode, const TAny *aCmdData)
1.1480 + {
1.1481 + TWsGcOpcodes opcode = static_cast<TWsGcOpcodes>(aOpcode);
1.1482 +
1.1483 + TWsGcCmdUnion pData;
1.1484 + pData.any=aCmdData;
1.1485 + switch(opcode)
1.1486 + {
1.1487 + case EWsGcOpActivate:
1.1488 + Activate(*pData.handle);
1.1489 + break;
1.1490 + case EWsGcOpDeactivate:
1.1491 + Deactivate();
1.1492 + break;
1.1493 + case EWsGcOpFree:
1.1494 + delete this;
1.1495 + break;
1.1496 + case EWsGcOpTestInvariant:
1.1497 + break;
1.1498 + default:
1.1499 + DoDrawing0L(opcode,pData);
1.1500 + break;
1.1501 + }
1.1502 + }
1.1503 +
1.1504 +void CWsGc::SetOrigin(const TPoint &aOrigin)
1.1505 + {
1.1506 + iOrigin=aOrigin;
1.1507 + }
1.1508 +
1.1509 +
1.1510 +/*------------------------------------------------------------------------------
1.1511 + Description: Saves graphics context information into a given buffer from a
1.1512 + given start position rather than just streaming data to the end.
1.1513 + This variant allows for buffers that are not fully utilised.
1.1514 + -----------------------------------------------------------------------------*/
1.1515 +TInt CWsGc::ExternalizeL(CBufBase& aBuffer, TInt aStartPos)
1.1516 + {
1.1517 + WS_ASSERT_DEBUG(!IsPolyPointData(), EWsPanicDrawCommandsInvalidState);
1.1518 +
1.1519 + // Open the stream used for the output from the given start position
1.1520 + // in the buffer.
1.1521 + RBufWriteStream bufWriteStream;
1.1522 + bufWriteStream.Open(aBuffer, aStartPos);
1.1523 + CleanupClosePushL(bufWriteStream);
1.1524 +
1.1525 + // Font/Bitmap Server data is serialised below in a call to
1.1526 + // ExternalizeGcAttributesL(). As this method does not return the amount of
1.1527 + // the data externalised we use methods in the underlying stream to
1.1528 + // calculate it. We do this because we need to return an accurate count of
1.1529 + // data serialised from this method so that the caller can update its
1.1530 + // buffer write counter.
1.1531 + MStreamBuf* ptrToRawStream = bufWriteStream.Sink(); // This is the real stream
1.1532 +
1.1533 + // Position of read seek pointer before externalise
1.1534 + TStreamPos size1 = ptrToRawStream->TellL(MStreamBuf::EWrite);
1.1535 +
1.1536 + // Save the font/bitmap server data
1.1537 + iInternalStatus.ExternalizeGcAttributesL(bufWriteStream);
1.1538 +
1.1539 + bufWriteStream.WriteInt32L(iOrigin.iX);
1.1540 + bufWriteStream.WriteInt32L(iOrigin.iY);
1.1541 +
1.1542 + bufWriteStream.WriteInt8L(iClippingRectSet);
1.1543 +
1.1544 + // If there is a clipping rectangle output that too.
1.1545 + if (iClippingRectSet)
1.1546 + {
1.1547 + bufWriteStream << iClippingRect;
1.1548 + }
1.1549 +
1.1550 + // Save clipping region data.
1.1551 + ExternalizeClippingRegionL(bufWriteStream);
1.1552 +
1.1553 + // Save the Alpha values for Brush and Pen colors.
1.1554 + ExternalizeAlphaValueL(bufWriteStream);
1.1555 +
1.1556 + // Position of read seek pointer after externalise
1.1557 + TStreamPos size2 = ptrToRawStream->TellL(MStreamBuf::EWrite);
1.1558 + CleanupStack::PopAndDestroy(&bufWriteStream);
1.1559 +
1.1560 + // Return actual size of data serialized
1.1561 + return (size2 - size1);
1.1562 + }
1.1563 +
1.1564 +/*------------------------------------------------------------------------------
1.1565 + Description: Saves TRgb::alpha value information into a given buffer.
1.1566 + ----------------------------------------------------------------------------*/
1.1567 +void CWsGc::ExternalizeAlphaValueL(RWriteStream& aWriteStream)
1.1568 + {
1.1569 + aWriteStream.WriteUint8L(iInternalStatus.iBrushColor.Alpha());
1.1570 + aWriteStream.WriteUint8L(iInternalStatus.iPenColor.Alpha());
1.1571 + }
1.1572 +
1.1573 +/*------------------------------------------------------------------------------
1.1574 + Description: Helper method to store clipping region data to a given
1.1575 + write stream.
1.1576 + -----------------------------------------------------------------------------*/
1.1577 +TInt CWsGc::ExternalizeClippingRegionL(RWriteStream& aWriteStream)
1.1578 + {
1.1579 + TBool clipRegion = (iUserDefinedClippingRegion != NULL);
1.1580 + // Store flag to indicate if client has defined a clipping region
1.1581 + aWriteStream.WriteInt8L(clipRegion);
1.1582 + // Store client clipping region data if it exists
1.1583 + if (clipRegion)
1.1584 + {
1.1585 + return ExternalizeRegionL(aWriteStream, *iUserDefinedClippingRegion) + sizeof(TInt8);
1.1586 + }
1.1587 + return sizeof(TInt8);
1.1588 + }
1.1589 +