1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/nga/CLIENT/RGC.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,2333 @@
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 +// Shells for window server graphics class
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <graphics/wsdrawresource.h>
1.23 +#include "../SERVER/w32cmd.h"
1.24 +#include "CLIENT.H"
1.25 +#include "w32comm.h"
1.26 +#include "graphicsresourcewrapper.h"
1.27 +#include <graphics/gdi/gdiconsts.h>
1.28 +#include <graphics/gdi/gdistructs.h>
1.29 +#include "graphics/windowserverconstants.h"
1.30 +
1.31 +#define KDefaultShadowColor KRgbGray
1.32 +enum {EPolygonMaxHeaderSize=sizeof(TWsCmdHeader)+sizeof(TWsGcCmdSegmentedDrawPolygonData)};
1.33 +
1.34 +//
1.35 +// class CWindowGc::CPimpl
1.36 +//
1.37 +
1.38 +NONSHARABLE_STRUCT(CWindowGc::CPimpl): public CBase, public MWsDrawResource
1.39 +/** @internalComponent @released */
1.40 + {
1.41 +public:
1.42 + enum TStateType
1.43 + {
1.44 + EStateBrushColor = 1<<0,
1.45 + EStateBrushStyle = 1<<1,
1.46 + EStatePenColor = 1<<2,
1.47 + EStatePenStyle = 1<<3,
1.48 + EStatePenSize = 1<<4,
1.49 + EStateDrawMode = 1<<5,
1.50 + EStateClippingRect = 1<<6,
1.51 + EStateUnderlineStyle = 1<<7,
1.52 + EStateStrikethroughStyle = 1<<8,
1.53 + EStateWordJustification = 1<<9,
1.54 + EStateCharJustification = 1<<10,
1.55 + };
1.56 +
1.57 + CPimpl(CWindowGc& aGc);
1.58 + void WriteAnyPendingStateChanges();
1.59 + void ResetPendingState();
1.60 + void StorePendingStateChange(TStateType aState, const TAny* aValue);
1.61 + TUint32 GetState() const {return iPendingState;}
1.62 + void CancelPendingClippingRect();
1.63 + ~CPimpl();
1.64 +public: //from MWsDrawResource
1.65 + void DrawResource(const TPoint& aPos, const RWsDrawableSource& aSource, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
1.66 + {
1.67 + iGc.DrawResource(aPos, aSource, aRotation);
1.68 + }
1.69 + void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
1.70 + {
1.71 + iGc.DrawResource(aDestRect, aSource, aRotation);
1.72 + }
1.73 + void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TRect& aSrcRect, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
1.74 + {
1.75 + iGc.DrawResource(aDestRect, aSource, aSrcRect, aRotation);
1.76 + }
1.77 + void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TDesC8& aParam)
1.78 + {
1.79 + iGc.DrawResource(aDestRect, aSource, aParam);
1.80 + }
1.81 +public:
1.82 + CWindowGc& iGc;
1.83 + CFbsFont* iFont;
1.84 + TRgb iShadowColor;
1.85 + TBool iForceWrite;
1.86 + TBool iClippingRectSet;
1.87 +
1.88 +private:
1.89 + TUint32 iPendingState;
1.90 +
1.91 + // Pending state - used to store requested state changes not yet written to wserv
1.92 + TRgb iPendingBrushColor;
1.93 + TBrushStyle iPendingBrushStyle;
1.94 + TRgb iPendingPenColor;
1.95 + TPenStyle iPendingPenStyle;
1.96 + TSize iPendingPenSize;
1.97 + TDrawMode iPendingDrawMode;
1.98 + TRect iPendingClippingRect;
1.99 + TFontUnderline iPendingUnderlineStyle;
1.100 + TFontStrikethrough iPendingStrikethroughStyle;
1.101 + TWsGcCmdSetJustification iPendingWordJustification;
1.102 + TWsGcCmdSetJustification iPendingCharJustification;
1.103 +
1.104 + // Current state - values that have actually been written to wserv
1.105 + TRgb iCurrentBrushColor;
1.106 + TBrushStyle iCurrentBrushStyle;
1.107 + TRgb iCurrentPenColor;
1.108 + TPenStyle iCurrentPenStyle;
1.109 + TSize iCurrentPenSize;
1.110 + TDrawMode iCurrentDrawMode;
1.111 + TFontUnderline iCurrentUnderlineStyle;
1.112 + TFontStrikethrough iCurrentStrikethroughStyle;
1.113 + TWsGcCmdSetJustification iCurrentWordJustification;
1.114 + TWsGcCmdSetJustification iCurrentCharJustification;
1.115 + };
1.116 +
1.117 +CWindowGc::CPimpl::CPimpl(CWindowGc& aGc)
1.118 + : iGc(aGc), iFont(NULL), iShadowColor(KDefaultShadowColor)
1.119 + {
1.120 + ResetPendingState();
1.121 + }
1.122 +
1.123 +CWindowGc::CPimpl::~CPimpl()
1.124 + {
1.125 + iFont = NULL;
1.126 + }
1.127 +
1.128 +void CWindowGc::CPimpl::CancelPendingClippingRect()
1.129 + {
1.130 + iPendingState &= ~EStateClippingRect;
1.131 + }
1.132 +
1.133 +void CWindowGc::CPimpl::WriteAnyPendingStateChanges()
1.134 + {
1.135 + if (iPendingState == 0)
1.136 + return;
1.137 +
1.138 + if (iPendingState & EStateDrawMode)
1.139 + {
1.140 + if (iPendingDrawMode != iCurrentDrawMode)
1.141 + {
1.142 + iGc.WriteInt(iPendingDrawMode,EWsGcOpSetDrawMode);
1.143 + iCurrentDrawMode = iPendingDrawMode;
1.144 + }
1.145 + }
1.146 +
1.147 + if (iPendingState & EStateBrushStyle)
1.148 + {
1.149 + if (iPendingBrushStyle != iCurrentBrushStyle)
1.150 + {
1.151 + iGc.WriteInt(iPendingBrushStyle,EWsGcOpSetBrushStyle);
1.152 + iCurrentBrushStyle = iPendingBrushStyle;
1.153 + }
1.154 + }
1.155 +
1.156 + if (iPendingState & EStateBrushColor)
1.157 + {
1.158 + // Brush colour optimisation more conservative (than for other state changes) because server-side code modifies it without client's knowledge
1.159 + if (iPendingBrushColor != iCurrentBrushColor || iForceWrite)
1.160 + {
1.161 + iGc.WriteInt(iPendingBrushColor.Internal(),EWsGcOpSetBrushColor);
1.162 + iCurrentBrushColor = iPendingBrushColor;
1.163 + iForceWrite = EFalse;
1.164 + }
1.165 + }
1.166 +
1.167 + if (iPendingState & EStatePenStyle)
1.168 + {
1.169 + if (iPendingPenStyle != iCurrentPenStyle)
1.170 + {
1.171 + iGc.WriteInt(iPendingPenStyle,EWsGcOpSetPenStyle);
1.172 + iCurrentPenStyle = iPendingPenStyle;
1.173 + }
1.174 + }
1.175 +
1.176 + if (iPendingState & EStatePenColor)
1.177 + {
1.178 + if (iPendingPenColor != iCurrentPenColor)
1.179 + {
1.180 + iGc.WriteInt(iPendingPenColor.Internal(),EWsGcOpSetPenColor);
1.181 + iCurrentPenColor = iPendingPenColor;
1.182 + }
1.183 + }
1.184 +
1.185 + if (iPendingState & EStateClippingRect)
1.186 + {
1.187 + iGc.WriteRect(iPendingClippingRect,EWsGcOpSetClippingRect);
1.188 + iClippingRectSet = ETrue;
1.189 + }
1.190 +
1.191 + if (iPendingState & EStateUnderlineStyle)
1.192 + {
1.193 + if (iPendingUnderlineStyle != iCurrentUnderlineStyle)
1.194 + {
1.195 + iGc.WriteInt(iPendingUnderlineStyle,EWsGcOpSetUnderlineStyle);
1.196 + iCurrentUnderlineStyle = iPendingUnderlineStyle;
1.197 + }
1.198 + }
1.199 +
1.200 + if (iPendingState & EStateStrikethroughStyle)
1.201 + {
1.202 + if (iPendingStrikethroughStyle != iCurrentStrikethroughStyle)
1.203 + {
1.204 + iGc.WriteInt(iPendingStrikethroughStyle,EWsGcOpSetStrikethroughStyle);
1.205 + iCurrentStrikethroughStyle = iPendingStrikethroughStyle;
1.206 + }
1.207 + }
1.208 +
1.209 + if (iPendingState & EStatePenSize)
1.210 + {
1.211 + if (iPendingPenSize != iCurrentPenSize)
1.212 + {
1.213 + iGc.WriteSize(iPendingPenSize,EWsGcOpSetPenSize);
1.214 + iCurrentPenSize = iPendingPenSize;
1.215 + }
1.216 + }
1.217 +
1.218 + if (iPendingState & EStateWordJustification)
1.219 + {
1.220 + if (iPendingWordJustification.excessWidth != iCurrentWordJustification.excessWidth
1.221 + || iPendingWordJustification.numGaps != iCurrentWordJustification.numGaps)
1.222 + {
1.223 + iGc.Write(&iPendingWordJustification,sizeof(iPendingWordJustification),EWsGcOpSetWordJustification);
1.224 + iCurrentWordJustification = iPendingWordJustification;
1.225 + }
1.226 + }
1.227 +
1.228 + if (iPendingState & EStateCharJustification)
1.229 + {
1.230 + if (iPendingCharJustification.excessWidth != iCurrentCharJustification.excessWidth
1.231 + || iPendingCharJustification.numGaps != iCurrentCharJustification.numGaps)
1.232 + {
1.233 + iGc.Write(&iPendingCharJustification,sizeof(iPendingCharJustification),EWsGcOpSetCharJustification);
1.234 + iCurrentCharJustification = iPendingCharJustification;
1.235 + }
1.236 + }
1.237 +
1.238 + iPendingState = 0;
1.239 + }
1.240 +
1.241 +void CWindowGc::CPimpl::ResetPendingState()
1.242 + {
1.243 + // This function should only be called from CWindowGc::Reset()
1.244 + iForceWrite = EFalse;
1.245 + iPendingState = 0;
1.246 +
1.247 + iClippingRectSet = EFalse;
1.248 +
1.249 + // The following default values are the same as those used by CFbsBitGc::Reset()
1.250 + iPendingBrushColor = KRgbWhite;
1.251 + iPendingBrushStyle = CGraphicsContext::ENullBrush;
1.252 + iPendingPenColor = KRgbBlack;
1.253 + iPendingPenStyle = CGraphicsContext::ESolidPen;
1.254 + iPendingPenSize = TSize(1,1);
1.255 + iPendingDrawMode = CGraphicsContext::EDrawModePEN;
1.256 + iPendingUnderlineStyle = EUnderlineOff;
1.257 + iPendingStrikethroughStyle = EStrikethroughOff;
1.258 + iPendingWordJustification.excessWidth = 0;
1.259 + iPendingWordJustification.numGaps = 0;
1.260 + iPendingCharJustification.excessWidth = 0;
1.261 + iPendingCharJustification.numGaps = 0;
1.262 +
1.263 + iCurrentBrushColor = iPendingBrushColor;
1.264 + iCurrentBrushStyle = iPendingBrushStyle;
1.265 + iCurrentPenColor = iPendingPenColor;
1.266 + iCurrentPenStyle = iPendingPenStyle;
1.267 + iCurrentPenSize = iPendingPenSize;
1.268 + iCurrentDrawMode = iPendingDrawMode;
1.269 + iCurrentUnderlineStyle = iPendingUnderlineStyle;
1.270 + iCurrentStrikethroughStyle = iPendingStrikethroughStyle;
1.271 + iCurrentWordJustification.excessWidth = iPendingWordJustification.excessWidth;
1.272 + iCurrentWordJustification.numGaps = iPendingWordJustification.numGaps;
1.273 + iCurrentCharJustification.excessWidth = iPendingCharJustification.excessWidth;
1.274 + iCurrentCharJustification.numGaps = iPendingCharJustification.numGaps;
1.275 + }
1.276 +
1.277 +void CWindowGc::CPimpl::StorePendingStateChange(TStateType aState, const TAny* aValue)
1.278 + {
1.279 + switch (aState)
1.280 + {
1.281 + case EStateBrushColor:
1.282 + iPendingState |= EStateBrushColor;
1.283 + iPendingBrushColor = *((TRgb*)(aValue));
1.284 + break;
1.285 + case EStateBrushStyle:
1.286 + iPendingState|=EStateBrushStyle;
1.287 + iPendingBrushStyle = *((TBrushStyle*)(aValue));
1.288 + break;
1.289 + case EStatePenColor:
1.290 + iPendingState|=EStatePenColor;
1.291 + iPendingPenColor = *((TRgb*)(aValue));
1.292 + break;
1.293 + case EStatePenStyle:
1.294 + iPendingState|=EStatePenStyle;
1.295 + iPendingPenStyle = *((TPenStyle*)(aValue));
1.296 + break;
1.297 + case EStateDrawMode:
1.298 + iPendingState|=EStateDrawMode;
1.299 + iPendingDrawMode = *((TDrawMode*)(aValue));
1.300 + break;
1.301 + case EStateClippingRect:
1.302 + iPendingState|=EStateClippingRect;
1.303 + iPendingClippingRect = *((TRect*)(aValue));
1.304 + break;
1.305 + case EStateUnderlineStyle:
1.306 + iPendingState|=EStateUnderlineStyle;
1.307 + iPendingUnderlineStyle = *((TFontUnderline*)(aValue));
1.308 + break;
1.309 + case EStateStrikethroughStyle:
1.310 + iPendingState|=EStateStrikethroughStyle;
1.311 + iPendingStrikethroughStyle= *((TFontStrikethrough*)(aValue));
1.312 + break;
1.313 + case EStatePenSize:
1.314 + iPendingState|=EStatePenSize;
1.315 + iPendingPenSize = *((TSize*)(aValue));
1.316 + break;
1.317 + case EStateWordJustification:
1.318 + iPendingState|=EStateWordJustification;
1.319 + iPendingWordJustification = *((TWsGcCmdSetJustification*)(aValue));
1.320 + break;
1.321 + case EStateCharJustification:
1.322 + iPendingState|=EStateCharJustification;
1.323 + iPendingCharJustification = *((TWsGcCmdSetJustification*)(aValue));
1.324 + break;
1.325 + default:
1.326 + break;
1.327 + }
1.328 + }
1.329 +
1.330 +//
1.331 +// class CWindowGc
1.332 +//
1.333 +
1.334 +EXPORT_C CWindowGc::CWindowGc(CWsScreenDevice *aDevice) : MWsClientClass(aDevice->iBuffer), iPimpl(NULL), iDevice(aDevice)
1.335 +/** Constructor which creates, but does not initialise a graphics context.
1.336 +
1.337 +@param aDevice Any screen device owned by the same session. Its life time
1.338 +should be at least as long as the gc itself.
1.339 +@see CWsScreenDevice::CreateContext() */
1.340 + {}
1.341 +
1.342 +EXPORT_C CWindowGc::~CWindowGc()
1.343 +/** Destructor. */
1.344 + {
1.345 + if (iBuffer && iWsHandle)
1.346 + Write(EWsGcOpFree);
1.347 + delete iPimpl;
1.348 + }
1.349 +
1.350 +void CWindowGc::WriteTextCommand(TAny *cmd, TInt len,const TDesC &aBuf,TInt opcode,TInt opcodePtr) const
1.351 + {
1.352 + if ((aBuf.Size()+len)>(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)))
1.353 + {
1.354 + WriteReplyByProvidingRemoteReadAccess(cmd,len,&aBuf,opcodePtr);
1.355 + }
1.356 + else
1.357 + {
1.358 + Write(cmd,len,aBuf.Ptr(),aBuf.Size(),opcode);
1.359 + }
1.360 + }
1.361 +
1.362 +void CWindowGc::WriteTextCommand(TAny *cmd, TInt len,const TDesC8 &aBuf,TInt opcode,TInt opcodePtr) const
1.363 + {
1.364 + if ((aBuf.Size()+len)>(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)))
1.365 + {
1.366 + WriteReplyByProvidingRemoteReadAccess(cmd,len,&aBuf,opcodePtr);
1.367 + }
1.368 + else
1.369 + {
1.370 + Write(cmd,len,aBuf.Ptr(),aBuf.Size(),opcode);
1.371 + }
1.372 + }
1.373 +
1.374 +EXPORT_C TInt CWindowGc::Construct()
1.375 +/** Completes construction.
1.376 +
1.377 +@return KErrNone if successful, otherwise a leave error.
1.378 +@panic TW32Panic 17 in debug builds if called on an already constructed object.
1.379 +This function always causes a flush of the window server buffer. */
1.380 + {
1.381 + __ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction));
1.382 + iPimpl = new CPimpl(*this);
1.383 + if (!iPimpl)
1.384 + return KErrNoMemory;
1.385 + TInt ret;
1.386 + if ((ret=iBuffer->WriteReplyWs(EWsClOpCreateGc))<0)
1.387 + return(ret);
1.388 + iWsHandle=ret;
1.389 + return(KErrNone);
1.390 + }
1.391 +
1.392 +EXPORT_C void CWindowGc::Activate(RDrawableWindow &aDevice)
1.393 +/** Activates the context for a given window and updates iDevice with the pointer to the screen device of the screen on which aDevice is found.
1.394 +
1.395 +When drawing is complete, the code using the context should call Deactivate().
1.396 +Draw methods invoked after an Activate() will affect the window specified.
1.397 +A graphics context can only be active for one window at a time. A panic occurs
1.398 +if a draw function is called before calling this function, or if Activate()
1.399 +is called twice without an intervening Deactivate().
1.400 +
1.401 +@param aWindow The window for which the graphics context is to be activated. */
1.402 + {
1.403 + TUint devicePointer = WriteReplyInt(aDevice.WsHandle(),EWsGcOpActivate);
1.404 + iDevice = (CWsScreenDevice*)devicePointer;
1.405 + iPimpl->iForceWrite = ETrue; // needed because brush colour set to window background colour in CWsGc::Activate
1.406 + }
1.407 +
1.408 +EXPORT_C void CWindowGc::Deactivate()
1.409 +/** Frees the graphics context to be used with another window.
1.410 +
1.411 +This method should be called when the application has completed drawing to
1.412 +the window. */
1.413 + {
1.414 + iPimpl->ResetPendingState(); // needed because server-side state is reset on deactivation
1.415 + Write(EWsGcOpDeactivate);
1.416 + iPimpl->iFont=NULL;
1.417 + iPimpl->iShadowColor = KDefaultShadowColor;
1.418 + }
1.419 +
1.420 +//====================Functions from GDI.H===============================
1.421 +
1.422 +EXPORT_C CGraphicsDevice* CWindowGc::Device() const
1.423 +/** Returns a pointer to the device, more specifically a CWsScreenDevice, for the screen that the WindowGc was last activated on.
1.424 +If the WindowGc has not been activated at all, it then returns the device that was passed to its constructor.
1.425 +
1.426 +The user should be careful when calling this function since it can return the screen device of any screen in the system.
1.427 +Hence, the return value of this function will be useful only if the user is aware of how the WindowGc was used before this function is called.
1.428 +@return A pointer to the device for the screen that the WindowGc was last activated on or the device passed at construction*/
1.429 + {
1.430 + return(iDevice);
1.431 + }
1.432 +
1.433 +EXPORT_C void CWindowGc::SetOrigin(const TPoint &aPoint)
1.434 +/** Sets the position of the co-ordinate origin.
1.435 +
1.436 +All subsequent drawing operations are then done relative to this origin. The
1.437 +default origin is (0,0), the top left corner of the window.
1.438 +
1.439 +@param aPoint A point for the origin, default (0,0).
1.440 +@see CGraphicsContext::SetOrigin() */
1.441 + {
1.442 + if ( iPimpl->GetState() & CPimpl::EStateClippingRect )
1.443 + {
1.444 + iPimpl->WriteAnyPendingStateChanges();
1.445 + }
1.446 + WritePoint(aPoint,EWsGcOpSetOrigin);
1.447 + }
1.448 +
1.449 +EXPORT_C void CWindowGc::SetClippingRect(const TRect& aRect)
1.450 +/** Sets a clipping rectangle.
1.451 +
1.452 +Graphics drawn to the window are clipped, so that only items which fall within
1.453 +the rectangle are displayed.
1.454 +
1.455 +Note that clipping is additive. If a clipping region has been set using SetClippingRegion()
1.456 +then clipping will be to the intersection of that region and this rectangle.
1.457 +
1.458 +@param aRect The clipping rectangle in window co-ordinates. Note that this rectangle is
1.459 +tranformed by the current drawing co-ordinate origin before it is used.
1.460 +The co-ordinate origin is set using SetOrigin().
1.461 +
1.462 +@see SetClippingRegion() */
1.463 + {
1.464 + TRect rect(aRect);
1.465 + iPimpl->StorePendingStateChange(CPimpl::EStateClippingRect, &rect);
1.466 + }
1.467 +
1.468 +EXPORT_C void CWindowGc::CancelClippingRect()
1.469 +/** Cancels the clipping rectangle.
1.470 +
1.471 +@see SetClippingRect() */
1.472 + {
1.473 + if (iPimpl->GetState() & CPimpl::EStateClippingRect)
1.474 + {
1.475 + iPimpl->CancelPendingClippingRect();
1.476 + }
1.477 +
1.478 + if (iPimpl->iClippingRectSet)
1.479 + {
1.480 + Write(EWsGcOpCancelClippingRect);
1.481 + }
1.482 +
1.483 + iPimpl->iClippingRectSet = EFalse;
1.484 + }
1.485 +
1.486 +EXPORT_C TInt CWindowGc::SetClippingRegion(const TRegion &aRegion)
1.487 +/** Sets the clipping region.
1.488 +
1.489 +Drawing is always clipped to the visible area of a window. The region specified
1.490 +by this function is in addition to that area.
1.491 +
1.492 +This function always causes a flush of the window server buffer.
1.493 +
1.494 +@param aRegion The new clipping region in window co-ordinates
1.495 +as used in SetClippingRect(). The clipping region is transformed by the current
1.496 +drawing origin before use.
1.497 +
1.498 +@return KErrNone if successful, KErrNoMemory if there is insufficient memory
1.499 +to create the region on the server side, otherwise another error code.
1.500 +
1.501 +@see SetClippingRect() */
1.502 + {
1.503 + const TInt regionCount=aRegion.Count();
1.504 + TPtrC8 ptrRect(reinterpret_cast<const TUint8*>(aRegion.RectangleList()),regionCount*sizeof(TRect));
1.505 + return(WriteReplyByProvidingRemoteReadAccess(®ionCount,sizeof(regionCount),&ptrRect,EWsGcOpSetClippingRegion));
1.506 + }
1.507 +
1.508 +EXPORT_C void CWindowGc::CancelClippingRegion()
1.509 +/** Cancels the current clipping region. */
1.510 + {
1.511 + Write(EWsGcOpCancelClippingRegion);
1.512 + }
1.513 +
1.514 +EXPORT_C void CWindowGc::SetDrawMode(TDrawMode aDrawingMode)
1.515 +/** Sets the drawing mode.
1.516 +
1.517 +This affects the colour that is actually drawn, because it defines the way
1.518 +that the current screen colour logically combines with the current pen colour
1.519 +and brush colour.
1.520 +
1.521 +There are 13 drawing modes (see CGraphicsContext::TDrawMode enum), each giving
1.522 +different logical combinations of pen, brush and screen colours. Each mode
1.523 +is produced by ORing together different combinations of seven drawing mode
1.524 +components (see CGraphicsContext::TDrawModeComponents enum).
1.525 +
1.526 +The three most important modes are TDrawMode::EDrawModePEN, TDrawMode::EDrawModeNOTSCREEN
1.527 +and TDrawMode::EDrawModeXOR. The default drawing mode is TDrawMode::EDrawModePEN.
1.528 +
1.529 +The drawing mode is over-ridden for line and shape drawing functions when
1.530 +a wide pen line has been selected. It is forced to TDrawMode::EDrawModePEN.
1.531 +This is to prevent undesired effects at line joins (vertexes).
1.532 +
1.533 +Notes:
1.534 +
1.535 +TDrawMode::EDrawModeAND gives a "colour filter" effect. For example:
1.536 +
1.537 +ANDing with white gives the original colour
1.538 +
1.539 +ANDing with black gives black
1.540 +
1.541 +TDrawMode::EDrawModeOR gives a "colour boost" effect. For example:
1.542 +
1.543 +ORing with black gives the original colour
1.544 +
1.545 +ORing with white gives white
1.546 +
1.547 +TDrawMode::EDrawModeXOR gives an "Exclusive OR" effect. For example:
1.548 +
1.549 +white XOR black gives white
1.550 +
1.551 +white XOR white gives black
1.552 +
1.553 +black XOR black gives black
1.554 +
1.555 +@param aDrawingMode A drawing mode.
1.556 +@see CGraphicsContext::SetDrawMode() */
1.557 + {
1.558 + iPimpl->StorePendingStateChange(CPimpl::EStateDrawMode, &aDrawingMode);
1.559 + }
1.560 +
1.561 +EXPORT_C void CWindowGc::UseFont(const CFont *aFont)
1.562 +/** Sets this context's font.
1.563 +
1.564 +The font is used for text drawing. If the font is already in the font and
1.565 +bitmap server's memory the GDI will share that copy.
1.566 +
1.567 +Note that this function must be called prior to drawing text or the calling
1.568 +thread will panic.
1.569 +
1.570 +@param aFont A device font.
1.571 +@see CGraphicsContext::UseFont() */
1.572 + {
1.573 + if (iPimpl->iFont!=(CFbsFont *)aFont)
1.574 + {
1.575 + iPimpl->iFont=(CFbsFont *)aFont;
1.576 + WriteInt(iPimpl->iFont->Handle(),EWsGcOpUseFont);
1.577 + }
1.578 + }
1.579 +
1.580 +EXPORT_C void CWindowGc::DiscardFont()
1.581 +/** Discards a font.
1.582 +
1.583 +This frees up the memory used (if the font is not being shared with some other
1.584 +process).
1.585 +
1.586 +Note that if no font is in use when this function is called, then there is no effect.
1.587 +
1.588 +@see CGraphicsContext::DiscardFont() */
1.589 + {
1.590 + Write(EWsGcOpDiscardFont);
1.591 + iPimpl->iFont=NULL;
1.592 + }
1.593 +
1.594 +EXPORT_C void CWindowGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
1.595 +/** Sets the underline style for all subsequently drawn text.
1.596 +
1.597 +@param aUnderlineStyle The underline style: either on or off.
1.598 +@see CGraphicsContext::SetUnderlineStyle() */
1.599 + {
1.600 + iPimpl->StorePendingStateChange(CPimpl::EStateUnderlineStyle, &aUnderlineStyle);
1.601 + }
1.602 +
1.603 +EXPORT_C void CWindowGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
1.604 +/** Sets the strikethrough style for all subsequently drawn text.
1.605 +
1.606 +@param aStrikethroughStyle The strikethrough style: either on or off.
1.607 +@see CGraphicsContext::SetStrikethroughStyle() */
1.608 + {
1.609 + iPimpl->StorePendingStateChange(CPimpl::EStateStrikethroughStyle, &aStrikethroughStyle);
1.610 + }
1.611 +
1.612 +void CWindowGc::SetJustification(TInt aExcessWidth,TInt aNumGaps, TInt aOpcode)
1.613 + {
1.614 + TWsGcCmdSetJustification justification;
1.615 +
1.616 + justification.excessWidth=aExcessWidth;
1.617 + justification.numGaps=aNumGaps;
1.618 +
1.619 + if (aOpcode == EWsGcOpSetWordJustification)
1.620 + {
1.621 + iPimpl->StorePendingStateChange(CPimpl::EStateWordJustification, &justification);
1.622 + }
1.623 + else if (aOpcode == EWsGcOpSetCharJustification)
1.624 + {
1.625 + iPimpl->StorePendingStateChange(CPimpl::EStateCharJustification, &justification);
1.626 + }
1.627 + }
1.628 +
1.629 +EXPORT_C void CWindowGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps)
1.630 +/** Sets word justification.
1.631 +
1.632 +This function is particularly useful for doing WYSIWYG underlining or strikethrough,
1.633 +as it ensures that the lines extend correctly into the gaps between words. It is not
1.634 +intended for regular use by developers.
1.635 +
1.636 +@param aExcessWidth The excess width (in pixels) to be distributed between
1.637 +the specified number of gaps (starting immediately)
1.638 +@param aNumGaps The number of gaps between words
1.639 +@see CGraphicsContext::SetWordJustification() */
1.640 + {
1.641 + SetJustification(aExcessWidth, aNumGaps, EWsGcOpSetWordJustification);
1.642 + }
1.643 +
1.644 +EXPORT_C void CWindowGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars)
1.645 +/** Sets the character justification.
1.646 +
1.647 +This function is used primarily to get accurate WYSIWYG, and is not intended
1.648 +for regular use by developers.
1.649 +
1.650 +The text line that is to be justified has a certain number of characters (this
1.651 +includes the spaces between the words). It also has a distance (in pixels)
1.652 +between the end of the last word and the actual end of the line (right hand
1.653 +margin, usually). These excess width pixels are distributed amongst all the
1.654 +characters, increasing the gaps between them, to achieve full justification
1.655 +of the text line.
1.656 +
1.657 +This function is particularly useful for WYSIWYG underlining or strikethrough,
1.658 +as it ensures that the lines extend into the gaps between characters.
1.659 +
1.660 +See CGraphicsContext::SetCharJustification() for more information.
1.661 +
1.662 +@param aExcessWidth The excess width (in pixels) to be distributed between
1.663 +the specified number of characters.
1.664 +@param aNumChars The number of characters involved
1.665 +@see CGraphicsContext::SetCharJustification() */
1.666 + {
1.667 + SetJustification(aExcessWidth, aNumChars, EWsGcOpSetCharJustification);
1.668 + }
1.669 +
1.670 +EXPORT_C void CWindowGc::SetPenColor(const TRgb &aColor)
1.671 +/** Sets the pen colour.
1.672 +
1.673 +The effective pen colour depends on the drawing mode (see SetDrawMode()).
1.674 +
1.675 +The default pen colour is black.
1.676 +
1.677 +@param aColor The RGB colour for the pen.
1.678 +@see CGraphicsContext::SetPenColor() */
1.679 + {
1.680 + TRgb color = aColor;
1.681 + iPimpl->StorePendingStateChange(CPimpl::EStatePenColor, &color);
1.682 + }
1.683 +
1.684 +EXPORT_C void CWindowGc::SetPenStyle(TPenStyle aPenStyle)
1.685 +/** Sets the line drawing style for the pen.
1.686 +
1.687 +The pen is used when drawing lines and for the outline of filled shapes. There
1.688 +are 6 pen styles (see CGraphicsContext::TPenStyle enum). If no pen style is
1.689 +set, the default is TPenStyle::ESolidPen.
1.690 +
1.691 +To use a pen style, its full context must be given, e.g. for a null pen: CGraphicsContext::TPenStyle::ENullPen.
1.692 +
1.693 +@param aPenStyle A pen style.
1.694 +@see CGraphicsContext::SetPenStyle() */
1.695 + {
1.696 + iPimpl->StorePendingStateChange(CPimpl::EStatePenStyle, &aPenStyle);
1.697 + }
1.698 +
1.699 +EXPORT_C void CWindowGc::SetPenSize(const TSize& aSize)
1.700 +/** Sets the line drawing size for the pen.
1.701 +
1.702 +Lines of size greater than one pixel are drawn with rounded ends that extend
1.703 +beyond the end points, (as if the line is drawn using a circular pen tip of
1.704 +the specified size). Rounded ends of lines drawn with a wide pen are always
1.705 +drawn in TDrawMode::EDrawModePEN mode, overriding whatever mode has been set
1.706 +using SetDrawMode().
1.707 +
1.708 +@param aSize A line size, the default being 1 pixel.
1.709 +@see CGraphicsContext::SetPenSize() */
1.710 + {
1.711 + TSize size(aSize);
1.712 + iPimpl->StorePendingStateChange(CPimpl::EStatePenSize, &size);
1.713 + }
1.714 +
1.715 +EXPORT_C void CWindowGc::SetBrushColor(const TRgb &aColor)
1.716 +/** Sets the brush colour.
1.717 +
1.718 +The effective brush colour depends on the drawing mode (see SetDrawMode()).
1.719 +If no brush colour has been set, it defaults to white. However the default
1.720 +brush style is null, so when drawing to a window, the default appears to be
1.721 +the window's background colour.
1.722 +
1.723 +@param aColor The RGB colour for the brush.
1.724 +@see CGraphicsContext::SetBrushColor() */
1.725 + {
1.726 + TRgb color = aColor;
1.727 + iPimpl->StorePendingStateChange(CPimpl::EStateBrushColor, &color);
1.728 + }
1.729 +
1.730 +EXPORT_C void CWindowGc::SetBrushStyle(TBrushStyle aBrushStyle)
1.731 +/** Sets the line drawing style for the brush.
1.732 +
1.733 +The GDI provides ten brush styles, including six built-in hatching patterns
1.734 +(see CGraphicsContext::TBrushStyle).
1.735 +
1.736 +Use TBrushStyle::ENullBrush to draw the outline of a fillable shape on its
1.737 +own, without filling.
1.738 +
1.739 +If the TBrushStyle::EPatternedBrush style is set, but no bitmap pattern has
1.740 +been selected using UseBrushPattern(), then the brush defaults to TBrushStyle::ENullBrush.
1.741 +
1.742 +Hatching lines are done in the current brush colour, set using SetBrushColor().
1.743 +Hatching can be overlaid on other graphics. The hatching pattern starts at
1.744 +the brush origin, set using SetBrushOrigin().
1.745 +
1.746 +@param aBrushStyle The brush style.
1.747 +@see CGraphicsContext::SetBrushStyle() */
1.748 + {
1.749 + iPimpl->StorePendingStateChange(CPimpl::EStateBrushStyle, &aBrushStyle);
1.750 + }
1.751 +EXPORT_C void CWindowGc::SetBrushOrigin(const TPoint &aOrigin)
1.752 +/** Sets the brush pattern origin.
1.753 +
1.754 +This specifies the position of the pixel in the top left corner of a reference
1.755 +pattern tile, (in absolute device co-ordinates). Other copies of the pattern
1.756 +tile are then drawn around the reference one. Thus the brush origin can be
1.757 +set as the top left corner of a shape.
1.758 +
1.759 +The brush pattern may be a built-in style (see SetBrushStyle()), or a bitmap.
1.760 +To use a bitmap, the brush must have a pattern set (see UseBrushPattern())
1.761 +and the brush style must be set to TBrushStyle::EPatternedBrush.
1.762 +
1.763 +Notes:
1.764 +
1.765 +If SetBrushOrigin() is not used, then the origin defaults to (0,0).
1.766 +
1.767 +This brush origin remains in effect for all fillable shapes drawn subsequently,
1.768 +until a new brush origin is set. Shapes can thus be considered as windows
1.769 +onto a continuous pattern field (covering the whole clipping region of a screen
1.770 +device, or the whole device area of a printer).
1.771 +
1.772 +@param aOrigin The origin point for the brush.
1.773 +@see CGraphicsContext::SetBrushOrigin() */
1.774 + {
1.775 + WritePoint(aOrigin,EWsGcOpSetBrushOrigin);
1.776 + }
1.777 +
1.778 +EXPORT_C void CWindowGc::UseBrushPattern(const CFbsBitmap *aDevice)
1.779 +/** Sets the brush pattern to the specified bitmap.
1.780 +
1.781 +For the brush to actually use the bitmap, TBrushStyle::EPatternedBrush must
1.782 +be used to set the brush style (see SetBrushStyle()). When the brush pattern
1.783 +is no longer required, use DiscardBrushPattern() to free up the memory used,
1.784 +(if the bitmap is not being shared). If UseBrushPattern() is used again without
1.785 +using DiscardBrushPattern() then the previous pattern is discarded automatically.
1.786 +
1.787 +Notes:
1.788 +
1.789 +When loading a bitmap, the GDI checks to see if the bitmap is already in memory.
1.790 +If the bitmap is already there, then that copy is shared.
1.791 +
1.792 +The brush does not need to have a pattern set at all. There are several built-in
1.793 +hatching patterns, which can be selected using SetBrushStyle().
1.794 +
1.795 +@param aDevice A bitmap pattern for the brush
1.796 +@see CGraphicsContext::UseBrushPattern() */
1.797 + {
1.798 + WriteInt(aDevice->Handle(),EWsGcOpUseBrushPattern);
1.799 + AddToBitmapArray(aDevice->Handle());
1.800 + }
1.801 +
1.802 +EXPORT_C void CWindowGc::DiscardBrushPattern()
1.803 +/** Discards a non-built-in brush pattern.
1.804 +
1.805 +This frees up the memory used for the bitmap, if it is not being shared by
1.806 +another process.
1.807 +
1.808 +If no brush pattern has been set when this function is called, it has no effect.
1.809 +
1.810 +@see CGraphicsContext::DiscardBrushPattern() */
1.811 + {
1.812 + Write(EWsGcOpDiscardBrushPattern);
1.813 + }
1.814 +
1.815 +EXPORT_C void CWindowGc::Plot(const TPoint &aPoint)
1.816 +/** Draws a single point.
1.817 +
1.818 +The point is drawn with the current pen settings using the current drawing
1.819 +mode.
1.820 +
1.821 +Note: if the pen size is greater than one pixel, a filled circle of the current
1.822 +pen colour is drawn, with the pen size as the diameter and the plotted point
1.823 +as the centre. If the pen size is an even number of pixels, the extra pixels
1.824 +are drawn below and to the right of the centre. See SetPenSize().
1.825 +
1.826 +@param aPoint The point to be drawn.
1.827 +@see CGraphicsContext::Plot() */
1.828 + {
1.829 + iPimpl->WriteAnyPendingStateChanges();
1.830 + WritePoint(aPoint,EWsGcOpPlot);
1.831 + }
1.832 +
1.833 +EXPORT_C void CWindowGc::DrawLine(const TPoint &aPoint1,const TPoint &aPoint2)
1.834 +/** Draws a straight line between two points.
1.835 +
1.836 +@param aPoint1 The point at the start of the line.
1.837 +@param aPoint2 The point at the end of the line.
1.838 +@see CGraphicsContext::DrawLine() */
1.839 + {
1.840 + iPimpl->WriteAnyPendingStateChanges();
1.841 + TWsGcCmdDrawLine drawLine(aPoint1,aPoint2);
1.842 + Write(&drawLine,sizeof(drawLine),EWsGcOpDrawLine);
1.843 + }
1.844 +
1.845 +EXPORT_C void CWindowGc::MoveTo(const TPoint &aPoint)
1.846 +/** Moves the internal drawing position relative to the co-ordinate origin, without
1.847 +drawing a line.
1.848 +
1.849 +A subsequent call to DrawLineTo() or DrawLineBy() will then use the new internal
1.850 +drawing position as the start point for the line drawn.
1.851 +
1.852 +Notes:
1.853 +
1.854 +The operations DrawLine(), DrawLineTo(), DrawLineBy() and DrawPolyline() also
1.855 +change the internal drawing position to the last point of the drawn line(s).
1.856 +
1.857 +The internal drawing position is set to the co-ordinate origin if no drawing
1.858 +or moving operations have yet taken place.
1.859 +
1.860 +@param aPoint The point to move the internal drawing position to.
1.861 +@see CGraphicsContext::MoveTo()
1.862 +@see CGraphicsContext::MoveBy() */
1.863 + {
1.864 + WritePoint(aPoint,EWsGcOpMoveTo);
1.865 + }
1.866 +
1.867 +EXPORT_C void CWindowGc::MoveBy(const TPoint &aPoint)
1.868 +/** Moves the internal drawing position by a vector, without drawing a line.
1.869 +
1.870 +The internal drawing position is moved relative to its current co-ordinates.
1.871 +
1.872 +@param aPoint The vector to move the internal drawing position by.
1.873 +@see CGraphicsContext::MoveBy()
1.874 +@see CGraphicsContext::MoveTo() */
1.875 + {
1.876 + WritePoint(aPoint,EWsGcOpMoveBy);
1.877 + }
1.878 +
1.879 +EXPORT_C void CWindowGc::DrawLineTo(const TPoint &aPoint)
1.880 +/** Draws a straight line from the current internal drawing position to a point.
1.881 +
1.882 +@param aPoint The point at the end of the line.
1.883 +@see CGraphicsContext::DrawLineTo() */
1.884 + {
1.885 + iPimpl->WriteAnyPendingStateChanges();
1.886 + WritePoint(aPoint,EWsGcOpDrawTo);
1.887 + }
1.888 +
1.889 +EXPORT_C void CWindowGc::DrawLineBy(const TPoint &aPoint)
1.890 +/** Draws a straight line relative to the current internal drawing position, using
1.891 +a vector.
1.892 +
1.893 +The start point of the line is the current internal drawing position. The
1.894 +vector aVector is added to the internal drawing position to give the end point
1.895 +of the line
1.896 +
1.897 +@param aPoint The vector to add to the current internal drawing position,
1.898 +giving the end point of the line.
1.899 +@see CGraphicsContext::DrawLineBy() */
1.900 + {
1.901 + iPimpl->WriteAnyPendingStateChanges();
1.902 + WritePoint(aPoint,EWsGcOpDrawBy);
1.903 + }
1.904 +
1.905 +void CWindowGc::doDrawPolyLine(const CArrayFix<TPoint> *aPointArray, const TPoint* aPointList,TInt aNumPoints)
1.906 + {
1.907 + TWsGcOpcodes opcode=EWsGcOpDrawPolyLine;
1.908 + TWsGcCmdDrawPolyLine polyLine;
1.909 + TInt maxBufLen=(iBuffer->BufferSize()-sizeof(TWsCmdHeader)-sizeof(polyLine))/sizeof(TPoint);
1.910 + TInt sent=0;
1.911 + while(sent<aNumPoints)
1.912 + {
1.913 + TInt availableLen;
1.914 + const TPoint *ptr;
1.915 + if (aPointArray)
1.916 + {
1.917 + ptr=&(*aPointArray)[sent];
1.918 + availableLen=aPointArray->End(sent)-ptr;
1.919 + }
1.920 + else
1.921 + {
1.922 + ptr=aPointList+sent;
1.923 + availableLen=aNumPoints-sent;
1.924 + }
1.925 + polyLine.numPoints=Min(availableLen,maxBufLen);
1.926 + sent+=polyLine.numPoints;
1.927 + polyLine.more=(sent!=aNumPoints);
1.928 + Write(&polyLine,sizeof(polyLine),ptr,polyLine.numPoints*sizeof(TPoint),opcode);
1.929 + polyLine.last=ptr[polyLine.numPoints-1];
1.930 + opcode=EWsGcOpDrawPolyLineContinued;
1.931 + }
1.932 + }
1.933 +
1.934 +EXPORT_C void CWindowGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
1.935 +/** Draws a polyline using points in a list.
1.936 +
1.937 +A polyline is a series of concatenated straight lines joining a set of points.
1.938 +
1.939 +@param aPointList Pointer to a list of points on the polyline.
1.940 +@param aNumPoints The number of points in the point list.
1.941 +@see CGraphicsContext::DrawPolyLine() */
1.942 + {
1.943 + iPimpl->WriteAnyPendingStateChanges();
1.944 + doDrawPolyLine(NULL,aPointList,aNumPoints);
1.945 + }
1.946 +
1.947 +EXPORT_C void CWindowGc::DrawPolyLine(const CArrayFix<TPoint> *aPointArray)
1.948 +/** Draws a polyline using points in an array.
1.949 +
1.950 +A polyline is a series of concatenated straight lines joining a set of points.
1.951 +
1.952 +@param aPointArray An array containing the points on the polyline.
1.953 +@see CGraphicsContext::DrawPolyLine() */
1.954 + {
1.955 + iPimpl->WriteAnyPendingStateChanges();
1.956 + doDrawPolyLine(aPointArray,NULL,aPointArray->Count());
1.957 + }
1.958 +
1.959 +TInt CWindowGc::doDrawPolygon(const CArrayFix<TPoint> *aPointArray,const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
1.960 + {
1.961 + if (aNumPoints<=0)
1.962 + return(KErrNone);
1.963 + TWsGcCmdSegmentedDrawPolygonData polyData;
1.964 + polyData.index=0;
1.965 + TInt maxBufLen=(iBuffer->BufferSize()-EPolygonMaxHeaderSize)/sizeof(TPoint);
1.966 + FOREVER
1.967 + {
1.968 + const TPoint *ptr;
1.969 + TInt availableLen;
1.970 + if (aPointArray)
1.971 + {
1.972 + ptr=&(*aPointArray)[polyData.index];
1.973 + availableLen=aPointArray->End(polyData.index)-ptr;
1.974 + }
1.975 + else
1.976 + {
1.977 + ptr=aPointList+polyData.index;
1.978 + availableLen=aNumPoints-polyData.index;
1.979 + }
1.980 + polyData.numPoints=Min(availableLen,maxBufLen);
1.981 + if (polyData.index==0) // First time around
1.982 + {
1.983 + if (polyData.numPoints==aNumPoints) // Can it be done in one go?
1.984 + {
1.985 + TWsGcCmdDrawPolygon drawPolygon;
1.986 + drawPolygon.numPoints=aNumPoints;
1.987 + drawPolygon.fillRule=aFillRule;
1.988 + Write(&drawPolygon,sizeof(drawPolygon),ptr,aNumPoints*sizeof(TPoint),EWsGcOpDrawPolygon);
1.989 + break;
1.990 + }
1.991 + TWsGcCmdStartSegmentedDrawPolygon start;
1.992 + start.totalNumPoints=aNumPoints;
1.993 + TInt err=WriteReply(&start,sizeof(start),EWsGcOpStartSegmentedDrawPolygon);
1.994 + if (err!=KErrNone)
1.995 + return(err);
1.996 + }
1.997 + Write(&polyData,sizeof(polyData),ptr,polyData.numPoints*sizeof(TPoint),EWsGcOpSegmentedDrawPolygonData);
1.998 + polyData.index+=polyData.numPoints;
1.999 + if (polyData.index==aNumPoints)
1.1000 + {
1.1001 + TWsGcCmdDrawSegmentedPolygon draw;
1.1002 + draw.fillRule=aFillRule;
1.1003 + Write(&draw,sizeof(draw),EWsGcOpDrawSegmentedPolygon);
1.1004 + break;
1.1005 + }
1.1006 + }
1.1007 + return(KErrNone);
1.1008 + }
1.1009 +
1.1010 +EXPORT_C TInt CWindowGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
1.1011 +/** Draws and fills a polygon using points defined in a list.
1.1012 +
1.1013 +The first TPoint in the list defines the start of the first side of the polygon.
1.1014 +The second TPoint defines the second vertex (the end point of the first side
1.1015 +and the start point of the second side) and so on. The final side of the polygon
1.1016 +is drawn using the last TPoint from the array or list, and the line drawn
1.1017 +to the start point of the first side.
1.1018 +
1.1019 +Self-crossing polygons can be filled according to one of two rules, TFillRule::EAlternate
1.1020 +(the default), or TFillRule::EWinding. To explain the difference between these
1.1021 +rules, the concept of a winding number needs to be introduced. The area outside
1.1022 +any of the loops of the polygon has a winding number of zero, and is never
1.1023 +filled. An inside a loop which is bounded by an area with winding number 0
1.1024 +has a winding number of 1. If an area is within a loop that is bounded by
1.1025 +an area with winding number 1, e.g. a loop within a loop, has a winding number
1.1026 +of 2, and so on.
1.1027 +
1.1028 +The filling of a polygon proceeds according to this algorithm:
1.1029 +
1.1030 +If aFillRule is TFillRule::EAlternate (default) and it has an odd winding
1.1031 +number, then fill the surrounding area.
1.1032 +
1.1033 +If aFillRule is TFillRule::EWinding and it has a winding number greater than
1.1034 +zero, then fill the surrounding area.
1.1035 +
1.1036 +This function always causes a flush of the window server buffer.
1.1037 +
1.1038 +@param aPointList Pointer to a list of points, specifying the vertices of
1.1039 +the polygon.
1.1040 +@param aNumPoints The number of points in the vertex list
1.1041 +@param aFillRule Either TFillRule::EAlternate (the default) or TFillRule::EWinding.
1.1042 +@return KErrNone if successful, otherwise another of the system-wide error
1.1043 +codes.
1.1044 +@see CGraphicsContext::DrawPolygon() */
1.1045 + {
1.1046 + iPimpl->WriteAnyPendingStateChanges();
1.1047 + return(doDrawPolygon(NULL,aPointList,aNumPoints,aFillRule));
1.1048 + }
1.1049 +
1.1050 +EXPORT_C TInt CWindowGc::DrawPolygon(const CArrayFix<TPoint> *aPointArray,TFillRule aFillRule)
1.1051 +/** Draws and fills a polygon using points defined in an array.
1.1052 +
1.1053 +The first TPoint in the array defines the start of the first side of the polygon.
1.1054 +The second TPoint defines the second vertex (the end point of the first side
1.1055 +and the start point of the second side) and so on. The final side of the polygon
1.1056 +is drawn using the last TPoint from the array or list, and the line drawn
1.1057 +to the start point of the first side.
1.1058 +
1.1059 +Self-crossing polygons can be filled according to one of two rules, TFillRule::EAlternate
1.1060 +(the default), or TFillRule::EWinding. To explain the difference between these
1.1061 +rules, the concept of a winding number needs to be introduced. The area outside
1.1062 +any of the loops of the polygon has a winding number of zero, and is never
1.1063 +filled. An inside a loop which is bounded by an area with winding number 0
1.1064 +has a winding number of 1. If an area is within a loop that is bounded by
1.1065 +an area with winding number 1, e.g. a loop within a loop, has a winding number
1.1066 +of 2, and so on.
1.1067 +
1.1068 +The filling of a polygon proceeds according to this algorithm:
1.1069 +
1.1070 +If aFillRule is TFillRule::EAlternate (default) and it has an odd winding
1.1071 +number, then fill the surrounding area.
1.1072 +
1.1073 +If aFillRule is TFillRule::EWinding and it has a winding number greater than
1.1074 +zero, then fill the surrounding area.
1.1075 +
1.1076 +This function always causes a flush of the window server buffer.
1.1077 +
1.1078 +@param aPointArray An array of points, specifying the vertices of the polygon.
1.1079 +@param aFillRule Either TFillRule::EAlternate (the default) or TFillRule::EWinding.
1.1080 +@return KErrNone if successful, otherwise another of the system-wide error
1.1081 +codes.
1.1082 +@see CGraphicsContext::DrawPolygon() */
1.1083 + {
1.1084 + iPimpl->WriteAnyPendingStateChanges();
1.1085 + return(doDrawPolygon(aPointArray,NULL,aPointArray->Count(),aFillRule));
1.1086 + }
1.1087 +
1.1088 +void CWindowGc::DrawArcOrPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd, TInt aOpcode)
1.1089 + {
1.1090 + iPimpl->WriteAnyPendingStateChanges();
1.1091 + TWsGcCmdDrawArcOrPie cmd(aRect,aStart,aEnd);
1.1092 + Write(&cmd,sizeof(cmd),aOpcode);
1.1093 + }
1.1094 +
1.1095 +EXPORT_C void CWindowGc::DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
1.1096 +/** Draws an arc (a portion of an ellipse).
1.1097 +
1.1098 +The point aStart is used to define one end of a line from the geometric centre
1.1099 +of the ellipse. The point of intersection between this line and the ellipse
1.1100 +defines the start point of the arc. The point aEnd is used to define one end
1.1101 +of a second line from the geometric centre of the ellipse. The point of intersection
1.1102 +between this line and the ellipse defines the end point of the arc. The pixels
1.1103 +at both the start point and the end point are drawn.
1.1104 +
1.1105 +The arc itself is the segment of the ellipse in an anti-clockwise direction
1.1106 +from the start point to the end point.
1.1107 +
1.1108 +Notes
1.1109 +
1.1110 +A rectangle is used in the construction of the ellipse of which the arc is
1.1111 +a segment. This rectangle is passed as an argument of type TRect.
1.1112 +
1.1113 +A wide line arc is drawn with the pixels distributed either side of a true
1.1114 +ellipse, in such a way that the outer edge of the line would touch the edge
1.1115 +of the construction rectangle. In other words, the ellipse used to construct
1.1116 +it is slightly smaller than that for a single pixel line size.
1.1117 +
1.1118 +If aStart or aEnd are the ellipse centre then the line that defines the start/end
1.1119 +of the arc defaults to one extending vertically above the centre point.
1.1120 +
1.1121 +If aStart and aEnd are the same point, or points on the same line through
1.1122 +the ellipse centre then a complete unfilled ellipse is drawn.
1.1123 +
1.1124 +Line drawing is subject to pen colour, width and style and draw mode
1.1125 +
1.1126 +@param aRect The rectangle in which to draw the ellipse (of which the arc is
1.1127 +a segment).
1.1128 +@param aStart A point to define the start of the arc.
1.1129 +@param aEnd A point to define the end of the arc.
1.1130 +@see CGraphicsContext::DrawArc() */
1.1131 + {
1.1132 + iPimpl->WriteAnyPendingStateChanges();
1.1133 + DrawArcOrPie(aRect,aStart,aEnd,EWsGcOpDrawArc);
1.1134 + }
1.1135 +
1.1136 +EXPORT_C void CWindowGc::DrawPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
1.1137 +/** Draws and fills a pie-shaped slice of an ellipse.
1.1138 +
1.1139 +Outlines are subject to the current pen colour, width, style and draw mode.
1.1140 +Set the pen to ENullPen for no outline. The fill is subject to brush style
1.1141 +(colour, hash or pattern), the origin and the current drawing mode. Set the
1.1142 +brush to ENullBrush for no fill.
1.1143 +
1.1144 +The point aStart is used to define one end of a line to the centre of the
1.1145 +ellipse. The point of intersection between this line and the ellipse defines
1.1146 +the start point of the arc bounding the pie slice. The point aEnd is used
1.1147 +to define one end of a second line to the centre of the ellipse. The point
1.1148 +of intersection between this line and the ellipse defines the end point of
1.1149 +the arc bounding the pie slice. The pixels at the end point are not drawn.
1.1150 +
1.1151 +The pie slice itself is the area bounded by: the arc of the ellipse in an
1.1152 +anticlockwise direction from the start point to the end point; the straight
1.1153 +line from the start point from the geometric centre of the ellipse; the
1.1154 +straight line from the end point from the geometric centre of the ellipse.
1.1155 +
1.1156 +The line drawn by the pen goes inside the rectangle given by the aRect argument.
1.1157 +
1.1158 +Notes:
1.1159 +
1.1160 +A rectangle is used in the construction of the pie slice. This rectangle is
1.1161 +passed as an argument of type TRect. The curved edge of the pie slice is an
1.1162 +arc of an ellipse constructed within the rectangle.
1.1163 +
1.1164 +A wide line edged pie slice has the arc drawn with the pixels distributed
1.1165 +either side of a true ellipse. This is done in such a way that the outer edge
1.1166 +of the line would touch the edge of the construction rectangle. In other words,
1.1167 +the ellipse used to construct it is slightly smaller than that for a single
1.1168 +pixel line size.
1.1169 +
1.1170 +If aStart or aEnd are the ellipse centre then the line that defines the start/end
1.1171 +of the arc defaults to one extending vertically above the centre point.
1.1172 +
1.1173 +If aStart and aEnd are the same point, or points on the same line through
1.1174 +the ellipse centre then a complete filled ellipse is drawn. A line is also
1.1175 +drawn from the edge to the ellipse centre.
1.1176 +
1.1177 +@param aRect A rectangle in which to draw the ellipse bounding the pie slice
1.1178 +@param aStart A point to define the start of the pie slice
1.1179 +@param aEnd A point to define the end of the pie slice
1.1180 +@see CGraphicsContext::DrawPie() */
1.1181 + {
1.1182 + iPimpl->WriteAnyPendingStateChanges();
1.1183 + DrawArcOrPie(aRect,aStart,aEnd,EWsGcOpDrawPie);
1.1184 + }
1.1185 +
1.1186 +EXPORT_C void CWindowGc::DrawEllipse(const TRect &aRect)
1.1187 +/** Draws and fills an ellipse.
1.1188 +
1.1189 +The ellipse is drawn inside the rectangle defined by the aRect argument. Any
1.1190 +TRect that has odd pixel dimensions, has the bottom right corner trimmed to
1.1191 +give even pixel dimensions before the ellipse is constructed.
1.1192 +
1.1193 +The column and row of pixels containing the bottom right co-ordinate of the
1.1194 +aRect argument are not part of the rectangle.
1.1195 +
1.1196 +Note: a wide outline ellipse is drawn with the pixels distributed either side of
1.1197 +a true ellipse, in such a way that the outer edge of the line touches the
1.1198 +edge of the construction rectangle. In other words, the ellipse used to construct
1.1199 +it is smaller than that for a single pixel line size.
1.1200 +
1.1201 +@param aRect The rectangle in which to draw the ellipse
1.1202 +@see CGraphicsContext::DrawEllipse() */
1.1203 + {
1.1204 + iPimpl->WriteAnyPendingStateChanges();
1.1205 + WriteRect(aRect,EWsGcOpDrawEllipse);
1.1206 + }
1.1207 +
1.1208 +EXPORT_C void CWindowGc::DrawRect(const TRect &aRect)
1.1209 +/** Draws and fills a rectangle.
1.1210 +
1.1211 +The rectangle's border is drawn with the pen, and it is filled using the brush.
1.1212 +
1.1213 +@param aRect The rectangle to be drawn.
1.1214 +@see CGraphicsContext::DrawRect() */
1.1215 + {
1.1216 + iPimpl->WriteAnyPendingStateChanges();
1.1217 + WriteRect(aRect,EWsGcOpDrawRect);
1.1218 + }
1.1219 +
1.1220 +EXPORT_C void CWindowGc::DrawRoundRect(const TRect &aRect,const TSize &aEllipse)
1.1221 +/** Draws and fills a rectangle with rounded corners.
1.1222 +
1.1223 +The rounded corners are each constructed as an arc of an ellipse. The dimensions
1.1224 +of each corner (corner size and corner height) are given by aEllipse. See
1.1225 +DrawArc() for a description of arc construction.
1.1226 +
1.1227 +The line drawn by the pen (if any) goes inside the rectangle given by the
1.1228 +TRect argument.
1.1229 +
1.1230 +Notes:
1.1231 +
1.1232 +Dotted and dashed pen styles cannot be used for the outline of a rounded rectangle.
1.1233 +
1.1234 +If either corner size dimension is greater than half the corresponding rectangle
1.1235 +length, the corner size dimension is reduced to half the rectangle size.
1.1236 +
1.1237 +@param aRect The rectangle to be drawn.
1.1238 +@param aEllipse The dimensions of each corner.
1.1239 +@see CGraphicsContext::DrawRoundRect() */
1.1240 + {
1.1241 + iPimpl->WriteAnyPendingStateChanges();
1.1242 + TWsGcCmdDrawRoundRect drawRoundRect(aRect,aEllipse);
1.1243 + Write(&drawRoundRect,sizeof(drawRoundRect),EWsGcOpDrawRoundRect);
1.1244 + }
1.1245 +
1.1246 +EXPORT_C void CWindowGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice)
1.1247 +/** Draws a bitmap at a specified point.
1.1248 +
1.1249 +The function does a compress/stretch based on its internally stored size in
1.1250 +twips. Note that if the twips value of the bitmap is not set then nothing
1.1251 +is drawn (this is the default situation).
1.1252 +
1.1253 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1254 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1255 +At some point later WSERV may need to draw that window again and it will just replay the
1.1256 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1257 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1258 +
1.1259 +Note: this member function uses the bitmap's size in twips and does a stretch/compress
1.1260 +blit using a linear DDA.
1.1261 +
1.1262 +@param aTopLeft The point where the top left pixel of the bitmap is to be
1.1263 +drawn
1.1264 +@param aDevice The source bitmap.
1.1265 +@see CGraphicsContext::DrawBitmap() */
1.1266 + {
1.1267 + iPimpl->WriteAnyPendingStateChanges();
1.1268 + TWsGcCmdDrawBitmap drawBitmap(aTopLeft,aDevice->Handle());
1.1269 + Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap);
1.1270 + AddToBitmapArray(aDevice->Handle());
1.1271 + }
1.1272 +
1.1273 +EXPORT_C void CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice)
1.1274 +/** Draws a bitmap in a rectangle.
1.1275 +
1.1276 +The bitmap is compressed/stretched to fit the specified rectangle. Note that
1.1277 +if the twips value of the bitmap is not set then nothing is drawn (this is
1.1278 +the default situation).
1.1279 +
1.1280 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1281 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1282 +At some point later WSERV may need to draw that window again and it will just replay the
1.1283 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1284 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1285 +
1.1286 +Notes: this member function uses the bitmap's size in pixels and does a stretch/compress
1.1287 +blit using a linear DDA.
1.1288 +
1.1289 +@param aDestRect The rectangle within which the bitmap is to be drawn.
1.1290 +@param aDevice The source bitmap.
1.1291 +@see CGraphicsContext::DrawBitmap() */
1.1292 + {
1.1293 + iPimpl->WriteAnyPendingStateChanges();
1.1294 + TWsGcCmdDrawBitmap2 drawBitmap(aDestRect,aDevice->Handle());
1.1295 + Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap2);
1.1296 + AddToBitmapArray(aDevice->Handle());
1.1297 + }
1.1298 +
1.1299 +EXPORT_C void CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect)
1.1300 +/** Draws a specified rectangle from a bitmap into another rectangle.
1.1301 +
1.1302 +The function compresses/stretches the specified rectangle from the bitmap
1.1303 +to fit the destination rectangle. Note that if the twips value of the bitmap
1.1304 +is not set then nothing is drawn (this is the default situation).
1.1305 +
1.1306 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1307 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1308 +At some point later WSERV may need to draw that window again and it will just replay the
1.1309 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1310 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1311 +
1.1312 +Note: this member function uses rectangle sizes in pixels and does a stretch/compress
1.1313 +blit using a linear DDA.
1.1314 +
1.1315 +@param aDestRect The rectangle within which the bitmap is to be drawn.
1.1316 +@param aDevice A source bitmap.
1.1317 +@param aSourceRect The rectangle in the source bitmap that is copied to the
1.1318 +destination rectangle.
1.1319 +@see CGraphicsContext::DrawBitmap() */
1.1320 + {
1.1321 + iPimpl->WriteAnyPendingStateChanges();
1.1322 + TWsGcCmdDrawBitmap3 drawBitmap(aDestRect,aDevice->Handle(),aSourceRect);
1.1323 + Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap3);
1.1324 + AddToBitmapArray(aDevice->Handle());
1.1325 + }
1.1326 +
1.1327 +/** Draws a specified rectangle from a bitmap and its mask into another rectangle.
1.1328 +
1.1329 +The function compresses/stretches the specified rectangle from the bitmap
1.1330 +to fit the destination rectangle.
1.1331 +The mask bitmap can be used as either a positive or negative mask. Masked
1.1332 +pixels are not mapped to the destination rectangle.
1.1333 +
1.1334 +A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black
1.1335 +pixels in the mask bitmap stop corresponding pixels in the source bitmap from
1.1336 +being transferred to the destination rectangle. With aInvertMask=ETrue, white
1.1337 +pixels in the mask bitmap stop corresponding pixels in the source bitmap from
1.1338 +being transferred to the destination rectangle.
1.1339 +
1.1340 +If mask bitmap's display mode is EColor256, the function does AplhaBlending
1.1341 +and ignores aInvertMask parameter.
1.1342 +
1.1343 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1344 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1345 +At some point later WSERV may need to draw that window again and it will just replay the
1.1346 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1347 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1348 +
1.1349 +Note: this member function uses rectangle sizes in pixels and does a stretch/compress
1.1350 +blit using a linear DDA.
1.1351 +
1.1352 +@param aDestRect The rectangle within which the masked bitmap is to be drawn.
1.1353 +@param aBitmap A source bitmap.
1.1354 +@param aSourceRect The rectangle in the source bitmap that is copied to the
1.1355 +destination rectangle.
1.1356 +@param aMaskBitmap A mask bitmap.
1.1357 +@param aInvertMask If false, a source pixel that is masked by a black pixel
1.1358 +is not transferred to the destination rectangle. If true, then a source pixel
1.1359 +that is masked by a white pixel is not transferred to the destination rectangle. */
1.1360 +EXPORT_C void CWindowGc::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask)
1.1361 + {
1.1362 + iPimpl->WriteAnyPendingStateChanges();
1.1363 + TWsGcCmdDrawBitmapMasked drawBitmap(aDestRect,aBitmap->Handle(),aSourceRect,aMaskBitmap->Handle(),aInvertMask);
1.1364 + Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmapMasked);
1.1365 + AddToBitmapArray(aBitmap->Handle());
1.1366 + AddToBitmapArray(aMaskBitmap->Handle());
1.1367 + }
1.1368 +
1.1369 +EXPORT_C void CWindowGc::DrawBitmapMasked(const TRect& aDestRect, const CWsBitmap* aBitmap, const TRect& aSourceRect, const CWsBitmap* aMaskBitmap, TBool aInvertMask)
1.1370 +/** Draws a specified rectangle from a wserv bitmap and its mask into
1.1371 +another rectangle.
1.1372 +
1.1373 +The function compresses/stretches the specified rectangle from the bitmap
1.1374 +to fit the destination rectangle.
1.1375 +The mask bitmap can be used as either a positive or negative mask. Masked
1.1376 +pixels are not mapped to the destination rectangle.
1.1377 +
1.1378 +A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black
1.1379 +pixels in the mask bitmap stop corresponding pixels in the source bitmap from
1.1380 +being transferred to the destination rectangle. With aInvertMask=ETrue, white
1.1381 +pixels in the mask bitmap stop corresponding pixels in the source bitmap from
1.1382 +being transferred to the destination rectangle.
1.1383 +
1.1384 +If mask bitmap's display mode is EColor256, the function does AplhaBlending
1.1385 +and ignores aInvertMask parameter.
1.1386 +
1.1387 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1388 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1389 +At some point later WSERV may need to draw that window again and it will just replay the
1.1390 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1391 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1392 +
1.1393 +Note: this member function uses rectangle sizes in pixels and does a stretch/compress
1.1394 +blit using a linear DDA.
1.1395 +
1.1396 +@param aDestRect The rectangle within which the masked bitmap is to be drawn.
1.1397 +@param aBitmap A source wserv bitmap.
1.1398 +@param aSourceRect The rectangle in the source bitmap that is copied to the
1.1399 +destination rectangle.
1.1400 +@param aMaskBitmap A mask wserv bitmap.
1.1401 +@param aInvertMask If false, a source pixel that is masked by a black pixel
1.1402 +is not transferred to the destination rectangle. If true, then a source pixel
1.1403 +that is masked by a white pixel is not transferred to the destination rectangle. */
1.1404 + {
1.1405 + iPimpl->WriteAnyPendingStateChanges();
1.1406 + TWsGcCmdDrawBitmapMasked drawBitmap(aDestRect,aBitmap->WsHandle(),aSourceRect,aMaskBitmap->WsHandle(),aInvertMask);
1.1407 + Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpWsDrawBitmapMasked);
1.1408 + AddToBitmapArray(aBitmap->Handle());
1.1409 + AddToBitmapArray(aMaskBitmap->Handle());
1.1410 + }
1.1411 +EXPORT_C void CWindowGc::DrawText(const TDesC &aBuf, const TPoint &aPos)
1.1412 +/** Draws horizontal text with no surrounding box.
1.1413 +
1.1414 +The appearance of the text is subject to the drawing mode, the font, pen colour,
1.1415 +word justification and character justification.
1.1416 +
1.1417 +A panic occurs if this function is called when there is no font: see UseFont().
1.1418 +
1.1419 +@param aBuf The string to write.
1.1420 +@param aPos The point specifying the position of the baseline at the left
1.1421 +end of the text.
1.1422 +@see CGraphicsContext::DrawText() */
1.1423 + {
1.1424 + iPimpl->WriteAnyPendingStateChanges();
1.1425 + TWsGcCmdDrawText printText(aPos,aBuf.Length());
1.1426 + __ASSERT_ALWAYS(((aBuf.Size()+sizeof(printText))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1427 + WriteTextCommand(&printText,sizeof(printText),aBuf,EWsGcOpDrawText,EWsGcOpDrawTextPtr);
1.1428 + }
1.1429 +
1.1430 +EXPORT_C void CWindowGc::DrawText(const TDesC &aBuf,const TRect &aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
1.1431 +/** Draws horizontal text within a cleared box.
1.1432 +
1.1433 +The appearance of the text is subject to the drawing mode, the font, pen colour,
1.1434 +word justification and character justification. It is also subject to the
1.1435 +background brush (set brush to ENullBrush for no effect on background).
1.1436 +
1.1437 +A panic occurs if this function is called when there is no font: see UseFont().
1.1438 +
1.1439 +Note: the text is clipped to the box. You must ensure that the specified string
1.1440 +is not too large.
1.1441 +
1.1442 +@param aBuf The text to write.
1.1443 +@param aBox The box to draw the text in.
1.1444 +@param aBaselineOffset An offset from the top of the box to the text baseline.
1.1445 +Note that the baseline is the line on which letters sit, for instance below r, s, t, and
1.1446 +above the tail of q, and y.
1.1447 +@param aHoriz The text alignment mode (default is left, rather than centre
1.1448 +or right).
1.1449 +@param aLeftMrg The left margin for left-aligned text, or the right margin
1.1450 +for right-aligned text (default is zero).
1.1451 +@see CGraphicsContext::DrawText() */
1.1452 + {
1.1453 + iPimpl->WriteAnyPendingStateChanges();
1.1454 + if (aBuf.Size()<(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)-sizeof(TWsGcCmdBoxTextOptimised2)))
1.1455 + {
1.1456 + if (aHoriz==ELeft && aLeftMrg==0)
1.1457 + {
1.1458 + TWsGcCmdBoxTextOptimised1 boxTextOpt1(aBox,aBaselineOffset,aBuf.Length());
1.1459 + __ASSERT_ALWAYS(((aBuf.Size()+sizeof(boxTextOpt1))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1460 + Write(&boxTextOpt1,sizeof(boxTextOpt1),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextOptimised1);
1.1461 + }
1.1462 + else
1.1463 + {
1.1464 + TWsGcCmdBoxTextOptimised2 boxTextOpt2(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length());
1.1465 + __ASSERT_ALWAYS(((aBuf.Size()+sizeof(boxTextOpt2))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1466 + Write(&boxTextOpt2,sizeof(boxTextOpt2),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextOptimised2);
1.1467 + }
1.1468 + }
1.1469 + else
1.1470 + {
1.1471 + TWsGcCmdBoxText boxText(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length(),iPimpl->iFont->TextWidthInPixels(aBuf));
1.1472 + __ASSERT_ALWAYS(((aBuf.Size()+sizeof(boxText))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1473 + WriteTextCommand(&boxText,sizeof(boxText),aBuf,EWsGcOpDrawBoxText,EWsGcOpDrawBoxTextPtr);
1.1474 + }
1.1475 + }
1.1476 +
1.1477 +TInt CWindowGc::APIExDrawText(const TDesC& aBuf,const TTextParameters* aParam,const TPoint& aPos)
1.1478 + {
1.1479 + iPimpl->WriteAnyPendingStateChanges();
1.1480 + TWsGcCmdDrawTextInContext printTextInContext(aPos,aBuf.Length(),aParam->iStart,aParam->iEnd);
1.1481 + __ASSERT_ALWAYS(((aBuf.Size()+sizeof(printTextInContext))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1482 + WriteTextCommand(&printTextInContext,sizeof(printTextInContext),aBuf,EWsGcOpDrawTextInContext,EWsGcOpDrawTextInContextPtr);
1.1483 + return KErrNone;
1.1484 + }
1.1485 +
1.1486 +TInt CWindowGc::APIExDrawText(const TDesC& aBuf,const TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
1.1487 + {
1.1488 + iPimpl->WriteAnyPendingStateChanges();
1.1489 + if (aBuf.Size()<(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)-sizeof(TWsGcCmdBoxTextInContextOptimised2)))
1.1490 + {
1.1491 + if (aHoriz==ELeft && aLeftMrg==0)
1.1492 + {
1.1493 + TWsGcCmdBoxTextInContextOptimised1 boxTextOpt1(aBox,aBaselineOffset,aBuf.Length(),aParam->iStart,aParam->iEnd);
1.1494 + __ASSERT_ALWAYS(((aBuf.Size()+sizeof(boxTextOpt1))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1495 + Write(&boxTextOpt1,sizeof(boxTextOpt1),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextInContextOptimised1);
1.1496 + }
1.1497 + else
1.1498 + {
1.1499 + TWsGcCmdBoxTextInContextOptimised2 boxTextOpt2(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length(),aParam->iStart,aParam->iEnd);
1.1500 + __ASSERT_ALWAYS(((aBuf.Size()+sizeof(boxTextOpt2))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1501 + Write(&boxTextOpt2,sizeof(boxTextOpt2),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextInContextOptimised2);
1.1502 + }
1.1503 + }
1.1504 + else
1.1505 + {
1.1506 + TWsGcCmdBoxTextInContext boxText(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length(),iPimpl->iFont->TextWidthInPixels(aBuf),aParam->iStart,aParam->iEnd);
1.1507 + __ASSERT_ALWAYS(((aBuf.Size()+sizeof(boxText))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1508 + WriteTextCommand(&boxText,sizeof(boxText),aBuf,EWsGcOpDrawBoxTextInContext,EWsGcOpDrawBoxTextInContextPtr);
1.1509 + }
1.1510 + return KErrNone;
1.1511 + }
1.1512 +EXPORT_C void CWindowGc::DrawTextVertical(const TDesC& aText,const TPoint& aPos,TBool aUp)
1.1513 +/** Draws vertical text in the specified direction.
1.1514 +
1.1515 +A panic occurs if this function is called when there is no font: see UseFont().
1.1516 +
1.1517 +@param aText The text to be drawn.
1.1518 +@param aPos Point of origin of the text baseline.
1.1519 +@param aUp Direction. ETrue for up, EFalse for down. */
1.1520 + {
1.1521 + iPimpl->WriteAnyPendingStateChanges();
1.1522 + TWsGcCmdDrawTextVertical printText(aPos,aText.Length(),aUp);
1.1523 + __ASSERT_ALWAYS(((aText.Size()+sizeof(printText))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1524 + WriteTextCommand(&printText,sizeof(printText),aText,EWsGcOpDrawTextVertical,EWsGcOpDrawTextVerticalPtr);
1.1525 + }
1.1526 +
1.1527 +EXPORT_C void CWindowGc::DrawTextVertical(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
1.1528 +/** Draws text vertically in the specified direction, within a box of the specified
1.1529 +size.
1.1530 +
1.1531 +A panic occurs if this function is called when there is no font: see UseFont().
1.1532 +
1.1533 +@param aText The text to be drawn.
1.1534 +@param aBox The bounding box within which the text should be drawn, and which
1.1535 +it is clipped to.
1.1536 +@param aBaselineOffset The height of the top of the characters from their text
1.1537 +baseline.
1.1538 +@param aUp The direction. ETrue for up, EFalse for down.
1.1539 +@param aVert The text alignment.
1.1540 +@param aMargin The margin. */
1.1541 + {
1.1542 + iPimpl->WriteAnyPendingStateChanges();
1.1543 + TWsGcCmdBoxTextVertical boxText(aBox);
1.1544 + boxText.baselineOffset=aBaselineOffset;
1.1545 + boxText.up=aUp;
1.1546 + boxText.vert=aVert;
1.1547 + boxText.margin=aMargin;
1.1548 + boxText.length=aText.Length();
1.1549 + boxText.width=iPimpl->iFont->TextWidthInPixels(aText);
1.1550 + __ASSERT_ALWAYS(((aText.Size()+sizeof(boxText))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1551 + WriteTextCommand(&boxText,sizeof(boxText),aText,EWsGcOpDrawBoxTextVertical,EWsGcOpDrawBoxTextVerticalPtr);
1.1552 + }
1.1553 +
1.1554 +TInt CWindowGc::APIExDrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPos,TBool aUp)
1.1555 + {
1.1556 + iPimpl->WriteAnyPendingStateChanges();
1.1557 + TWsGcCmdDrawTextInContextVertical printText(aPos,aText.Length(),aUp,aParam->iStart,aParam->iEnd);
1.1558 + __ASSERT_ALWAYS(((aText.Size()+sizeof(printText))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1559 + WriteTextCommand(&printText,sizeof(printText),aText,EWsGcOpDrawTextInContextVertical,EWsGcOpDrawTextInContextVerticalPtr);
1.1560 + return KErrNone;
1.1561 + }
1.1562 +
1.1563 +TInt CWindowGc::APIExDrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
1.1564 + {
1.1565 + iPimpl->WriteAnyPendingStateChanges();
1.1566 + TWsGcCmdBoxTextInContextVertical boxText(aBox);
1.1567 + boxText.baselineOffset=aBaselineOffset;
1.1568 + boxText.up=aUp;
1.1569 + boxText.vert=aVert;
1.1570 + boxText.margin=aMargin;
1.1571 + boxText.length=aText.Length();
1.1572 + boxText.width=iPimpl->iFont->TextWidthInPixels(aText);
1.1573 + boxText.start = aParam->iStart;
1.1574 + boxText.end = aParam->iEnd;
1.1575 + __ASSERT_ALWAYS(((aText.Size()+sizeof(boxText))<=EClientBufferMaxSize),Panic(EW32PanicSizeNotExpected));
1.1576 + WriteTextCommand(&boxText,sizeof(boxText),aText,EWsGcOpDrawBoxTextInContextVertical,EWsGcOpDrawBoxTextInContextVerticalPtr);
1.1577 + return KErrNone;
1.1578 + }
1.1579 +
1.1580 +//========================Extra functions============================
1.1581 +
1.1582 +EXPORT_C void CWindowGc::CopyRect(const TPoint &anOffset,const TRect &aRect)
1.1583 +/** Copies a rectangle from any part of the screen into the window that the gc
1.1584 +is active on.
1.1585 +
1.1586 +The copy part of the operation applies to the whole rectangle, irrespective
1.1587 +of whether or not it within the window, however the "paste" is clipped to
1.1588 +the drawing area.
1.1589 +
1.1590 +The rectangle is specified in window coordinates (if the top-left of the rectangle
1.1591 +is (0,0) then the area of the screen it specifies has its top-left at the
1.1592 +top left corner of the window, if it is (-10,-10) then it starts 10 pixels
1.1593 +above and to the left of the window).
1.1594 +
1.1595 +Note: shadows in the source rectangle will be copied. None of the area drawn to
1.1596 +will gain shadowing (even if the window is already in shadow).
1.1597 +
1.1598 +This version of this function is only really suitable for testing.
1.1599 +
1.1600 +@param anOffset The offset from the original position to the point where the
1.1601 +rectangle is copied.
1.1602 +@param aRect The rectangular area to be copied. This is in window co-ordinates,
1.1603 +e.g. the top left corner of the window is position (0,0) with respect to the
1.1604 +rectangle.
1.1605 +@see CBitmapContext::CopyRect() */
1.1606 + {
1.1607 + iPimpl->WriteAnyPendingStateChanges();
1.1608 + TWsGcCmdCopyRect copyRect(anOffset,aRect);
1.1609 + Write(©Rect,sizeof(copyRect),EWsGcOpCopyRect);
1.1610 + }
1.1611 +
1.1612 +EXPORT_C void CWindowGc::BitBlt(const TPoint &aPoint, const CFbsBitmap *aBitmap)
1.1613 +/** Performs a bitmap block transfer.
1.1614 +
1.1615 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1616 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1617 +At some point later WSERV may need to draw that window again and it will just replay the
1.1618 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1619 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1620 +
1.1621 +@param aPoint The position for the top left corner of the bitmap.
1.1622 +@param aBitmap A memory-resident bitmap.
1.1623 +@see CBitmapContext::BitBlt() */
1.1624 + {
1.1625 + if (aBitmap == NULL || !aBitmap->Handle())
1.1626 + return;
1.1627 + iPimpl->WriteAnyPendingStateChanges();
1.1628 + TWsGcCmdGdiBlt2 gdiBlit(aPoint,aBitmap->Handle());
1.1629 + Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiBlt2);
1.1630 + AddToBitmapArray(aBitmap->Handle());
1.1631 + }
1.1632 +
1.1633 +EXPORT_C void CWindowGc::BitBlt(const TPoint &aDestination,const CFbsBitmap *aBitmap,const TRect &aSource)
1.1634 +/** Performs a bitmap block transfer of a rectangular piece of a bitmap.
1.1635 +
1.1636 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1637 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1638 +At some point later WSERV may need to draw that window again and it will just replay the
1.1639 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1640 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1641 +
1.1642 +Note: if the rectangle aSource is larger than the bitmap then the bitmap will be padded
1.1643 +with white.
1.1644 +
1.1645 +@param aDestination The position for the top left corner of the bitmap.
1.1646 +@param aBitmap A memory-resident bitmap
1.1647 +@param aSource A rectangle defining the piece of the bitmap to be drawn, with
1.1648 +co-ordinates relative to the top left corner of the bitmap
1.1649 +@see CBitmapContext::BitBlt() */
1.1650 + {
1.1651 + if (aBitmap == NULL || !aBitmap->Handle())
1.1652 + return;
1.1653 + iPimpl->WriteAnyPendingStateChanges();
1.1654 + TWsGcCmdGdiBlt3 gdiBlit(aDestination,aBitmap->Handle(),aSource);
1.1655 + Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiBlt3);
1.1656 + AddToBitmapArray(aBitmap->Handle());
1.1657 + }
1.1658 +
1.1659 +EXPORT_C void CWindowGc::BitBltMasked(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask)
1.1660 +/** Performs a masked bitmap block transfer of a memory resident source bitmap.
1.1661 +
1.1662 +The mask bitmap can be used as either a positive or negative mask. Masked
1.1663 +pixels are not mapped to the destination rectangle.
1.1664 +
1.1665 +A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black
1.1666 +pixels in the mask bitmap stop corresponding pixels in the source bitmap from
1.1667 +being transferred to the destination rectangle. With aInvertMask=ETrue, white
1.1668 +pixels in the mask bitmap stop corresponding pixels in the source bitmap from
1.1669 +being transferred to the destination rectangle.
1.1670 +
1.1671 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1672 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1673 +At some point later WSERV may need to draw that window again and it will just replay the
1.1674 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1675 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1676 +
1.1677 +@param aPoint A position for the top left corner of the bitmap.
1.1678 +@param aBitmap A memory-resident source bitmap.
1.1679 +@param aSourceRect A rectangle defining the piece of the bitmap to be drawn,
1.1680 +with co-ordinates relative to the top left corner of the bitmap
1.1681 +@param aMaskBitmap A mask bitmap.
1.1682 +@param aInvertMask If false, a source pixel that is masked by a black pixel
1.1683 +is not transferred to the destination rectangle. If true, then a source pixel
1.1684 +that is masked by a white pixel is not transferred to the destination rectangle.
1.1685 +
1.1686 +@see CBitmapContext::BitBltMasked() */
1.1687 + {
1.1688 + if (aBitmap == NULL || !aBitmap->Handle() || aMaskBitmap == NULL || !aMaskBitmap->Handle())
1.1689 + return;
1.1690 + iPimpl->WriteAnyPendingStateChanges();
1.1691 + TWsGcCmdBltMasked gdiBlitMasked(aPoint,aBitmap->Handle(),aSourceRect,aMaskBitmap->Handle(),aInvertMask);
1.1692 + Write(&gdiBlitMasked,sizeof(gdiBlitMasked),EWsGcOpGdiBltMasked);
1.1693 + AddToBitmapArray(aBitmap->Handle());
1.1694 + AddToBitmapArray(aMaskBitmap->Handle());
1.1695 + }
1.1696 +
1.1697 +EXPORT_C void CWindowGc::BitBlt(const TPoint &aPoint, const CWsBitmap *aBitmap)
1.1698 +/** Performs a bitmap block transfer on a bitmap to which the window server already
1.1699 +has a handle.
1.1700 +
1.1701 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1702 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1703 +At some point later WSERV may need to draw that window again and it will just replay the
1.1704 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1705 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1706 +
1.1707 +This function should be used in preference to the CFbsBitmap overload if the
1.1708 +bitmap is to be used more than once, as it is a lot quicker.
1.1709 +
1.1710 +@param aPoint The position for the top left corner of the bitmap.
1.1711 +@param aBitmap A window server bitmap.
1.1712 +@see CBitmapContext::BitBlt() */
1.1713 + {
1.1714 + if (aBitmap == NULL || !aBitmap->Handle())
1.1715 + return;
1.1716 + iPimpl->WriteAnyPendingStateChanges();
1.1717 + TWsGcCmdGdiBlt2 gdiBlit(aPoint,aBitmap->WsHandle());
1.1718 + Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiWsBlt2);
1.1719 + AddToBitmapArray(aBitmap->Handle());
1.1720 + }
1.1721 +
1.1722 +EXPORT_C void CWindowGc::BitBlt(const TPoint &aDestination,const CWsBitmap *aBitmap,const TRect &aSource)
1.1723 +/** Performs a bitmap block transfer of a rectangular piece of a bitmap to which
1.1724 +the window server already has a handle.
1.1725 +
1.1726 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1727 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1728 +At some point later WSERV may need to draw that window again and it will just replay the
1.1729 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1730 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1731 +
1.1732 +This function should be used in preference to the CFbsBitmap overload if the
1.1733 +bitmap is to be used more than once, as it is a lot quicker.
1.1734 +
1.1735 +Note: if the rectangle aSource is larger than the bitmap then the bitmap will be padded
1.1736 +with white.
1.1737 +
1.1738 +@param aDestination The position for the top left corner of the bitmap.
1.1739 +@param aBitmap A window server bitmap.
1.1740 +@param aSource A rectangle defining the piece of the bitmap to be drawn, with
1.1741 +co-ordinates relative to the top left corner of the bitmap
1.1742 +@see CBitmapContext::BitBlt() */
1.1743 + {
1.1744 + if (aBitmap == NULL || !aBitmap->Handle())
1.1745 + return;
1.1746 + iPimpl->WriteAnyPendingStateChanges();
1.1747 + TWsGcCmdGdiBlt3 gdiBlit(aDestination,aBitmap->WsHandle(),aSource);
1.1748 + Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiWsBlt3);
1.1749 + AddToBitmapArray(aBitmap->Handle());
1.1750 + }
1.1751 +
1.1752 +EXPORT_C void CWindowGc::BitBltMasked(const TPoint& aPoint,const CWsBitmap * aBitmap,const TRect& aSourceRect,const CWsBitmap * aMaskBitmap,TBool aInvertMask)
1.1753 +/** Performs a masked bitmap block transfer of a window server bitmap.
1.1754 +
1.1755 +The mask bitmap can be used as either a positive or negative mask. Masked
1.1756 +pixels are not mapped to the destination rectangle.
1.1757 +
1.1758 +A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black
1.1759 +pixels in the mask bitmap stop corresponding pixels in the source bitmap from
1.1760 +being transferred to the destination rectangle. With aInvertMask=ETrue, white
1.1761 +pixels in the mask bitmap stop corresponding pixels in the source bitmap from
1.1762 +being transferred to the destination rectangle.
1.1763 +
1.1764 +This function should be used in preference to the CFbsBitmap overload if the
1.1765 +bitmap is to be used more than once, as it is a lot quicker.
1.1766 +
1.1767 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1768 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1769 +At some point later WSERV may need to draw that window again and it will just replay the
1.1770 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1771 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1772 +
1.1773 +@param aPoint A position for the top left corner of the bitmap.
1.1774 +@param aBitmap A window server bitmap.
1.1775 +@param aSourceRect A rectangle defining the piece of the bitmap to be drawn,
1.1776 +with co-ordinates relative to the top left corner of the bitmap.
1.1777 +@param aMaskBitmap A window server mask bitmap.
1.1778 +@param aInvertMask If false, a source pixel that is masked by a black pixel
1.1779 +is not transferred to the destination rectangle. If true, then a source pixel
1.1780 +that is masked by a white pixel is not transferred to the destination rectangle.
1.1781 +
1.1782 +@see CBitmapContext::BitBltMasked() */
1.1783 + {
1.1784 + if (aBitmap == NULL || !aBitmap->Handle() || aMaskBitmap == NULL || !aMaskBitmap->Handle())
1.1785 + return;
1.1786 + iPimpl->WriteAnyPendingStateChanges();
1.1787 + TWsGcCmdBltMasked gdiBlitMasked(aPoint,aBitmap->WsHandle(),aSourceRect,aMaskBitmap->WsHandle(),aInvertMask);
1.1788 + Write(&gdiBlitMasked,sizeof(gdiBlitMasked),EWsGcOpGdiWsBltMasked);
1.1789 + AddToBitmapArray(aBitmap->Handle());
1.1790 + AddToBitmapArray(aMaskBitmap->Handle());
1.1791 + }
1.1792 +
1.1793 +/**
1.1794 +This method has been deprecated. It is no longer possible to re-map pixel colours
1.1795 +within a rectangle. Calling it has no effect.
1.1796 +@param aRect Ignored.
1.1797 +@param aColors Ignored.
1.1798 +@param aNumPairs Ignored.
1.1799 +@param aMapForwards Ignored.
1.1800 +@deprecated
1.1801 +*/
1.1802 +EXPORT_C void CWindowGc::MapColors(const TRect& /*aRect*/, const TRgb* /*aColors*/, TInt /*aNumPairs*/, TBool /*aMapForwards*/)
1.1803 + {
1.1804 + }
1.1805 +
1.1806 +EXPORT_C void CWindowGc::Clear(const TRect &aRect)
1.1807 +/** Clears a rectangular area of a window.
1.1808 +
1.1809 +The cleared area is filled with the current brush colour.
1.1810 +
1.1811 +@param aRect The rectangle to clear.
1.1812 +@see CBitmapContext::Clear() */
1.1813 + {
1.1814 + iPimpl->WriteAnyPendingStateChanges();
1.1815 + WriteRect(aRect,EWsGcOpClearRect);
1.1816 + }
1.1817 +
1.1818 +EXPORT_C void CWindowGc::Clear()
1.1819 +/** Clears the whole window.
1.1820 +
1.1821 +The cleared area is filled with the current brush colour.
1.1822 +
1.1823 +@see CBitmapContext::Clear() */
1.1824 + {
1.1825 + iPimpl->WriteAnyPendingStateChanges();
1.1826 + Write(EWsGcOpClear);
1.1827 + }
1.1828 +
1.1829 +EXPORT_C void CWindowGc::Reset()
1.1830 +/** Resets the graphics context to its default settings.
1.1831 +
1.1832 +The drawing mode is set to TDrawMode::EDrawModePen (pen and brush colours used as
1.1833 +they are); there is no clipping rectangle; the pen settings are black,
1.1834 +solid, single pixel size; the brush style is null; no text font is selected.
1.1835 +
1.1836 +@see CGraphicsContext::Reset() */
1.1837 + {
1.1838 + Write(EWsGcOpReset);
1.1839 + iPimpl->iFont=NULL;
1.1840 + iPimpl->iShadowColor = KDefaultShadowColor;
1.1841 + iPimpl->ResetPendingState();
1.1842 + iPimpl->iForceWrite = ETrue; // needed because brush colour set to window background colour in CPlaybackGc::CommandL and CWsGc::SetGcAttribute
1.1843 + }
1.1844 +
1.1845 +/**
1.1846 +This method has been deprecated. Dithering is no longer supported. Calling it
1.1847 +has no effect.
1.1848 +@param aPoint Ignored.
1.1849 +@deprecated
1.1850 +*/
1.1851 +EXPORT_C void CWindowGc::SetDitherOrigin(const TPoint& /*aPoint*/)
1.1852 + {
1.1853 + }
1.1854 +
1.1855 +EXPORT_C void CWindowGc::SetFaded(TBool aFaded)
1.1856 +/** Sets whether the graphics context is faded.
1.1857 +
1.1858 +Fading is used to make a window appear less colourful so that other windows
1.1859 +stand out. For example, a window would be faded when a dialogue is displayed
1.1860 +in front of it.
1.1861 +
1.1862 +@param aFaded ETrue to fade the graphics context, EFalse to unfade it. */
1.1863 + {
1.1864 + iPimpl->WriteAnyPendingStateChanges();
1.1865 + WriteInt(aFaded,EWsGcOpSetFaded);
1.1866 + }
1.1867 +
1.1868 +EXPORT_C void CWindowGc::SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap)
1.1869 +/** Sets the fading parameters.
1.1870 +
1.1871 +This function allows you to override the map used when drawing with a faded
1.1872 +graphics context. However if you draw to a faded window with a faded graphics
1.1873 +context, then fading on the graphics context is ignored and it will use the
1.1874 +fading of the window.
1.1875 +
1.1876 +Fading is used to make a window appear less colourful so that other windows stand
1.1877 +out. For example, a window would be faded when a dialogue is displayed
1.1878 +in front of it.
1.1879 +
1.1880 +You can either make a faded window closer to white or closer to black.
1.1881 +The fading map allows you to over-ride the default fading parameters set in
1.1882 +RWsSession::SetDefaultFadingParameters().
1.1883 +
1.1884 +Fading re-maps colours to fall between the specified black and white map values.
1.1885 +If aBlackMap=0 and aWhiteMap=255 then the colours are mapped unchanged. As the
1.1886 +values converge, the colours are mapped to a smaller range, so the differences
1.1887 +between colours in the faded graphics context decrease. If the values are reversed
1.1888 +then the colours are inverted (i.e. where the gc would be black, it is now white).
1.1889 +
1.1890 +@param aBlackMap Black map fading parameter. Unfaded this is 0.
1.1891 +@param aWhiteMap White map fading parameter. Unfaded this is 255.
1.1892 +@see RWsSession::SetDefaultFadingParameters()
1.1893 +@see RWindowTreeNode::SetFaded() */
1.1894 + {
1.1895 + WriteInt(WservEncoding::Encode8BitValues(aBlackMap,aWhiteMap),EWsGcOpSetFadeParams);
1.1896 + }
1.1897 +
1.1898 +EXPORT_C TInt CWindowGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect,const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
1.1899 +/**
1.1900 +Performs an alpha blending of the source data, aSrcBmp, with the window, using
1.1901 +the data from aAlphaBmp as an alpha blending factor.
1.1902 +The formula used is:
1.1903 +(S * A + W * (255 - A)) / 255, where:
1.1904 +- S - a pixel from aSrcBmp;
1.1905 +- W - a pixel from the window;
1.1906 +- A - a pixel from aAlphaBmp;
1.1907 +The contents of source and alpha bitmap are preserved.
1.1908 +The calculated alpha blended pixels are written to the destination - the window image.
1.1909 +
1.1910 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1911 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1912 +At some point later WSERV may need to draw that window again and it will just replay the
1.1913 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1914 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1915 +
1.1916 +This method is supported from version 8.1
1.1917 +@param aDestPt Position in the target the result should be drawn to.
1.1918 +@param aSrcBmp A pointer to the source bitmap.
1.1919 +@param aSrcRect The part of the source bitmap that should be used.
1.1920 +@param aAlphaBmp A pointer to the bitmap used as an alpha blending factor.
1.1921 +@param aAlphaPt Position of the first pixel in the alpha bitmap that should be used as a source
1.1922 + for the alpha blending. The size of the area is the same as the
1.1923 + source bitmap area - aSrcRect parameter.
1.1924 +@see CFbsBitGc::AlphaBlendBitmaps()
1.1925 +*/
1.1926 + {
1.1927 + iPimpl->WriteAnyPendingStateChanges();
1.1928 + TWsGcCmdAlphaBlendBitmaps alphaBlend(aDestPt, aSrcBmp->Handle(), aSrcRect, aAlphaBmp->Handle(), aAlphaPt);
1.1929 + Write(&alphaBlend,sizeof(alphaBlend),EWsGcOpGdiAlphaBlendBitmaps);
1.1930 + AddToBitmapArray(aSrcBmp->Handle());
1.1931 + AddToBitmapArray(aAlphaBmp->Handle());
1.1932 + return KErrNone;
1.1933 + }
1.1934 +
1.1935 +EXPORT_C TInt CWindowGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CWsBitmap* aSrcBmp, const TRect& aSrcRect,const CWsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
1.1936 +/**
1.1937 +The method performs an alpha blending of the source data, aSrcBmp, with the window, using
1.1938 +the data from aAlphaBmp as an alpha blending factor.
1.1939 +For information on how this function works, see the other overload.
1.1940 +
1.1941 +Windows that store their redraw commands will only store drawing position and a handle to bitmaps
1.1942 +that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap.
1.1943 +At some point later WSERV may need to draw that window again and it will just replay the
1.1944 +stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
1.1945 +WSERV will effectively draw a different bitmap when it replays the commands.
1.1946 +
1.1947 +This method is supported from version 8.1
1.1948 +@param aDestPt Position in the target the result should be drawn to.
1.1949 +@param aSrcBmp A pointer to the source bitmap.
1.1950 +@param aSrcRect The part of the source bitmap that should be used.
1.1951 +@param aAlphaBmp A pointer to the bitmap used as an alpha blending factor.
1.1952 +@param aAlphaPt Position of the first pixel in the alpha bitmap that should be used as a source
1.1953 + for the alpha blending. The size of the area is the same as the
1.1954 + source bitmap area - aSrcRect parameter.
1.1955 +@see CFbsBitGc::AlphaBlendBitmaps()
1.1956 +*/
1.1957 + {
1.1958 + iPimpl->WriteAnyPendingStateChanges();
1.1959 + TWsGcCmdAlphaBlendBitmaps alphaBlend(aDestPt, aSrcBmp->WsHandle(), aSrcRect, aAlphaBmp->WsHandle(), aAlphaPt);
1.1960 + Write(&alphaBlend,sizeof(alphaBlend),EWsGcOpGdiWsAlphaBlendBitmaps);
1.1961 + AddToBitmapArray(aSrcBmp->Handle());
1.1962 + AddToBitmapArray(aAlphaBmp->Handle());
1.1963 + return KErrNone;
1.1964 + }
1.1965 +
1.1966 +/**
1.1967 +This method has been deprecated. Calling it has no effect.
1.1968 +@param aDrawOpaque Ignored.
1.1969 +@deprecated
1.1970 +*/
1.1971 +EXPORT_C void CWindowGc::SetOpaque(TBool aDrawOpaque)
1.1972 + {
1.1973 + iPimpl->WriteAnyPendingStateChanges();
1.1974 + WriteInt(aDrawOpaque, EWsGcOpSetOpaque);
1.1975 + }
1.1976 +
1.1977 +/** APIExtension can contain as many additional methods as is required by
1.1978 +CGraphicsContext after its original conception. It takes 3 parameters.
1.1979 +Function is exported due to constrains of retaining BC with earlier versions.
1.1980 +This is not used directly by external methods, instead it is called by a named
1.1981 +method in CGraphicsContext which passes the relivant arguements including an
1.1982 +unique identifier for the required action.
1.1983 +@param aUid The unique identifier for the method that is required. Selected
1.1984 +internally by a series of "if" statements.
1.1985 +@see Valid Uid identifiers are listed in header gdi.h
1.1986 +@see CGraphicsContext
1.1987 +@param aOutput is a TAny pointer to a reference. Used to output data as the structure
1.1988 +does not need to be instantiated before the function call this adds greater
1.1989 +flexibility.
1.1990 +@param aInput is a TAny pointer used to input data.
1.1991 +*/
1.1992 +EXPORT_C TInt CWindowGc::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput)
1.1993 + {
1.1994 + if (aUid == KGetUnderlineMetrics)
1.1995 + {
1.1996 + return APIExGetUnderlineMetrics(aOutput);
1.1997 + }
1.1998 + else if (aUid == KSetShadowColor)
1.1999 + {
1.2000 + return APIExSetShadowColor(aInput);
1.2001 + }
1.2002 + else if (aUid == KGetShadowColor)
1.2003 + {
1.2004 + return APIExGetShadowColor(aOutput);
1.2005 + }
1.2006 + else if (aUid == KDrawTextInContextUid)
1.2007 + {
1.2008 + TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
1.2009 + return APIExDrawText(contextParam->iText, &contextParam->iParam, contextParam->iPosition);
1.2010 + }
1.2011 + else if (aUid == KDrawBoxTextInContextUid)
1.2012 + {
1.2013 + TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
1.2014 + return APIExDrawText(contextParam->iText,&contextParam->iParam,contextParam->iBox,contextParam->iBaselineOffset,contextParam->iAlign,contextParam->iMargin);
1.2015 + }
1.2016 + else if (aUid == KDrawTextInContextVerticalUid)
1.2017 + {
1.2018 + TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
1.2019 + return APIExDrawTextVertical(contextParam->iText, &contextParam->iParam, contextParam->iPosition,contextParam->iUp);
1.2020 + }
1.2021 + else if (aUid == KDrawBoxTextInContextVerticalUid)
1.2022 + {
1.2023 + TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
1.2024 + return APIExDrawTextVertical(contextParam->iText,&contextParam->iParam,contextParam->iBox,contextParam->iBaselineOffset,contextParam->iUp,contextParam->iAlign,contextParam->iMargin);
1.2025 + }
1.2026 + else if (aUid == KApiExtensionInterfaceUid)
1.2027 + {
1.2028 + return APIExInterface(aOutput, *static_cast<TUid*>(aInput));
1.2029 + }
1.2030 + /* Future cases may be placed here later.*/
1.2031 + else
1.2032 + return CBitmapContext::APIExtension(aUid, aOutput, aInput);
1.2033 + }
1.2034 +
1.2035 +//The methods listed above in APIExtension follow here with the prefix APIEx.
1.2036 +TInt CWindowGc::APIExGetUnderlineMetrics(TAny*& aOutput)
1.2037 + {
1.2038 + const TInt width = Max(iPimpl->iFont->HeightInPixels() / 10,1);
1.2039 + TTwoTInt* ptr = (TTwoTInt*)aOutput;
1.2040 + ptr->iTop = 1 + width / 2;
1.2041 + ptr->iBottom = (ptr->iTop) + width;
1.2042 + return KErrNone;
1.2043 + }
1.2044 +
1.2045 +TInt CWindowGc::APIExSetShadowColor(TAny* aShadowColor)
1.2046 + {
1.2047 + const TRgb shadowColor = *(reinterpret_cast<TRgb*> (aShadowColor));
1.2048 + WriteInt(shadowColor.Internal(), EWsGcOpSetShadowColor);
1.2049 + iPimpl->iShadowColor = shadowColor;
1.2050 + return KErrNone;
1.2051 + }
1.2052 +
1.2053 +TInt CWindowGc::APIExGetShadowColor(TAny*& aOutput)
1.2054 + {
1.2055 + TRgb* ptr = (TRgb*)aOutput;
1.2056 + ptr->SetInternal(iPimpl->iShadowColor.Internal());
1.2057 + return KErrNone;
1.2058 + }
1.2059 +
1.2060 +//Default implementation of reserved virtual
1.2061 +EXPORT_C void CWindowGc::Reserved_CGraphicsContext_2()
1.2062 + {
1.2063 + CBitmapContext::Reserved_CGraphicsContext_2();
1.2064 + }
1.2065 +
1.2066 +//Default implementation of reserved virtual
1.2067 +EXPORT_C void CWindowGc::Reserved_CBitmapContext_1()
1.2068 + {
1.2069 + CBitmapContext::Reserved_CBitmapContext_1();
1.2070 + }
1.2071 +
1.2072 +//Default implementation of reserved virtual
1.2073 +EXPORT_C void CWindowGc::Reserved_CBitmapContext_2()
1.2074 + {
1.2075 + CBitmapContext::Reserved_CBitmapContext_2();
1.2076 + }
1.2077 +
1.2078 +//Default implementation of reserved virtual
1.2079 +EXPORT_C void CWindowGc::Reserved_CBitmapContext_3()
1.2080 + {
1.2081 + CBitmapContext::Reserved_CBitmapContext_3();
1.2082 + }
1.2083 +
1.2084 +// was Reserved_CWindowGc_1
1.2085 +EXPORT_C void CWindowGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect)
1.2086 +/** Draws an abstract artwork.
1.2087 +It does nothing if aDestRect values fall outside the window area.
1.2088 +
1.2089 +@param aId the identifier for the artwork
1.2090 +@param aDestRect the destination rect within the active window for this artwork
1.2091 +
1.2092 +@since 9.2
1.2093 +@released
1.2094 +*/
1.2095 + {
1.2096 + iPimpl->WriteAnyPendingStateChanges();
1.2097 + TWsGcCmdDrawWsGraphic drawWsGraphic(aId,aDestRect);
1.2098 + Write(&drawWsGraphic,sizeof(drawWsGraphic),EWsGcOpDrawWsGraphic);
1.2099 + }
1.2100 +
1.2101 +// Reserved_CWindowGc_2
1.2102 +EXPORT_C void CWindowGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect,const TDesC8& aData)
1.2103 +/** Draws an abstract artwork.
1.2104 +It does nothing if aDestRect values fall outside the window area.
1.2105 +
1.2106 +@param aId the identifier for the artwork
1.2107 +@param aDestRect the destination rect within the active window for this artwork
1.2108 +@param aData opaque datagram to associate with this occasion of drawing. The format is dependent upon the artwork
1.2109 +
1.2110 +@since 9.2
1.2111 +@released
1.2112 +*/
1.2113 + {
1.2114 + iPimpl->WriteAnyPendingStateChanges();
1.2115 + TWsGcCmdDrawWsGraphic drawWsGraphic(aId,aDestRect);
1.2116 + drawWsGraphic.iDataLen = aData.Size();
1.2117 + WriteTextCommand(&drawWsGraphic, sizeof(drawWsGraphic), aData, EWsGcOpDrawWsGraphic, EWsGcOpDrawWsGraphicPtr);
1.2118 + }
1.2119 +
1.2120 +/**
1.2121 +Gets an extension interface specified by the supplied UID, or NULL if it isn't supported.
1.2122 +
1.2123 +@param aInterfaceId The UID of the requested interface
1.2124 +@return A pointer to the interface, or NULL if the interface isn't supported
1.2125 +@publishedPartner
1.2126 +@prototype
1.2127 +*/
1.2128 +EXPORT_C TAny* CWindowGc::Interface(TUid aInterfaceId)
1.2129 + {
1.2130 + TAny* interface = NULL;
1.2131 + if(KErrNone == APIExtension(KApiExtensionInterfaceUid, interface, &aInterfaceId))
1.2132 + return interface;
1.2133 + return NULL;
1.2134 + }
1.2135 +
1.2136 +/**
1.2137 +Gets an extension interface specified by the supplied UID, or NULL if it isn't supported.
1.2138 +
1.2139 +@param aInterfaceId The UID of the requested interface
1.2140 +@return A pointer to the interface, or NULL if the interface isn't supported
1.2141 +@publishedPartner
1.2142 +@prototype
1.2143 +*/
1.2144 +EXPORT_C const TAny* CWindowGc::Interface(TUid aInterfaceId) const
1.2145 + {
1.2146 + return const_cast<CWindowGc*>(this)->Interface(aInterfaceId);
1.2147 + }
1.2148 +
1.2149 +TInt CWindowGc::APIExInterface(TAny*& aInterface, TUid aInterfaceId)
1.2150 + {
1.2151 + if(aInterfaceId == KMWsDrawResourceInterfaceUid)
1.2152 + {
1.2153 + aInterface = static_cast<MWsDrawResource*>(iPimpl);
1.2154 + return KErrNone;
1.2155 + }
1.2156 + return KErrNotSupported;
1.2157 + }
1.2158 +
1.2159 +void CWindowGc::DrawResource(const TPoint& aPos, const RWsDrawableSource& aSource, TGraphicsRotation aRotation)
1.2160 + {
1.2161 + iPimpl->WriteAnyPendingStateChanges();
1.2162 + TWsGcCmdDrawResourceToPos drawWsResource(aSource.WsHandle(), aPos, aRotation);
1.2163 + Write(&drawWsResource, sizeof(drawWsResource), EWsGcOpDrawResourceToPos);
1.2164 + }
1.2165 +
1.2166 +void CWindowGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, TGraphicsRotation aRotation)
1.2167 + {
1.2168 + iPimpl->WriteAnyPendingStateChanges();
1.2169 + TWsGcCmdDrawResourceToRect drawWsResource(aSource.WsHandle(), aDestRect, aRotation);
1.2170 + Write(&drawWsResource, sizeof(drawWsResource), EWsGcOpDrawResourceToRect);
1.2171 + }
1.2172 +
1.2173 +void CWindowGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TRect& aSrcRect, TGraphicsRotation aRotation)
1.2174 + {
1.2175 + iPimpl->WriteAnyPendingStateChanges();
1.2176 + TWsGcCmdDrawResourceFromRectToRect drawWsResource(aSource.WsHandle(), aDestRect, aSrcRect, aRotation);
1.2177 + Write(&drawWsResource, sizeof(drawWsResource), EWsGcOpDrawResourceFromRectToRect);
1.2178 + }
1.2179 +
1.2180 +void CWindowGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TDesC8& aParam)
1.2181 + {
1.2182 + iPimpl->WriteAnyPendingStateChanges();
1.2183 + TWsGcCmdDrawResourceWithData drawWsResource(aSource.WsHandle(), aDestRect, &aParam);
1.2184 + Write(&drawWsResource, sizeof(drawWsResource),EWsGcOpDrawResourceWithData);
1.2185 + }
1.2186 +
1.2187 +//Default implementation of reserved virtual
1.2188 +EXPORT_C void CWindowGc::Reserved_CWindowGc_3()
1.2189 + {
1.2190 + }
1.2191 +
1.2192 +//Default implementation of reserved virtual
1.2193 +EXPORT_C void CWindowGc::Reserved_CWindowGc_4()
1.2194 + {
1.2195 + }
1.2196 +
1.2197 +//Default implementation of reserved virtual
1.2198 +EXPORT_C void CWindowGc::Reserved_CWindowGc_5()
1.2199 + {
1.2200 + }
1.2201 +
1.2202 +/**
1.2203 +Default constructor.
1.2204 +Only for embedding instances of RWsDrawableSource into other classes as data members.
1.2205 +Before a RWsDrawableSource can be used the other constructor must be called.
1.2206 + */
1.2207 +EXPORT_C RWsDrawableSource::RWsDrawableSource()
1.2208 + : iDrawableId(KSgNullDrawableId), iScreenNumber(KSgScreenIdMain)
1.2209 + {
1.2210 + }
1.2211 +
1.2212 +/**
1.2213 +Constructor.
1.2214 +@param aWs Session to the window server
1.2215 +
1.2216 +@pre Connection to the window server is established
1.2217 + */
1.2218 +EXPORT_C RWsDrawableSource::RWsDrawableSource(RWsSession &aWs)
1.2219 + : MWsClientClass(aWs.iBuffer), iDrawableId(KSgNullDrawableId), iScreenNumber(KSgScreenIdMain)
1.2220 + {
1.2221 + }
1.2222 +
1.2223 +/**
1.2224 +Create window server object for resource drawing operation via window server.
1.2225 +
1.2226 +This object will be identified by a unique handle and will be associated with drawable resource which is passed as a parameter.
1.2227 +
1.2228 +This object will be created for drawing onto the default screen only.
1.2229 +
1.2230 +@see CWindowGc
1.2231 +@param aDrawable Drawable resource.
1.2232 +
1.2233 +@post Drawable source is created and can be used by window server. The reference counter of the underlying
1.2234 + image resource is incremented.
1.2235 +
1.2236 +@return KErrNone if successful, KErrArgument if the image resource is not valid,
1.2237 + KErrAlreadyExists if this handle is already associated with a
1.2238 + specific resource, otherwise one of the system-wide error codes.
1.2239 + */
1.2240 +EXPORT_C TInt RWsDrawableSource::Create(const RSgDrawable& aDrawable)
1.2241 + {
1.2242 + return Create(aDrawable, KSgScreenIdMain);
1.2243 + }
1.2244 +
1.2245 +/**
1.2246 +Create window server object for resource drawing operation via window server.
1.2247 +
1.2248 +This object will be identified by unique handle and will be associated with drawable resource which is passed as a parameter.
1.2249 +
1.2250 +This object will be created for drawing onto the specified screen only.
1.2251 +
1.2252 +@see CWindowGc
1.2253 +@param aDrawable Drawable resource.
1.2254 +@param aScreenNumber The screen onto which this drawable resource can be drawn.
1.2255 +
1.2256 +@post Drawable source is created and can be used by window server. The reference counter of the underlying
1.2257 + image resource is incremented.
1.2258 +
1.2259 +@return KErrNone if successful, KErrArgument if the image resource is not valid
1.2260 + or if the specified screen is invalid, KErrAlreadyExists if this handle
1.2261 + is already associated with a specific resource, otherwise one of the
1.2262 + system-wide error codes.
1.2263 + */
1.2264 +EXPORT_C TInt RWsDrawableSource::Create(const RSgDrawable& aDrawable, TInt aScreenNumber)
1.2265 + {
1.2266 + if (iWsHandle)
1.2267 + {
1.2268 + return KErrAlreadyExists;
1.2269 + }
1.2270 + CGraphicsResourceWrapperFactory* grwFactory = new CGraphicsResourceWrapperFactory();
1.2271 + if (!grwFactory)
1.2272 + return KErrNoMemory;
1.2273 + // coverity[uninit_use_in_call]
1.2274 + CGraphicsResourceWrapper* graphicsResource = grwFactory->NewGraphicsResourceWrapper();
1.2275 + if(!graphicsResource)
1.2276 + {
1.2277 + delete grwFactory;
1.2278 + return KErrNotSupported;
1.2279 + }
1.2280 + if (graphicsResource->IsNull(aDrawable) || aScreenNumber < 0)
1.2281 + {
1.2282 + delete graphicsResource;
1.2283 + delete grwFactory;
1.2284 + return KErrArgument;
1.2285 + }
1.2286 + TWsClCmdCreateDrawableSource create(graphicsResource->Id(aDrawable), aScreenNumber);
1.2287 + TInt ret;
1.2288 + if ((ret = iBuffer->WriteReplyWs(&create, sizeof(TWsClCmdCreateDrawableSource), EWsClOpCreateDrawableSource)) < 0)
1.2289 + {
1.2290 + delete graphicsResource;
1.2291 + delete grwFactory;
1.2292 + return ret;
1.2293 + }
1.2294 + iWsHandle = ret;
1.2295 + iDrawableId = graphicsResource->Id(aDrawable);
1.2296 + iScreenNumber = aScreenNumber;
1.2297 + delete graphicsResource;
1.2298 + delete grwFactory;
1.2299 + return KErrNone;
1.2300 + }
1.2301 +
1.2302 +/**
1.2303 +Destroy the window server drawable source.
1.2304 +Calling this method on a object that is not associated with any RSgDrawable
1.2305 +resource will have no effect. Once Close() is called, this drawable source object can be reused.
1.2306 +
1.2307 +@post The window server drawable object is destroyed. The instance is no longer associated
1.2308 + with a RSgDrawable specific resource. The reference counter of the underlying
1.2309 + image resource is decremented.
1.2310 +*/
1.2311 +EXPORT_C void RWsDrawableSource::Close()
1.2312 + {
1.2313 + if (iWsHandle)
1.2314 + {
1.2315 + Write(EWsDrawableSourceOpFree);
1.2316 + iWsHandle = 0;
1.2317 + iDrawableId = KSgNullDrawableId;
1.2318 + iScreenNumber = KSgScreenIdMain;
1.2319 + }
1.2320 + }
1.2321 +
1.2322 +/**
1.2323 + Get the unique ID of the associated drawable resource.
1.2324 + */
1.2325 +EXPORT_C const TSgDrawableId& RWsDrawableSource::DrawableId() const
1.2326 + {
1.2327 + return iDrawableId;
1.2328 + }
1.2329 +
1.2330 +/**
1.2331 + Get the screen number of the drawable source.
1.2332 + */
1.2333 +EXPORT_C TInt RWsDrawableSource::ScreenNumber() const
1.2334 + {
1.2335 + return iScreenNumber;
1.2336 + }