windowing/windowserver/nga/CLIENT/RGC.CPP
changeset 0 5d03bc08d59c
child 150 57c618273d5c
child 160 969102054596
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Shells for window server graphics class
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <graphics/wsdrawresource.h>
       
    20 #include "../SERVER/w32cmd.h"
       
    21 #include "CLIENT.H"
       
    22 #include "w32comm.h"
       
    23 #include "graphicsresourcewrapper.h"
       
    24 #include <graphics/gdi/gdiconsts.h>
       
    25 #include <graphics/gdi/gdistructs.h>
       
    26 #include "graphics/windowserverconstants.h"
       
    27 
       
    28 #define KDefaultShadowColor KRgbGray
       
    29 enum {EPolygonMaxHeaderSize=sizeof(TWsCmdHeader)+sizeof(TWsGcCmdSegmentedDrawPolygonData)};
       
    30 
       
    31 //
       
    32 // class CWindowGc::CPimpl
       
    33 //
       
    34 
       
    35 NONSHARABLE_STRUCT(CWindowGc::CPimpl): public CBase, public MWsDrawResource
       
    36 /** @internalComponent @released */
       
    37 	{
       
    38 public:
       
    39 	enum TStateType
       
    40 	    {
       
    41 	    EStateBrushColor           = 1<<0,
       
    42 	    EStateBrushStyle           = 1<<1,
       
    43 	    EStatePenColor             = 1<<2,
       
    44 	    EStatePenStyle             = 1<<3,
       
    45 	    EStatePenSize              = 1<<4,           
       
    46 	    EStateDrawMode             = 1<<5,
       
    47 	    EStateClippingRect         = 1<<6,
       
    48         EStateUnderlineStyle       = 1<<7,
       
    49         EStateStrikethroughStyle   = 1<<8,
       
    50         EStateWordJustification    = 1<<9,
       
    51         EStateCharJustification    = 1<<10,
       
    52 	    };
       
    53 
       
    54 	CPimpl(CWindowGc& aGc);
       
    55 	void WriteAnyPendingStateChanges();
       
    56 	void ResetPendingState();
       
    57 	void StorePendingStateChange(TStateType aState, const TAny* aValue);
       
    58 	TUint32 GetState() const {return iPendingState;}
       
    59 	void CancelPendingClippingRect();
       
    60 	~CPimpl();
       
    61 public: //from MWsDrawResource
       
    62 	void DrawResource(const TPoint& aPos, const RWsDrawableSource& aSource, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
       
    63 		{
       
    64 		iGc.DrawResource(aPos, aSource, aRotation);
       
    65 		}
       
    66 	void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
       
    67 		{
       
    68 		iGc.DrawResource(aDestRect, aSource, aRotation);
       
    69 		}
       
    70 	void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TRect& aSrcRect, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
       
    71 		{
       
    72 		iGc.DrawResource(aDestRect, aSource, aSrcRect, aRotation);
       
    73 		}
       
    74 	void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TDesC8& aParam)
       
    75 		{
       
    76 		iGc.DrawResource(aDestRect, aSource, aParam);
       
    77 		}
       
    78 public:
       
    79 	CWindowGc& iGc;
       
    80 	CFbsFont* iFont;
       
    81 	TRgb iShadowColor;
       
    82     TBool iForceWrite;
       
    83     TBool iClippingRectSet;
       
    84         
       
    85 private:
       
    86     TUint32 iPendingState;
       
    87 
       
    88     // Pending state - used to store requested state changes not yet written to wserv
       
    89     TRgb iPendingBrushColor;
       
    90 	TBrushStyle iPendingBrushStyle;
       
    91     TRgb iPendingPenColor;
       
    92     TPenStyle iPendingPenStyle;
       
    93     TSize iPendingPenSize;
       
    94     TDrawMode iPendingDrawMode;
       
    95     TRect iPendingClippingRect;
       
    96     TFontUnderline iPendingUnderlineStyle;
       
    97     TFontStrikethrough iPendingStrikethroughStyle;
       
    98     TWsGcCmdSetJustification iPendingWordJustification;
       
    99     TWsGcCmdSetJustification iPendingCharJustification;
       
   100 
       
   101     // Current state - values that have actually been written to wserv
       
   102     TRgb iCurrentBrushColor;
       
   103 	TBrushStyle iCurrentBrushStyle;
       
   104     TRgb iCurrentPenColor;
       
   105     TPenStyle iCurrentPenStyle;
       
   106     TSize iCurrentPenSize;
       
   107     TDrawMode iCurrentDrawMode;
       
   108     TFontUnderline iCurrentUnderlineStyle;
       
   109     TFontStrikethrough iCurrentStrikethroughStyle;
       
   110     TWsGcCmdSetJustification iCurrentWordJustification;
       
   111     TWsGcCmdSetJustification iCurrentCharJustification;
       
   112 	};
       
   113 
       
   114 CWindowGc::CPimpl::CPimpl(CWindowGc& aGc)
       
   115 	: iGc(aGc), iFont(NULL), iShadowColor(KDefaultShadowColor)
       
   116 	{
       
   117 	ResetPendingState();
       
   118 	}
       
   119 
       
   120 CWindowGc::CPimpl::~CPimpl()
       
   121 	{
       
   122 	iFont = NULL;
       
   123 	}
       
   124 
       
   125 void CWindowGc::CPimpl::CancelPendingClippingRect()
       
   126     {
       
   127     iPendingState &= ~EStateClippingRect;
       
   128     }
       
   129 
       
   130 void CWindowGc::CPimpl::WriteAnyPendingStateChanges()
       
   131     {
       
   132     if (iPendingState == 0)
       
   133         return;
       
   134     
       
   135     if (iPendingState & EStateDrawMode)
       
   136         {
       
   137         if (iPendingDrawMode != iCurrentDrawMode)
       
   138             {
       
   139             iGc.WriteInt(iPendingDrawMode,EWsGcOpSetDrawMode);
       
   140             iCurrentDrawMode = iPendingDrawMode;
       
   141             }
       
   142         }
       
   143     
       
   144     if (iPendingState & EStateBrushStyle)
       
   145         {
       
   146         if (iPendingBrushStyle != iCurrentBrushStyle)
       
   147             {
       
   148             iGc.WriteInt(iPendingBrushStyle,EWsGcOpSetBrushStyle);
       
   149             iCurrentBrushStyle = iPendingBrushStyle;
       
   150             }
       
   151         }
       
   152 
       
   153     if (iPendingState & EStateBrushColor)
       
   154         {
       
   155         // Brush colour optimisation more conservative (than for other state changes) because server-side code modifies it without client's knowledge
       
   156         if (iPendingBrushColor != iCurrentBrushColor || iForceWrite)
       
   157             {
       
   158             iGc.WriteInt(iPendingBrushColor.Internal(),EWsGcOpSetBrushColor);
       
   159             iCurrentBrushColor = iPendingBrushColor;
       
   160             iForceWrite = EFalse;
       
   161             }
       
   162         }
       
   163 
       
   164     if (iPendingState & EStatePenStyle)
       
   165         {
       
   166         if (iPendingPenStyle != iCurrentPenStyle)
       
   167             {
       
   168             iGc.WriteInt(iPendingPenStyle,EWsGcOpSetPenStyle);
       
   169             iCurrentPenStyle = iPendingPenStyle;   
       
   170             }
       
   171         }
       
   172         
       
   173     if (iPendingState & EStatePenColor)
       
   174         {
       
   175         if (iPendingPenColor != iCurrentPenColor)
       
   176             {
       
   177             iGc.WriteInt(iPendingPenColor.Internal(),EWsGcOpSetPenColor);
       
   178             iCurrentPenColor = iPendingPenColor;            
       
   179             }
       
   180         }
       
   181     
       
   182     if (iPendingState & EStateClippingRect)
       
   183         {
       
   184         iGc.WriteRect(iPendingClippingRect,EWsGcOpSetClippingRect);
       
   185         iClippingRectSet = ETrue;
       
   186         }
       
   187 
       
   188     if (iPendingState & EStateUnderlineStyle)
       
   189         {
       
   190         if (iPendingUnderlineStyle != iCurrentUnderlineStyle)
       
   191             {
       
   192             iGc.WriteInt(iPendingUnderlineStyle,EWsGcOpSetUnderlineStyle);
       
   193             iCurrentUnderlineStyle = iPendingUnderlineStyle;            
       
   194             }
       
   195         }
       
   196     
       
   197     if (iPendingState & EStateStrikethroughStyle)
       
   198         {
       
   199         if (iPendingStrikethroughStyle != iCurrentStrikethroughStyle)
       
   200             {
       
   201             iGc.WriteInt(iPendingStrikethroughStyle,EWsGcOpSetStrikethroughStyle);
       
   202             iCurrentStrikethroughStyle = iPendingStrikethroughStyle;
       
   203             }
       
   204         }
       
   205     
       
   206     if (iPendingState & EStatePenSize)
       
   207         {
       
   208         if (iPendingPenSize != iCurrentPenSize)
       
   209             {
       
   210             iGc.WriteSize(iPendingPenSize,EWsGcOpSetPenSize);
       
   211             iCurrentPenSize = iPendingPenSize;
       
   212             }
       
   213         }    
       
   214 
       
   215     if (iPendingState & EStateWordJustification)
       
   216         {
       
   217         if (iPendingWordJustification.excessWidth != iCurrentWordJustification.excessWidth
       
   218             || iPendingWordJustification.numGaps != iCurrentWordJustification.numGaps)
       
   219             {
       
   220             iGc.Write(&iPendingWordJustification,sizeof(iPendingWordJustification),EWsGcOpSetWordJustification);
       
   221             iCurrentWordJustification = iPendingWordJustification;
       
   222             }
       
   223         }    
       
   224 
       
   225     if (iPendingState & EStateCharJustification)
       
   226         {
       
   227         if (iPendingCharJustification.excessWidth != iCurrentCharJustification.excessWidth
       
   228             || iPendingCharJustification.numGaps != iCurrentCharJustification.numGaps)
       
   229             {
       
   230             iGc.Write(&iPendingCharJustification,sizeof(iPendingCharJustification),EWsGcOpSetCharJustification);
       
   231             iCurrentCharJustification = iPendingCharJustification;
       
   232             }
       
   233         }    
       
   234     
       
   235     iPendingState = 0;
       
   236     }
       
   237 
       
   238 void CWindowGc::CPimpl::ResetPendingState()
       
   239     {
       
   240     // This function should only be called from CWindowGc::Reset()
       
   241     iForceWrite = EFalse;
       
   242     iPendingState = 0;
       
   243 
       
   244     iClippingRectSet = EFalse;
       
   245 
       
   246     // The following default values are the same as those used by CFbsBitGc::Reset()
       
   247     iPendingBrushColor = KRgbWhite;
       
   248     iPendingBrushStyle = CGraphicsContext::ENullBrush;
       
   249     iPendingPenColor = KRgbBlack;
       
   250     iPendingPenStyle = CGraphicsContext::ESolidPen;
       
   251     iPendingPenSize = TSize(1,1);
       
   252     iPendingDrawMode = CGraphicsContext::EDrawModePEN;
       
   253     iPendingUnderlineStyle = EUnderlineOff;    
       
   254     iPendingStrikethroughStyle = EStrikethroughOff;
       
   255     iPendingWordJustification.excessWidth = 0;
       
   256     iPendingWordJustification.numGaps = 0;
       
   257     iPendingCharJustification.excessWidth = 0;
       
   258     iPendingCharJustification.numGaps = 0;
       
   259         
       
   260     iCurrentBrushColor = iPendingBrushColor;
       
   261     iCurrentBrushStyle = iPendingBrushStyle;
       
   262     iCurrentPenColor = iPendingPenColor;
       
   263     iCurrentPenStyle = iPendingPenStyle;
       
   264     iCurrentPenSize = iPendingPenSize;    
       
   265     iCurrentDrawMode = iPendingDrawMode;
       
   266     iCurrentUnderlineStyle = iPendingUnderlineStyle;
       
   267     iCurrentStrikethroughStyle = iPendingStrikethroughStyle;
       
   268     iCurrentWordJustification.excessWidth = iPendingWordJustification.excessWidth;
       
   269     iCurrentWordJustification.numGaps = iPendingWordJustification.numGaps;
       
   270     iCurrentCharJustification.excessWidth = iPendingCharJustification.excessWidth;
       
   271     iCurrentCharJustification.numGaps = iPendingCharJustification.numGaps;
       
   272     }
       
   273     
       
   274 void CWindowGc::CPimpl::StorePendingStateChange(TStateType aState, const TAny* aValue)
       
   275     {
       
   276     switch (aState)
       
   277         {
       
   278         case EStateBrushColor:
       
   279             iPendingState |= EStateBrushColor;
       
   280             iPendingBrushColor = *((TRgb*)(aValue));
       
   281             break;
       
   282         case EStateBrushStyle:
       
   283             iPendingState|=EStateBrushStyle;
       
   284             iPendingBrushStyle = *((TBrushStyle*)(aValue));
       
   285             break;
       
   286         case EStatePenColor:
       
   287             iPendingState|=EStatePenColor;
       
   288             iPendingPenColor = *((TRgb*)(aValue));
       
   289             break;
       
   290         case EStatePenStyle:
       
   291             iPendingState|=EStatePenStyle;
       
   292             iPendingPenStyle = *((TPenStyle*)(aValue));
       
   293             break;
       
   294         case EStateDrawMode:
       
   295             iPendingState|=EStateDrawMode;
       
   296             iPendingDrawMode = *((TDrawMode*)(aValue));
       
   297             break;
       
   298         case EStateClippingRect:
       
   299             iPendingState|=EStateClippingRect;
       
   300             iPendingClippingRect = *((TRect*)(aValue));
       
   301             break;
       
   302         case EStateUnderlineStyle:
       
   303             iPendingState|=EStateUnderlineStyle;
       
   304             iPendingUnderlineStyle = *((TFontUnderline*)(aValue));
       
   305             break;
       
   306         case EStateStrikethroughStyle:
       
   307             iPendingState|=EStateStrikethroughStyle;
       
   308             iPendingStrikethroughStyle= *((TFontStrikethrough*)(aValue));
       
   309             break;
       
   310         case EStatePenSize:
       
   311             iPendingState|=EStatePenSize;
       
   312             iPendingPenSize = *((TSize*)(aValue));
       
   313             break;
       
   314         case EStateWordJustification:
       
   315             iPendingState|=EStateWordJustification;
       
   316             iPendingWordJustification = *((TWsGcCmdSetJustification*)(aValue));
       
   317             break;
       
   318         case EStateCharJustification:
       
   319             iPendingState|=EStateCharJustification;
       
   320             iPendingCharJustification = *((TWsGcCmdSetJustification*)(aValue));
       
   321             break;
       
   322         default:
       
   323             break;
       
   324         }
       
   325     }
       
   326 
       
   327 //
       
   328 // class CWindowGc
       
   329 //
       
   330 
       
   331 EXPORT_C CWindowGc::CWindowGc(CWsScreenDevice *aDevice) : MWsClientClass(aDevice->iBuffer), iPimpl(NULL), iDevice(aDevice)
       
   332 /** Constructor which creates, but does not initialise a graphics context. 
       
   333 
       
   334 @param aDevice Any screen device owned by the same session. Its life time 
       
   335 should be at least as long as the gc itself. 
       
   336 @see CWsScreenDevice::CreateContext() */
       
   337 	{}
       
   338 
       
   339 EXPORT_C CWindowGc::~CWindowGc()
       
   340 /** Destructor. */
       
   341 	{
       
   342 	if (iBuffer && iWsHandle)
       
   343 		Write(EWsGcOpFree);
       
   344 	delete iPimpl;
       
   345 	}
       
   346 
       
   347 void CWindowGc::WriteTextCommand(TAny *cmd, TInt len,const TDesC &aBuf,TInt opcode,TInt opcodePtr) const
       
   348 	{
       
   349 	if ((aBuf.Size()+len)>(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)))
       
   350 		{
       
   351 		WriteReplyByProvidingRemoteReadAccess(cmd,len,&aBuf,opcodePtr);
       
   352 		}
       
   353 	else
       
   354 		{
       
   355 		Write(cmd,len,aBuf.Ptr(),aBuf.Size(),opcode);
       
   356 		}
       
   357 	}
       
   358 	
       
   359 void CWindowGc::WriteTextCommand(TAny *cmd, TInt len,const TDesC8 &aBuf,TInt opcode,TInt opcodePtr) const
       
   360 	{
       
   361 	if ((aBuf.Size()+len)>(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)))
       
   362 		{
       
   363 		WriteReplyByProvidingRemoteReadAccess(cmd,len,&aBuf,opcodePtr);
       
   364 		}
       
   365 	else
       
   366 		{
       
   367 		Write(cmd,len,aBuf.Ptr(),aBuf.Size(),opcode);
       
   368 		}
       
   369 	}	
       
   370 	
       
   371 EXPORT_C TInt CWindowGc::Construct()
       
   372 /** Completes construction. 
       
   373 
       
   374 @return KErrNone if successful, otherwise a leave error. 
       
   375 @panic TW32Panic 17 in debug builds if called on an already constructed object.
       
   376 This function always causes a flush of the window server buffer. */
       
   377 	{
       
   378 	__ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction));
       
   379 	iPimpl = new CPimpl(*this);
       
   380 	if (!iPimpl)
       
   381 		return KErrNoMemory;
       
   382 	TInt ret;
       
   383 	if ((ret=iBuffer->WriteReplyWs(EWsClOpCreateGc))<0)
       
   384 		return(ret);
       
   385 	iWsHandle=ret;
       
   386 	return(KErrNone);
       
   387 	}
       
   388 
       
   389 EXPORT_C void CWindowGc::Activate(RDrawableWindow &aDevice)
       
   390 /** 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.  
       
   391 
       
   392 When drawing is complete, the code using the context should call Deactivate(). 
       
   393 Draw methods invoked after an Activate() will affect the window specified. 
       
   394 A graphics context can only be active for one window at a time. A panic occurs 
       
   395 if a draw function is called before calling this function, or if Activate() 
       
   396 is called twice without an intervening Deactivate().
       
   397 
       
   398 @param aWindow The window for which the graphics context is to be activated. */
       
   399 	{
       
   400 	TUint devicePointer = WriteReplyInt(aDevice.WsHandle(),EWsGcOpActivate);
       
   401 	iDevice = (CWsScreenDevice*)devicePointer;
       
   402 	iPimpl->iForceWrite = ETrue; // needed because brush colour set to window background colour in CWsGc::Activate
       
   403 	}
       
   404 
       
   405 EXPORT_C void CWindowGc::Deactivate()
       
   406 /** Frees the graphics context to be used with another window. 
       
   407 
       
   408 This method should be called when the application has completed drawing to 
       
   409 the window. */
       
   410 	{
       
   411 	iPimpl->ResetPendingState(); // needed because server-side state is reset on deactivation
       
   412 	Write(EWsGcOpDeactivate);
       
   413 	iPimpl->iFont=NULL;
       
   414 	iPimpl->iShadowColor = KDefaultShadowColor;
       
   415 	}
       
   416 
       
   417 //====================Functions from GDI.H===============================
       
   418 
       
   419 EXPORT_C CGraphicsDevice* CWindowGc::Device() const
       
   420 /** Returns a pointer to the device, more specifically a CWsScreenDevice, for the screen that the WindowGc was last activated on.
       
   421 If the WindowGc has not been activated at all, it then returns the device that was passed to its constructor.
       
   422 
       
   423 The user should be careful when calling this function since it can return the screen device of any screen in the system.
       
   424 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.
       
   425 @return A pointer to the device for the screen that the WindowGc was last activated on or the device passed at construction*/
       
   426 	{
       
   427 	return(iDevice);
       
   428 	}
       
   429 
       
   430 EXPORT_C void CWindowGc::SetOrigin(const TPoint &aPoint)
       
   431 /** Sets the position of the co-ordinate origin. 
       
   432 
       
   433 All subsequent drawing operations are then done relative to this origin. The 
       
   434 default origin is (0,0), the top left corner of the window.
       
   435 
       
   436 @param aPoint A point for the origin, default (0,0). 
       
   437 @see CGraphicsContext::SetOrigin() */
       
   438 	{
       
   439 	if ( iPimpl->GetState() & CPimpl::EStateClippingRect )
       
   440 	    {
       
   441 	    iPimpl->WriteAnyPendingStateChanges();
       
   442 	    }
       
   443 	WritePoint(aPoint,EWsGcOpSetOrigin);
       
   444 	}
       
   445 
       
   446 EXPORT_C void CWindowGc::SetClippingRect(const TRect& aRect)
       
   447 /** Sets a clipping rectangle.
       
   448 
       
   449 Graphics drawn to the window are clipped, so that only items which fall within 
       
   450 the rectangle are displayed. 
       
   451 
       
   452 Note that clipping is additive. If a clipping region has been set using SetClippingRegion() 
       
   453 then clipping will be to the intersection of that region and this rectangle.
       
   454 
       
   455 @param aRect The clipping rectangle in window co-ordinates. Note that this rectangle is 
       
   456 tranformed by the current drawing co-ordinate origin before it is used. 
       
   457 The co-ordinate origin is set using SetOrigin().
       
   458  
       
   459 @see SetClippingRegion() */
       
   460 	{
       
   461     TRect rect(aRect);
       
   462     iPimpl->StorePendingStateChange(CPimpl::EStateClippingRect, &rect);
       
   463 	}
       
   464 
       
   465 EXPORT_C void CWindowGc::CancelClippingRect()
       
   466 /** Cancels the clipping rectangle. 
       
   467 
       
   468 @see SetClippingRect() */
       
   469 	{
       
   470 	if (iPimpl->GetState() & CPimpl::EStateClippingRect)
       
   471 	    {
       
   472 	    iPimpl->CancelPendingClippingRect();
       
   473 	    }
       
   474 	
       
   475 	if (iPimpl->iClippingRectSet)
       
   476 	    {
       
   477         Write(EWsGcOpCancelClippingRect);
       
   478 	    }
       
   479 
       
   480 	iPimpl->iClippingRectSet = EFalse;
       
   481 	}
       
   482 
       
   483 EXPORT_C TInt CWindowGc::SetClippingRegion(const TRegion &aRegion)
       
   484 /** Sets the clipping region.
       
   485 
       
   486 Drawing is always clipped to the visible area of a window. The region specified 
       
   487 by this function is in addition to that area.
       
   488 
       
   489 This function always causes a flush of the window server buffer.
       
   490 
       
   491 @param aRegion The new clipping region in window co-ordinates 
       
   492 as used in SetClippingRect(). The clipping region is transformed by the current 
       
   493 drawing origin before use.
       
   494 
       
   495 @return KErrNone if successful, KErrNoMemory if there is insufficient memory 
       
   496 to create the region on the server side, otherwise another error code. 
       
   497 
       
   498 @see SetClippingRect() */
       
   499 	{
       
   500 	const TInt regionCount=aRegion.Count();
       
   501 	TPtrC8 ptrRect(reinterpret_cast<const TUint8*>(aRegion.RectangleList()),regionCount*sizeof(TRect));
       
   502 	return(WriteReplyByProvidingRemoteReadAccess(&regionCount,sizeof(regionCount),&ptrRect,EWsGcOpSetClippingRegion));
       
   503 	}
       
   504 
       
   505 EXPORT_C void CWindowGc::CancelClippingRegion()
       
   506 /** Cancels the current clipping region. */
       
   507 	{
       
   508 	Write(EWsGcOpCancelClippingRegion);
       
   509 	}
       
   510 
       
   511 EXPORT_C void CWindowGc::SetDrawMode(TDrawMode aDrawingMode)
       
   512 /** Sets the drawing mode. 
       
   513 
       
   514 This affects the colour that is actually drawn, because it defines the way 
       
   515 that the current screen colour logically combines with the current pen colour 
       
   516 and brush colour. 
       
   517 
       
   518 There are 13 drawing modes (see CGraphicsContext::TDrawMode enum), each giving 
       
   519 different logical combinations of pen, brush and screen colours. Each mode 
       
   520 is produced by ORing together different combinations of seven drawing mode 
       
   521 components (see CGraphicsContext::TDrawModeComponents enum).
       
   522 
       
   523 The three most important modes are TDrawMode::EDrawModePEN, TDrawMode::EDrawModeNOTSCREEN 
       
   524 and TDrawMode::EDrawModeXOR. The default drawing mode is TDrawMode::EDrawModePEN.
       
   525 
       
   526 The drawing mode is over-ridden for line and shape drawing functions when 
       
   527 a wide pen line has been selected. It is forced to TDrawMode::EDrawModePEN. 
       
   528 This is to prevent undesired effects at line joins (vertexes).
       
   529 
       
   530 Notes:
       
   531 
       
   532 TDrawMode::EDrawModeAND gives a "colour filter" effect. For example:
       
   533 
       
   534 ANDing with white gives the original colour 
       
   535 
       
   536 ANDing with black gives black 
       
   537 
       
   538 TDrawMode::EDrawModeOR gives a "colour boost" effect. For example:
       
   539 
       
   540 ORing with black gives the original colour 
       
   541 
       
   542 ORing with white gives white 
       
   543 
       
   544 TDrawMode::EDrawModeXOR gives an "Exclusive OR" effect. For example:
       
   545 
       
   546 white XOR black gives white 
       
   547 
       
   548 white XOR white gives black 
       
   549 
       
   550 black XOR black gives black
       
   551 
       
   552 @param aDrawingMode A drawing mode. 
       
   553 @see CGraphicsContext::SetDrawMode() */
       
   554 	{
       
   555     iPimpl->StorePendingStateChange(CPimpl::EStateDrawMode, &aDrawingMode);
       
   556 	}
       
   557 
       
   558 EXPORT_C void CWindowGc::UseFont(const CFont *aFont)
       
   559 /** Sets this context's font.
       
   560 
       
   561 The font is used for text drawing. If the font is already in the font and 
       
   562 bitmap server's memory the GDI will share that copy.
       
   563 
       
   564 Note that this function must be called prior to drawing text or the calling 
       
   565 thread will panic.
       
   566 
       
   567 @param aFont A device font. 
       
   568 @see CGraphicsContext::UseFont() */
       
   569 	{
       
   570 	if (iPimpl->iFont!=(CFbsFont *)aFont)
       
   571 		{
       
   572 		iPimpl->iFont=(CFbsFont *)aFont;
       
   573 		WriteInt(iPimpl->iFont->Handle(),EWsGcOpUseFont);
       
   574 		}
       
   575 	}
       
   576 
       
   577 EXPORT_C void CWindowGc::DiscardFont()
       
   578 /** Discards a font. 
       
   579 
       
   580 This frees up the memory used (if the font is not being shared with some other 
       
   581 process).
       
   582 
       
   583 Note that if no font is in use when this function is called, then there is no effect.
       
   584 
       
   585 @see CGraphicsContext::DiscardFont() */
       
   586 	{
       
   587 	Write(EWsGcOpDiscardFont);
       
   588 	iPimpl->iFont=NULL;
       
   589 	}
       
   590 
       
   591 EXPORT_C void CWindowGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
       
   592 /** Sets the underline style for all subsequently drawn text.
       
   593 
       
   594 @param aUnderlineStyle The underline style: either on or off.
       
   595 @see CGraphicsContext::SetUnderlineStyle() */
       
   596 	{
       
   597     iPimpl->StorePendingStateChange(CPimpl::EStateUnderlineStyle, &aUnderlineStyle);	
       
   598 	}
       
   599 
       
   600 EXPORT_C void CWindowGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
       
   601 /** Sets the strikethrough style for all subsequently drawn text.
       
   602 
       
   603 @param aStrikethroughStyle The strikethrough style: either on or off. 
       
   604 @see CGraphicsContext::SetStrikethroughStyle() */
       
   605 	{
       
   606 	iPimpl->StorePendingStateChange(CPimpl::EStateStrikethroughStyle, &aStrikethroughStyle);
       
   607 	}
       
   608 
       
   609 void CWindowGc::SetJustification(TInt aExcessWidth,TInt aNumGaps, TInt aOpcode)
       
   610 	{
       
   611 	TWsGcCmdSetJustification justification;
       
   612 
       
   613 	justification.excessWidth=aExcessWidth;
       
   614 	justification.numGaps=aNumGaps;
       
   615 
       
   616 	if (aOpcode == EWsGcOpSetWordJustification)
       
   617 	    {
       
   618         iPimpl->StorePendingStateChange(CPimpl::EStateWordJustification, &justification);
       
   619 	    }
       
   620 	else if (aOpcode == EWsGcOpSetCharJustification)
       
   621 	    {
       
   622         iPimpl->StorePendingStateChange(CPimpl::EStateCharJustification, &justification);
       
   623 	    }
       
   624 	}
       
   625 
       
   626 EXPORT_C void CWindowGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps)
       
   627 /** Sets word justification.
       
   628 
       
   629 This function is particularly useful for doing WYSIWYG underlining or strikethrough, 
       
   630 as it ensures that the lines extend correctly into the gaps between words. It is not 
       
   631 intended for regular use by developers.
       
   632 
       
   633 @param aExcessWidth The excess width (in pixels) to be distributed between 
       
   634 the specified number of gaps (starting immediately) 
       
   635 @param aNumGaps The number of gaps between words 
       
   636 @see CGraphicsContext::SetWordJustification() */
       
   637 	{
       
   638 	SetJustification(aExcessWidth, aNumGaps, EWsGcOpSetWordJustification);
       
   639 	}
       
   640 
       
   641 EXPORT_C void CWindowGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars)
       
   642 /** Sets the character justification.
       
   643 
       
   644 This function is used primarily to get accurate WYSIWYG, and is not intended 
       
   645 for regular use by developers.
       
   646 
       
   647 The text line that is to be justified has a certain number of characters (this 
       
   648 includes the spaces between the words). It also has a distance (in pixels) 
       
   649 between the end of the last word and the actual end of the line (right hand 
       
   650 margin, usually). These excess width pixels are distributed amongst all the 
       
   651 characters, increasing the gaps between them, to achieve full justification 
       
   652 of the text line.
       
   653 
       
   654 This function is particularly useful for WYSIWYG underlining or strikethrough, 
       
   655 as it ensures that the lines extend into the gaps between characters.
       
   656 
       
   657 See CGraphicsContext::SetCharJustification() for more information.
       
   658 
       
   659 @param aExcessWidth The excess width (in pixels) to be distributed between 
       
   660 the specified number of characters. 
       
   661 @param aNumChars The number of characters involved 
       
   662 @see CGraphicsContext::SetCharJustification() */
       
   663 	{
       
   664 	SetJustification(aExcessWidth, aNumChars, EWsGcOpSetCharJustification);
       
   665 	}
       
   666 
       
   667 EXPORT_C void CWindowGc::SetPenColor(const TRgb &aColor)
       
   668 /** Sets the pen colour.
       
   669 
       
   670 The effective pen colour depends on the drawing mode (see SetDrawMode()).
       
   671 
       
   672 The default pen colour is black.
       
   673 
       
   674 @param aColor The RGB colour for the pen. 
       
   675 @see CGraphicsContext::SetPenColor() */
       
   676 	{
       
   677 	TRgb color = aColor;
       
   678     iPimpl->StorePendingStateChange(CPimpl::EStatePenColor, &color);
       
   679 	}
       
   680 
       
   681 EXPORT_C void CWindowGc::SetPenStyle(TPenStyle aPenStyle)
       
   682 /** Sets the line drawing style for the pen. 
       
   683 
       
   684 The pen is used when drawing lines and for the outline of filled shapes. There 
       
   685 are 6 pen styles (see CGraphicsContext::TPenStyle enum). If no pen style is 
       
   686 set, the default is TPenStyle::ESolidPen.
       
   687 
       
   688 To use a pen style, its full context must be given, e.g. for a null pen: CGraphicsContext::TPenStyle::ENullPen.
       
   689 
       
   690 @param aPenStyle A pen style. 
       
   691 @see CGraphicsContext::SetPenStyle() */
       
   692 	{
       
   693 	iPimpl->StorePendingStateChange(CPimpl::EStatePenStyle, &aPenStyle);
       
   694 	}
       
   695 
       
   696 EXPORT_C void CWindowGc::SetPenSize(const TSize& aSize)
       
   697 /** Sets the line drawing size for the pen.
       
   698 
       
   699 Lines of size greater than one pixel are drawn with rounded ends that extend 
       
   700 beyond the end points, (as if the line is drawn using a circular pen tip of 
       
   701 the specified size). Rounded ends of lines drawn with a wide pen are always 
       
   702 drawn in TDrawMode::EDrawModePEN mode, overriding whatever mode has been set 
       
   703 using SetDrawMode().
       
   704 
       
   705 @param aSize A line size, the default being 1 pixel. 
       
   706 @see CGraphicsContext::SetPenSize() */
       
   707 	{
       
   708 	TSize size(aSize);
       
   709 	iPimpl->StorePendingStateChange(CPimpl::EStatePenSize, &size);
       
   710 	}
       
   711 
       
   712 EXPORT_C void CWindowGc::SetBrushColor(const TRgb &aColor)
       
   713 /** Sets the brush colour. 
       
   714 
       
   715 The effective brush colour depends on the drawing mode (see SetDrawMode()). 
       
   716 If no brush colour has been set, it defaults to white. However the default 
       
   717 brush style is null, so when drawing to a window, the default appears to be 
       
   718 the window's background colour.
       
   719 
       
   720 @param aColor The RGB colour for the brush. 
       
   721 @see CGraphicsContext::SetBrushColor() */
       
   722 	{
       
   723 	TRgb color = aColor;
       
   724     iPimpl->StorePendingStateChange(CPimpl::EStateBrushColor, &color);
       
   725 	}
       
   726 
       
   727 EXPORT_C void CWindowGc::SetBrushStyle(TBrushStyle aBrushStyle)
       
   728 /** Sets the line drawing style for the brush.
       
   729 
       
   730 The GDI provides ten brush styles, including six built-in hatching patterns 
       
   731 (see CGraphicsContext::TBrushStyle).
       
   732 
       
   733 Use TBrushStyle::ENullBrush to draw the outline of a fillable shape on its 
       
   734 own, without filling.
       
   735 
       
   736 If the TBrushStyle::EPatternedBrush style is set, but no bitmap pattern has 
       
   737 been selected using UseBrushPattern(), then the brush defaults to TBrushStyle::ENullBrush.
       
   738 
       
   739 Hatching lines are done in the current brush colour, set using SetBrushColor(). 
       
   740 Hatching can be overlaid on other graphics. The hatching pattern starts at 
       
   741 the brush origin, set using SetBrushOrigin().
       
   742 
       
   743 @param aBrushStyle The brush style. 
       
   744 @see CGraphicsContext::SetBrushStyle() */
       
   745 	{
       
   746 	iPimpl->StorePendingStateChange(CPimpl::EStateBrushStyle, &aBrushStyle);
       
   747 	}
       
   748 EXPORT_C void CWindowGc::SetBrushOrigin(const TPoint &aOrigin)
       
   749 /** Sets the brush pattern origin. 
       
   750 
       
   751 This specifies the position of the pixel in the top left corner of a reference 
       
   752 pattern tile, (in absolute device co-ordinates). Other copies of the pattern 
       
   753 tile are then drawn around the reference one. Thus the brush origin can be 
       
   754 set as the top left corner of a shape.
       
   755 
       
   756 The brush pattern may be a built-in style (see SetBrushStyle()), or a bitmap. 
       
   757 To use a bitmap, the brush must have a pattern set (see UseBrushPattern()) 
       
   758 and the brush style must be set to TBrushStyle::EPatternedBrush.
       
   759 
       
   760 Notes:
       
   761 
       
   762 If SetBrushOrigin() is not used, then the origin defaults to (0,0).
       
   763 
       
   764 This brush origin remains in effect for all fillable shapes drawn subsequently, 
       
   765 until a new brush origin is set. Shapes can thus be considered as windows 
       
   766 onto a continuous pattern field (covering the whole clipping region of a screen 
       
   767 device, or the whole device area of a printer).
       
   768 
       
   769 @param aOrigin The origin point for the brush. 
       
   770 @see CGraphicsContext::SetBrushOrigin() */
       
   771 	{
       
   772 	WritePoint(aOrigin,EWsGcOpSetBrushOrigin);
       
   773 	}
       
   774 
       
   775 EXPORT_C void CWindowGc::UseBrushPattern(const CFbsBitmap *aDevice)
       
   776 /** Sets the brush pattern to the specified bitmap. 
       
   777 
       
   778 For the brush to actually use the bitmap, TBrushStyle::EPatternedBrush must 
       
   779 be used to set the brush style (see SetBrushStyle()). When the brush pattern 
       
   780 is no longer required, use DiscardBrushPattern() to free up the memory used, 
       
   781 (if the bitmap is not being shared). If UseBrushPattern() is used again without 
       
   782 using DiscardBrushPattern() then the previous pattern is discarded automatically.
       
   783 
       
   784 Notes:
       
   785 
       
   786 When loading a bitmap, the GDI checks to see if the bitmap is already in memory. 
       
   787 If the bitmap is already there, then that copy is shared.
       
   788 
       
   789 The brush does not need to have a pattern set at all. There are several built-in 
       
   790 hatching patterns, which can be selected using SetBrushStyle().
       
   791 
       
   792 @param aDevice A bitmap pattern for the brush 
       
   793 @see CGraphicsContext::UseBrushPattern() */
       
   794 	{
       
   795 	WriteInt(aDevice->Handle(),EWsGcOpUseBrushPattern);
       
   796 	AddToBitmapArray(aDevice->Handle());
       
   797 	}
       
   798 
       
   799 EXPORT_C void CWindowGc::DiscardBrushPattern()
       
   800 /** Discards a non-built-in brush pattern. 
       
   801 
       
   802 This frees up the memory used for the bitmap, if it is not being shared by 
       
   803 another process.
       
   804 
       
   805 If no brush pattern has been set when this function is called, it has no effect.
       
   806 
       
   807 @see CGraphicsContext::DiscardBrushPattern() */
       
   808 	{
       
   809 	Write(EWsGcOpDiscardBrushPattern);
       
   810 	}
       
   811 
       
   812 EXPORT_C void CWindowGc::Plot(const TPoint &aPoint)
       
   813 /** Draws a single point. 
       
   814 
       
   815 The point is drawn with the current pen settings using the current drawing 
       
   816 mode.
       
   817 
       
   818 Note: if the pen size is greater than one pixel, a filled circle of the current 
       
   819 pen colour is drawn, with the pen size as the diameter and the plotted point 
       
   820 as the centre. If the pen size is an even number of pixels, the extra pixels 
       
   821 are drawn below and to the right of the centre. See SetPenSize().
       
   822 
       
   823 @param aPoint The point to be drawn. 
       
   824 @see CGraphicsContext::Plot() */
       
   825 	{
       
   826 	iPimpl->WriteAnyPendingStateChanges();
       
   827 	WritePoint(aPoint,EWsGcOpPlot);
       
   828 	}
       
   829 
       
   830 EXPORT_C void CWindowGc::DrawLine(const TPoint &aPoint1,const TPoint &aPoint2)
       
   831 /** Draws a straight line between two points.
       
   832 
       
   833 @param aPoint1 The point at the start of the line. 
       
   834 @param aPoint2 The point at the end of the line. 
       
   835 @see CGraphicsContext::DrawLine() */
       
   836 	{
       
   837 	iPimpl->WriteAnyPendingStateChanges();
       
   838 	TWsGcCmdDrawLine drawLine(aPoint1,aPoint2);
       
   839 	Write(&drawLine,sizeof(drawLine),EWsGcOpDrawLine);
       
   840 	}
       
   841 
       
   842 EXPORT_C void CWindowGc::MoveTo(const TPoint &aPoint)
       
   843 /** Moves the internal drawing position relative to the co-ordinate origin, without 
       
   844 drawing a line.
       
   845 
       
   846 A subsequent call to DrawLineTo() or DrawLineBy() will then use the new internal 
       
   847 drawing position as the start point for the line drawn.
       
   848 
       
   849 Notes:
       
   850 
       
   851 The operations DrawLine(), DrawLineTo(), DrawLineBy() and DrawPolyline() also 
       
   852 change the internal drawing position to the last point of the drawn line(s).
       
   853 
       
   854 The internal drawing position is set to the co-ordinate origin if no drawing 
       
   855 or moving operations have yet taken place.
       
   856 
       
   857 @param aPoint The point to move the internal drawing position to. 
       
   858 @see CGraphicsContext::MoveTo()
       
   859 @see CGraphicsContext::MoveBy() */
       
   860 	{
       
   861 	WritePoint(aPoint,EWsGcOpMoveTo);
       
   862 	}
       
   863 
       
   864 EXPORT_C void CWindowGc::MoveBy(const TPoint &aPoint)
       
   865 /** Moves the internal drawing position by a vector, without drawing a line.
       
   866 
       
   867 The internal drawing position is moved relative to its current co-ordinates.
       
   868 
       
   869 @param aPoint The vector to move the internal drawing position by. 
       
   870 @see CGraphicsContext::MoveBy()
       
   871 @see CGraphicsContext::MoveTo() */
       
   872 	{
       
   873 	WritePoint(aPoint,EWsGcOpMoveBy);
       
   874 	}
       
   875 
       
   876 EXPORT_C void CWindowGc::DrawLineTo(const TPoint &aPoint)
       
   877 /** Draws a straight line from the current internal drawing position to a point.
       
   878 
       
   879 @param aPoint The point at the end of the line. 
       
   880 @see CGraphicsContext::DrawLineTo() */
       
   881 	{
       
   882 	iPimpl->WriteAnyPendingStateChanges();
       
   883 	WritePoint(aPoint,EWsGcOpDrawTo);
       
   884 	}
       
   885 
       
   886 EXPORT_C void CWindowGc::DrawLineBy(const TPoint &aPoint)
       
   887 /** Draws a straight line relative to the current internal drawing position, using 
       
   888 a vector.
       
   889 
       
   890 The start point of the line is the current internal drawing position. The 
       
   891 vector aVector is added to the internal drawing position to give the end point 
       
   892 of the line
       
   893 
       
   894 @param aPoint The vector to add to the current internal drawing position, 
       
   895 giving the end point of the line. 
       
   896 @see CGraphicsContext::DrawLineBy() */
       
   897 	{
       
   898 	iPimpl->WriteAnyPendingStateChanges();
       
   899 	WritePoint(aPoint,EWsGcOpDrawBy);
       
   900 	}
       
   901 
       
   902 void CWindowGc::doDrawPolyLine(const CArrayFix<TPoint> *aPointArray, const TPoint* aPointList,TInt aNumPoints)
       
   903 	{
       
   904 	TWsGcOpcodes opcode=EWsGcOpDrawPolyLine;
       
   905 	TWsGcCmdDrawPolyLine polyLine;
       
   906 	TInt maxBufLen=(iBuffer->BufferSize()-sizeof(TWsCmdHeader)-sizeof(polyLine))/sizeof(TPoint);
       
   907 	TInt sent=0;
       
   908 	while(sent<aNumPoints)
       
   909 		{
       
   910 		TInt availableLen;
       
   911 		const TPoint *ptr;
       
   912 		if (aPointArray)
       
   913 			{
       
   914 			ptr=&(*aPointArray)[sent];
       
   915 			availableLen=aPointArray->End(sent)-ptr;
       
   916 			}
       
   917 		else
       
   918 			{
       
   919 			ptr=aPointList+sent;
       
   920 			availableLen=aNumPoints-sent;
       
   921 			}
       
   922 		polyLine.numPoints=Min(availableLen,maxBufLen);
       
   923 		sent+=polyLine.numPoints;
       
   924 		polyLine.more=(sent!=aNumPoints);
       
   925 		Write(&polyLine,sizeof(polyLine),ptr,polyLine.numPoints*sizeof(TPoint),opcode);
       
   926 		polyLine.last=ptr[polyLine.numPoints-1];
       
   927 		opcode=EWsGcOpDrawPolyLineContinued;
       
   928 		} 
       
   929 	}
       
   930 
       
   931 EXPORT_C void CWindowGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
       
   932 /** Draws a polyline using points in a list. 
       
   933 
       
   934 A polyline is a series of concatenated straight lines joining a set of points.
       
   935 
       
   936 @param aPointList Pointer to a list of points on the polyline. 
       
   937 @param aNumPoints The number of points in the point list. 
       
   938 @see CGraphicsContext::DrawPolyLine() */
       
   939 	{
       
   940 	iPimpl->WriteAnyPendingStateChanges();
       
   941 	doDrawPolyLine(NULL,aPointList,aNumPoints);
       
   942 	}
       
   943 
       
   944 EXPORT_C void CWindowGc::DrawPolyLine(const CArrayFix<TPoint> *aPointArray)
       
   945 /** Draws a polyline using points in an array. 
       
   946 
       
   947 A polyline is a series of concatenated straight lines joining a set of points.
       
   948 
       
   949 @param aPointArray An array containing the points on the polyline. 
       
   950 @see CGraphicsContext::DrawPolyLine() */
       
   951 	{
       
   952    	iPimpl->WriteAnyPendingStateChanges();
       
   953 	doDrawPolyLine(aPointArray,NULL,aPointArray->Count());
       
   954 	}
       
   955 
       
   956 TInt CWindowGc::doDrawPolygon(const CArrayFix<TPoint> *aPointArray,const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
       
   957 	{
       
   958 	if (aNumPoints<=0)
       
   959 		return(KErrNone);
       
   960 	TWsGcCmdSegmentedDrawPolygonData polyData;
       
   961 	polyData.index=0;
       
   962 	TInt maxBufLen=(iBuffer->BufferSize()-EPolygonMaxHeaderSize)/sizeof(TPoint);
       
   963 	FOREVER
       
   964 		{
       
   965 		const TPoint *ptr;
       
   966 		TInt availableLen;
       
   967 		if (aPointArray)
       
   968 			{
       
   969 			ptr=&(*aPointArray)[polyData.index];
       
   970 			availableLen=aPointArray->End(polyData.index)-ptr;
       
   971 			}
       
   972 		else
       
   973 			{
       
   974 			ptr=aPointList+polyData.index;
       
   975 			availableLen=aNumPoints-polyData.index;
       
   976 			}
       
   977 		polyData.numPoints=Min(availableLen,maxBufLen);
       
   978 		if (polyData.index==0)	// First time around
       
   979 			{
       
   980 			if (polyData.numPoints==aNumPoints)	// Can it be done in one go?
       
   981 				{
       
   982 				TWsGcCmdDrawPolygon drawPolygon;
       
   983 				drawPolygon.numPoints=aNumPoints;
       
   984 				drawPolygon.fillRule=aFillRule;
       
   985 				Write(&drawPolygon,sizeof(drawPolygon),ptr,aNumPoints*sizeof(TPoint),EWsGcOpDrawPolygon);
       
   986 				break;
       
   987 				}
       
   988 			TWsGcCmdStartSegmentedDrawPolygon start;
       
   989 			start.totalNumPoints=aNumPoints;
       
   990 			TInt err=WriteReply(&start,sizeof(start),EWsGcOpStartSegmentedDrawPolygon);
       
   991 			if (err!=KErrNone)
       
   992 				return(err);
       
   993 			}
       
   994 		Write(&polyData,sizeof(polyData),ptr,polyData.numPoints*sizeof(TPoint),EWsGcOpSegmentedDrawPolygonData);
       
   995 		polyData.index+=polyData.numPoints;
       
   996 		if (polyData.index==aNumPoints)
       
   997 			{
       
   998 			TWsGcCmdDrawSegmentedPolygon draw;
       
   999 			draw.fillRule=aFillRule;
       
  1000 			Write(&draw,sizeof(draw),EWsGcOpDrawSegmentedPolygon);
       
  1001 			break;
       
  1002 			}
       
  1003 		}
       
  1004 	return(KErrNone);
       
  1005 	}
       
  1006 
       
  1007 EXPORT_C TInt CWindowGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
       
  1008 /** Draws and fills a polygon using points defined in a list.
       
  1009 
       
  1010 The first TPoint in the list defines the start of the first side of the polygon. 
       
  1011 The second TPoint defines the second vertex (the end point of the first side 
       
  1012 and the start point of the second side) and so on. The final side of the polygon 
       
  1013 is drawn using the last TPoint from the array or list, and the line drawn 
       
  1014 to the start point of the first side.
       
  1015 
       
  1016 Self-crossing polygons can be filled according to one of two rules, TFillRule::EAlternate 
       
  1017 (the default), or TFillRule::EWinding. To explain the difference between these 
       
  1018 rules, the concept of a winding number needs to be introduced. The area outside 
       
  1019 any of the loops of the polygon has a winding number of zero, and is never 
       
  1020 filled. An inside a loop which is bounded by an area with winding number 0 
       
  1021 has a winding number of 1. If an area is within a loop that is bounded by 
       
  1022 an area with winding number 1, e.g. a loop within a loop, has a winding number 
       
  1023 of 2, and so on.
       
  1024 
       
  1025 The filling of a polygon proceeds according to this algorithm:
       
  1026 
       
  1027 If aFillRule is TFillRule::EAlternate (default) and it has an odd winding 
       
  1028 number, then fill the surrounding area.
       
  1029 
       
  1030 If aFillRule is TFillRule::EWinding and it has a winding number greater than 
       
  1031 zero, then fill the surrounding area.
       
  1032 
       
  1033 This function always causes a flush of the window server buffer.
       
  1034 
       
  1035 @param aPointList Pointer to a list of points, specifying the vertices of 
       
  1036 the polygon. 
       
  1037 @param aNumPoints The number of points in the vertex list 
       
  1038 @param aFillRule Either TFillRule::EAlternate (the default) or TFillRule::EWinding. 
       
  1039 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1040 codes. 
       
  1041 @see CGraphicsContext::DrawPolygon() */
       
  1042 	{
       
  1043 	iPimpl->WriteAnyPendingStateChanges();
       
  1044 	return(doDrawPolygon(NULL,aPointList,aNumPoints,aFillRule));
       
  1045 	}
       
  1046 
       
  1047 EXPORT_C TInt CWindowGc::DrawPolygon(const CArrayFix<TPoint> *aPointArray,TFillRule aFillRule)
       
  1048 /** Draws and fills a polygon using points defined in an array.
       
  1049 
       
  1050 The first TPoint in the array defines the start of the first side of the polygon. 
       
  1051 The second TPoint defines the second vertex (the end point of the first side 
       
  1052 and the start point of the second side) and so on. The final side of the polygon 
       
  1053 is drawn using the last TPoint from the array or list, and the line drawn 
       
  1054 to the start point of the first side.
       
  1055 
       
  1056 Self-crossing polygons can be filled according to one of two rules, TFillRule::EAlternate 
       
  1057 (the default), or TFillRule::EWinding. To explain the difference between these 
       
  1058 rules, the concept of a winding number needs to be introduced. The area outside 
       
  1059 any of the loops of the polygon has a winding number of zero, and is never 
       
  1060 filled. An inside a loop which is bounded by an area with winding number 0 
       
  1061 has a winding number of 1. If an area is within a loop that is bounded by 
       
  1062 an area with winding number 1, e.g. a loop within a loop, has a winding number 
       
  1063 of 2, and so on.
       
  1064 
       
  1065 The filling of a polygon proceeds according to this algorithm:
       
  1066 
       
  1067 If aFillRule is TFillRule::EAlternate (default) and it has an odd winding 
       
  1068 number, then fill the surrounding area.
       
  1069 
       
  1070 If aFillRule is TFillRule::EWinding and it has a winding number greater than 
       
  1071 zero, then fill the surrounding area.
       
  1072 
       
  1073 This function always causes a flush of the window server buffer.
       
  1074 
       
  1075 @param aPointArray An array of points, specifying the vertices of the polygon. 
       
  1076 @param aFillRule Either TFillRule::EAlternate (the default) or TFillRule::EWinding. 
       
  1077 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1078 codes. 
       
  1079 @see CGraphicsContext::DrawPolygon() */
       
  1080 	{
       
  1081 	iPimpl->WriteAnyPendingStateChanges();
       
  1082 	return(doDrawPolygon(aPointArray,NULL,aPointArray->Count(),aFillRule));
       
  1083 	}
       
  1084 
       
  1085 void CWindowGc::DrawArcOrPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd, TInt aOpcode)
       
  1086 	{
       
  1087 	iPimpl->WriteAnyPendingStateChanges();
       
  1088 	TWsGcCmdDrawArcOrPie cmd(aRect,aStart,aEnd);
       
  1089 	Write(&cmd,sizeof(cmd),aOpcode);
       
  1090 	}
       
  1091 
       
  1092 EXPORT_C void CWindowGc::DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
       
  1093 /** Draws an arc (a portion of an ellipse).
       
  1094 
       
  1095 The point aStart is used to define one end of a line from the geometric centre 
       
  1096 of the ellipse. The point of intersection between this line and the ellipse 
       
  1097 defines the start point of the arc. The point aEnd is used to define one end 
       
  1098 of a second line from the geometric centre of the ellipse. The point of intersection 
       
  1099 between this line and the ellipse defines the end point of the arc. The pixels 
       
  1100 at both the start point and the end point are drawn.
       
  1101 
       
  1102 The arc itself is the segment of the ellipse in an anti-clockwise direction 
       
  1103 from the start point to the end point.
       
  1104 
       
  1105 Notes
       
  1106 
       
  1107 A rectangle is used in the construction of the ellipse of which the arc is 
       
  1108 a segment. This rectangle is passed as an argument of type TRect.
       
  1109 
       
  1110 A wide line arc is drawn with the pixels distributed either side of a true 
       
  1111 ellipse, in such a way that the outer edge of the line would touch the edge 
       
  1112 of the construction rectangle. In other words, the ellipse used to construct 
       
  1113 it is slightly smaller than that for a single pixel line size.
       
  1114 
       
  1115 If aStart or aEnd are the ellipse centre then the line that defines the start/end 
       
  1116 of the arc defaults to one extending vertically above the centre point.
       
  1117 
       
  1118 If aStart and aEnd are the same point, or points on the same line through 
       
  1119 the ellipse centre then a complete unfilled ellipse is drawn.
       
  1120 
       
  1121 Line drawing is subject to pen colour, width and style and draw mode
       
  1122 
       
  1123 @param aRect The rectangle in which to draw the ellipse (of which the arc is 
       
  1124 a segment).
       
  1125 @param aStart A point to define the start of the arc.
       
  1126 @param aEnd A point to define the end of the arc.
       
  1127 @see CGraphicsContext::DrawArc() */
       
  1128 	{
       
  1129 	iPimpl->WriteAnyPendingStateChanges();
       
  1130 	DrawArcOrPie(aRect,aStart,aEnd,EWsGcOpDrawArc);
       
  1131 	}
       
  1132 
       
  1133 EXPORT_C void CWindowGc::DrawPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
       
  1134 /** Draws and fills a pie-shaped slice of an ellipse.
       
  1135 
       
  1136 Outlines are subject to the current pen colour, width, style and draw mode. 
       
  1137 Set the pen to ENullPen for no outline. The fill is subject to brush style 
       
  1138 (colour, hash or pattern), the origin and the current drawing mode. Set the 
       
  1139 brush to ENullBrush for no fill.
       
  1140 
       
  1141 The point aStart is used to define one end of a line to the centre of the 
       
  1142 ellipse. The point of intersection between this line and the ellipse defines 
       
  1143 the start point of the arc bounding the pie slice. The point aEnd is used 
       
  1144 to define one end of a second line to the centre of the ellipse. The point 
       
  1145 of intersection between this line and the ellipse defines the end point of 
       
  1146 the arc bounding the pie slice. The pixels at the end point are not drawn.
       
  1147 
       
  1148 The pie slice itself is the area bounded by: the arc of the ellipse in an 
       
  1149 anticlockwise direction from the start point to the end point; the straight 
       
  1150 line from the start point from the geometric centre of the ellipse; the 
       
  1151 straight line from the end point from the geometric centre of the ellipse.
       
  1152 
       
  1153 The line drawn by the pen goes inside the rectangle given by the aRect argument.
       
  1154 
       
  1155 Notes:
       
  1156 
       
  1157 A rectangle is used in the construction of the pie slice. This rectangle is 
       
  1158 passed as an argument of type TRect. The curved edge of the pie slice is an 
       
  1159 arc of an ellipse constructed within the rectangle.
       
  1160 
       
  1161 A wide line edged pie slice has the arc drawn with the pixels distributed 
       
  1162 either side of a true ellipse. This is done in such a way that the outer edge 
       
  1163 of the line would touch the edge of the construction rectangle. In other words, 
       
  1164 the ellipse used to construct it is slightly smaller than that for a single 
       
  1165 pixel line size.
       
  1166 
       
  1167 If aStart or aEnd are the ellipse centre then the line that defines the start/end 
       
  1168 of the arc defaults to one extending vertically above the centre point.
       
  1169 
       
  1170 If aStart and aEnd are the same point, or points on the same line through 
       
  1171 the ellipse centre then a complete filled ellipse is drawn. A line is also 
       
  1172 drawn from the edge to the ellipse centre.
       
  1173 
       
  1174 @param aRect A rectangle in which to draw the ellipse bounding the pie slice 
       
  1175 @param aStart A point to define the start of the pie slice 
       
  1176 @param aEnd A point to define the end of the pie slice 
       
  1177 @see CGraphicsContext::DrawPie() */
       
  1178 	{
       
  1179 	iPimpl->WriteAnyPendingStateChanges();
       
  1180 	DrawArcOrPie(aRect,aStart,aEnd,EWsGcOpDrawPie);
       
  1181 	}
       
  1182 
       
  1183 EXPORT_C void CWindowGc::DrawEllipse(const TRect &aRect)
       
  1184 /** Draws and fills an ellipse.
       
  1185 
       
  1186 The ellipse is drawn inside the rectangle defined by the aRect argument. Any 
       
  1187 TRect that has odd pixel dimensions, has the bottom right corner trimmed to 
       
  1188 give even pixel dimensions before the ellipse is constructed.
       
  1189 
       
  1190 The column and row of pixels containing the bottom right co-ordinate of the 
       
  1191 aRect argument are not part of the rectangle.
       
  1192 
       
  1193 Note: a wide outline ellipse is drawn with the pixels distributed either side of 
       
  1194 a true ellipse, in such a way that the outer edge of the line touches the 
       
  1195 edge of the construction rectangle. In other words, the ellipse used to construct 
       
  1196 it is smaller than that for a single pixel line size.
       
  1197 
       
  1198 @param aRect The rectangle in which to draw the ellipse 
       
  1199 @see CGraphicsContext::DrawEllipse() */
       
  1200 	{
       
  1201 	iPimpl->WriteAnyPendingStateChanges();
       
  1202 	WriteRect(aRect,EWsGcOpDrawEllipse);
       
  1203 	}
       
  1204 
       
  1205 EXPORT_C void CWindowGc::DrawRect(const TRect &aRect)
       
  1206 /** Draws and fills a rectangle. 
       
  1207 
       
  1208 The rectangle's border is drawn with the pen, and it is filled using the brush.
       
  1209 
       
  1210 @param aRect The rectangle to be drawn. 
       
  1211 @see CGraphicsContext::DrawRect() */
       
  1212 	{
       
  1213 	iPimpl->WriteAnyPendingStateChanges();
       
  1214 	WriteRect(aRect,EWsGcOpDrawRect);
       
  1215 	}
       
  1216 
       
  1217 EXPORT_C void CWindowGc::DrawRoundRect(const TRect &aRect,const TSize &aEllipse)
       
  1218 /** Draws and fills a rectangle with rounded corners.
       
  1219 
       
  1220 The rounded corners are each constructed as an arc of an ellipse. The dimensions 
       
  1221 of each corner (corner size and corner height) are given by aEllipse. See 
       
  1222 DrawArc() for a description of arc construction.
       
  1223 
       
  1224 The line drawn by the pen (if any) goes inside the rectangle given by the 
       
  1225 TRect argument.
       
  1226 
       
  1227 Notes:
       
  1228 
       
  1229 Dotted and dashed pen styles cannot be used for the outline of a rounded rectangle.
       
  1230 
       
  1231 If either corner size dimension is greater than half the corresponding rectangle 
       
  1232 length, the corner size dimension is reduced to half the rectangle size.
       
  1233 
       
  1234 @param aRect The rectangle to be drawn. 
       
  1235 @param aEllipse The dimensions of each corner. 
       
  1236 @see CGraphicsContext::DrawRoundRect() */
       
  1237 	{
       
  1238 	iPimpl->WriteAnyPendingStateChanges();
       
  1239 	TWsGcCmdDrawRoundRect drawRoundRect(aRect,aEllipse);
       
  1240 	Write(&drawRoundRect,sizeof(drawRoundRect),EWsGcOpDrawRoundRect);
       
  1241 	}
       
  1242 
       
  1243 EXPORT_C void CWindowGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice)
       
  1244 /** Draws a bitmap at a specified point. 
       
  1245 
       
  1246 The function does a compress/stretch based on its internally stored size in 
       
  1247 twips. Note that if the twips value of the bitmap is not set then nothing 
       
  1248 is drawn (this is the default situation).
       
  1249 
       
  1250 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1251 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1252 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1253 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1254 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1255 
       
  1256 Note: this member function uses the bitmap's size in twips and does a stretch/compress 
       
  1257 blit using a linear DDA.
       
  1258 
       
  1259 @param aTopLeft The point where the top left pixel of the bitmap is to be 
       
  1260 drawn 
       
  1261 @param aDevice The source bitmap. 
       
  1262 @see CGraphicsContext::DrawBitmap() */
       
  1263 	{
       
  1264 	iPimpl->WriteAnyPendingStateChanges();
       
  1265 	TWsGcCmdDrawBitmap drawBitmap(aTopLeft,aDevice->Handle());
       
  1266 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap);
       
  1267 	AddToBitmapArray(aDevice->Handle());
       
  1268 	}
       
  1269 
       
  1270 EXPORT_C void CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice)
       
  1271 /** Draws a bitmap in a rectangle.
       
  1272 
       
  1273 The bitmap is compressed/stretched to fit the specified rectangle. Note that 
       
  1274 if the twips value of the bitmap is not set then nothing is drawn (this is 
       
  1275 the default situation).
       
  1276 
       
  1277 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1278 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1279 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1280 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1281 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1282 
       
  1283 Notes: this member function uses the bitmap's size in pixels and does a stretch/compress 
       
  1284 blit using a linear DDA.
       
  1285 
       
  1286 @param aDestRect The rectangle within which the bitmap is to be drawn. 
       
  1287 @param aDevice The source bitmap. 
       
  1288 @see CGraphicsContext::DrawBitmap() */
       
  1289 	{
       
  1290 	iPimpl->WriteAnyPendingStateChanges();
       
  1291 	TWsGcCmdDrawBitmap2 drawBitmap(aDestRect,aDevice->Handle());
       
  1292 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap2);
       
  1293 	AddToBitmapArray(aDevice->Handle());
       
  1294 	}
       
  1295 
       
  1296 EXPORT_C void CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect)
       
  1297 /** Draws a specified rectangle from a bitmap into another rectangle.
       
  1298 
       
  1299 The function compresses/stretches the specified rectangle from the bitmap 
       
  1300 to fit the destination rectangle. Note that if the twips value of the bitmap 
       
  1301 is not set then nothing is drawn (this is the default situation).
       
  1302 
       
  1303 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1304 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1305 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1306 stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
       
  1307 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1308 
       
  1309 Note: this member function uses rectangle sizes in pixels and does a stretch/compress 
       
  1310 blit using a linear DDA.
       
  1311 
       
  1312 @param aDestRect The rectangle within which the bitmap is to be drawn. 
       
  1313 @param aDevice A source bitmap. 
       
  1314 @param aSourceRect The rectangle in the source bitmap that is copied to the 
       
  1315 destination rectangle. 
       
  1316 @see CGraphicsContext::DrawBitmap() */
       
  1317 	{
       
  1318 	iPimpl->WriteAnyPendingStateChanges();
       
  1319 	TWsGcCmdDrawBitmap3 drawBitmap(aDestRect,aDevice->Handle(),aSourceRect);
       
  1320 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap3);
       
  1321 	AddToBitmapArray(aDevice->Handle());
       
  1322 	}
       
  1323 
       
  1324 /** Draws a specified rectangle from a bitmap and its mask into another rectangle.
       
  1325 
       
  1326 The function compresses/stretches the specified rectangle from the bitmap 
       
  1327 to fit the destination rectangle. 
       
  1328 The mask bitmap can be used as either a positive or negative mask. Masked 
       
  1329 pixels are not mapped to the destination rectangle.
       
  1330 
       
  1331 A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black 
       
  1332 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1333 being transferred to the destination rectangle. With aInvertMask=ETrue, white 
       
  1334 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1335 being transferred to the destination rectangle.
       
  1336 
       
  1337 If mask bitmap's display mode is EColor256, the function does AplhaBlending
       
  1338 and ignores aInvertMask parameter.
       
  1339 
       
  1340 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1341 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1342 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1343 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1344 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1345 
       
  1346 Note: this member function uses rectangle sizes in pixels and does a stretch/compress 
       
  1347 blit using a linear DDA.
       
  1348 
       
  1349 @param aDestRect The rectangle within which the masked bitmap is to be drawn. 
       
  1350 @param aBitmap A source bitmap. 
       
  1351 @param aSourceRect The rectangle in the source bitmap that is copied to the 
       
  1352 destination rectangle.
       
  1353 @param aMaskBitmap A mask bitmap. 
       
  1354 @param aInvertMask If false, a source pixel that is masked by a black pixel 
       
  1355 is not transferred to the destination rectangle. If true, then a source pixel 
       
  1356 that is masked by a white pixel is not transferred to the destination rectangle. */
       
  1357 EXPORT_C void CWindowGc::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask)
       
  1358 	{
       
  1359 	iPimpl->WriteAnyPendingStateChanges();
       
  1360 	TWsGcCmdDrawBitmapMasked drawBitmap(aDestRect,aBitmap->Handle(),aSourceRect,aMaskBitmap->Handle(),aInvertMask);
       
  1361 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmapMasked);
       
  1362 	AddToBitmapArray(aBitmap->Handle());
       
  1363 	AddToBitmapArray(aMaskBitmap->Handle());
       
  1364 	}
       
  1365 
       
  1366 EXPORT_C void CWindowGc::DrawBitmapMasked(const TRect& aDestRect, const CWsBitmap* aBitmap, const TRect& aSourceRect, const CWsBitmap* aMaskBitmap, TBool aInvertMask)
       
  1367 /** Draws a specified rectangle from a wserv bitmap and its mask into 
       
  1368 another rectangle.
       
  1369 
       
  1370 The function compresses/stretches the specified rectangle from the bitmap 
       
  1371 to fit the destination rectangle. 
       
  1372 The mask bitmap can be used as either a positive or negative mask. Masked 
       
  1373 pixels are not mapped to the destination rectangle.
       
  1374 
       
  1375 A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black 
       
  1376 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1377 being transferred to the destination rectangle. With aInvertMask=ETrue, white 
       
  1378 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1379 being transferred to the destination rectangle.
       
  1380 
       
  1381 If mask bitmap's display mode is EColor256, the function does AplhaBlending
       
  1382 and ignores aInvertMask parameter.
       
  1383 
       
  1384 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1385 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1386 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1387 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1388 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1389 
       
  1390 Note: this member function uses rectangle sizes in pixels and does a stretch/compress 
       
  1391 blit using a linear DDA.
       
  1392 
       
  1393 @param aDestRect The rectangle within which the masked bitmap is to be drawn. 
       
  1394 @param aBitmap A source wserv bitmap. 
       
  1395 @param aSourceRect The rectangle in the source bitmap that is copied to the 
       
  1396 destination rectangle.
       
  1397 @param aMaskBitmap A mask wserv bitmap. 
       
  1398 @param aInvertMask If false, a source pixel that is masked by a black pixel 
       
  1399 is not transferred to the destination rectangle. If true, then a source pixel 
       
  1400 that is masked by a white pixel is not transferred to the destination rectangle. */
       
  1401 	{
       
  1402 	iPimpl->WriteAnyPendingStateChanges();
       
  1403 	TWsGcCmdDrawBitmapMasked drawBitmap(aDestRect,aBitmap->WsHandle(),aSourceRect,aMaskBitmap->WsHandle(),aInvertMask);
       
  1404 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpWsDrawBitmapMasked);
       
  1405 	AddToBitmapArray(aBitmap->Handle());
       
  1406 	AddToBitmapArray(aMaskBitmap->Handle());
       
  1407 	}
       
  1408 EXPORT_C void CWindowGc::DrawText(const TDesC &aBuf, const TPoint &aPos)
       
  1409 /** Draws horizontal text with no surrounding box. 
       
  1410 
       
  1411 The appearance of the text is subject to the drawing mode, the font, pen colour, 
       
  1412 word justification and character justification. 
       
  1413 
       
  1414 A panic occurs if this function is called when there is no font: see UseFont().
       
  1415 
       
  1416 @param aBuf The string to write. 
       
  1417 @param aPos The point specifying the position of the baseline at the left 
       
  1418 end of the text.
       
  1419 @see CGraphicsContext::DrawText() */
       
  1420 	{
       
  1421 	iPimpl->WriteAnyPendingStateChanges();
       
  1422 	TWsGcCmdDrawText printText(aPos,aBuf.Length());
       
  1423 	WriteTextCommand(&printText,sizeof(printText),aBuf,EWsGcOpDrawText,EWsGcOpDrawTextPtr);
       
  1424 	}
       
  1425 
       
  1426 EXPORT_C void CWindowGc::DrawText(const TDesC &aBuf,const TRect &aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
       
  1427 /** Draws horizontal text within a cleared box.
       
  1428 
       
  1429 The appearance of the text is subject to the drawing mode, the font, pen colour, 
       
  1430 word justification and character justification. It is also subject to the 
       
  1431 background brush (set brush to ENullBrush for no effect on background).
       
  1432 
       
  1433 A panic occurs if this function is called when there is no font: see UseFont().
       
  1434 
       
  1435 Note: the text is clipped to the box. You must ensure that the specified string 
       
  1436 is not too large.
       
  1437 
       
  1438 @param aBuf The text to write.
       
  1439 @param aBox The box to draw the text in. 
       
  1440 @param aBaselineOffset An offset from the top of the box to the text baseline. 
       
  1441 Note that the baseline is the line on which letters sit, for instance below r, s, t, and 
       
  1442 above the tail of q, and y. 
       
  1443 @param aHoriz The text alignment mode (default is left, rather than centre 
       
  1444 or right). 
       
  1445 @param aLeftMrg The left margin for left-aligned text, or the right margin 
       
  1446 for right-aligned text (default is zero). 
       
  1447 @see CGraphicsContext::DrawText() */
       
  1448 	{
       
  1449 	iPimpl->WriteAnyPendingStateChanges();
       
  1450 	if (aBuf.Size()<(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)-sizeof(TWsGcCmdBoxTextOptimised2))) 
       
  1451 		{
       
  1452 		if (aHoriz==ELeft && aLeftMrg==0)
       
  1453 			{
       
  1454 			TWsGcCmdBoxTextOptimised1 boxTextOpt1(aBox,aBaselineOffset,aBuf.Length());
       
  1455 			Write(&boxTextOpt1,sizeof(boxTextOpt1),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextOptimised1);
       
  1456 			}
       
  1457 		else
       
  1458 			{
       
  1459 			TWsGcCmdBoxTextOptimised2 boxTextOpt2(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length());
       
  1460 			Write(&boxTextOpt2,sizeof(boxTextOpt2),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextOptimised2);
       
  1461 			}
       
  1462 		}
       
  1463 	else
       
  1464 		{
       
  1465 		TWsGcCmdBoxText boxText(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length(),iPimpl->iFont->TextWidthInPixels(aBuf));
       
  1466 		WriteTextCommand(&boxText,sizeof(boxText),aBuf,EWsGcOpDrawBoxText,EWsGcOpDrawBoxTextPtr);
       
  1467 		}
       
  1468 	}
       
  1469 
       
  1470 TInt CWindowGc::APIExDrawText(const TDesC& aBuf,const TTextParameters* aParam,const TPoint& aPos)
       
  1471 	{
       
  1472 	iPimpl->WriteAnyPendingStateChanges();
       
  1473 	TWsGcCmdDrawTextInContext printTextInContext(aPos,aBuf.Length(),aParam->iStart,aParam->iEnd);
       
  1474 	WriteTextCommand(&printTextInContext,sizeof(printTextInContext),aBuf,EWsGcOpDrawTextInContext,EWsGcOpDrawTextInContextPtr);
       
  1475 	return KErrNone;
       
  1476 	}
       
  1477 	
       
  1478 TInt CWindowGc::APIExDrawText(const TDesC& aBuf,const TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
       
  1479 	{
       
  1480 	iPimpl->WriteAnyPendingStateChanges();
       
  1481 	if (aBuf.Size()<(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)-sizeof(TWsGcCmdBoxTextInContextOptimised2))) 
       
  1482 		{
       
  1483 		if (aHoriz==ELeft && aLeftMrg==0)
       
  1484 			{
       
  1485 			TWsGcCmdBoxTextInContextOptimised1 boxTextOpt1(aBox,aBaselineOffset,aBuf.Length(),aParam->iStart,aParam->iEnd);
       
  1486 			Write(&boxTextOpt1,sizeof(boxTextOpt1),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextInContextOptimised1);
       
  1487 			}
       
  1488 		else
       
  1489 			{
       
  1490 			TWsGcCmdBoxTextInContextOptimised2 boxTextOpt2(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length(),aParam->iStart,aParam->iEnd);
       
  1491 			Write(&boxTextOpt2,sizeof(boxTextOpt2),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextInContextOptimised2);
       
  1492 			}
       
  1493 		}
       
  1494 	else
       
  1495 		{
       
  1496 		TWsGcCmdBoxTextInContext boxText(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length(),iPimpl->iFont->TextWidthInPixels(aBuf),aParam->iStart,aParam->iEnd);
       
  1497 		WriteTextCommand(&boxText,sizeof(boxText),aBuf,EWsGcOpDrawBoxTextInContext,EWsGcOpDrawBoxTextInContextPtr);
       
  1498 		}
       
  1499 	return KErrNone;
       
  1500 	}
       
  1501 EXPORT_C void CWindowGc::DrawTextVertical(const TDesC& aText,const TPoint& aPos,TBool aUp)
       
  1502 /** Draws vertical text in the specified direction.
       
  1503 
       
  1504 A panic occurs if this function is called when there is no font: see UseFont().
       
  1505 
       
  1506 @param aText The text to be drawn. 
       
  1507 @param aPos Point of origin of the text baseline. 
       
  1508 @param aUp Direction. ETrue for up, EFalse for down. */
       
  1509 	{
       
  1510 	iPimpl->WriteAnyPendingStateChanges();
       
  1511 	TWsGcCmdDrawTextVertical printText(aPos,aText.Length(),aUp);
       
  1512 	WriteTextCommand(&printText,sizeof(printText),aText,EWsGcOpDrawTextVertical,EWsGcOpDrawTextVerticalPtr);
       
  1513 	}
       
  1514 
       
  1515 EXPORT_C void CWindowGc::DrawTextVertical(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
       
  1516 /** Draws text vertically in the specified direction, within a box of the specified 
       
  1517 size.
       
  1518 
       
  1519 A panic occurs if this function is called when there is no font: see UseFont().
       
  1520 
       
  1521 @param aText The text to be drawn. 
       
  1522 @param aBox The bounding box within which the text should be drawn, and which 
       
  1523 it is clipped to.
       
  1524 @param aBaselineOffset The height of the top of the characters from their text 
       
  1525 baseline. 
       
  1526 @param aUp The direction. ETrue for up, EFalse for down.
       
  1527 @param aVert The text alignment. 
       
  1528 @param aMargin The margin. */
       
  1529 	{
       
  1530 	iPimpl->WriteAnyPendingStateChanges();
       
  1531 	TWsGcCmdBoxTextVertical boxText(aBox);
       
  1532 	boxText.baselineOffset=aBaselineOffset;
       
  1533 	boxText.up=aUp;
       
  1534 	boxText.vert=aVert;
       
  1535 	boxText.margin=aMargin;
       
  1536 	boxText.length=aText.Length();
       
  1537 	boxText.width=iPimpl->iFont->TextWidthInPixels(aText);
       
  1538 	WriteTextCommand(&boxText,sizeof(boxText),aText,EWsGcOpDrawBoxTextVertical,EWsGcOpDrawBoxTextVerticalPtr);
       
  1539 	}
       
  1540 
       
  1541 TInt CWindowGc::APIExDrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPos,TBool aUp)
       
  1542 	{
       
  1543 	iPimpl->WriteAnyPendingStateChanges();
       
  1544 	TWsGcCmdDrawTextInContextVertical printText(aPos,aText.Length(),aUp,aParam->iStart,aParam->iEnd);
       
  1545 	WriteTextCommand(&printText,sizeof(printText),aText,EWsGcOpDrawTextInContextVertical,EWsGcOpDrawTextInContextVerticalPtr);
       
  1546 	return KErrNone;
       
  1547 	}
       
  1548 
       
  1549 TInt CWindowGc::APIExDrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
       
  1550 	{
       
  1551 	iPimpl->WriteAnyPendingStateChanges();
       
  1552 	TWsGcCmdBoxTextInContextVertical boxText(aBox);
       
  1553 	boxText.baselineOffset=aBaselineOffset;
       
  1554 	boxText.up=aUp;
       
  1555 	boxText.vert=aVert;
       
  1556 	boxText.margin=aMargin;
       
  1557 	boxText.length=aText.Length();
       
  1558 	boxText.width=iPimpl->iFont->TextWidthInPixels(aText);
       
  1559 	boxText.start = aParam->iStart;
       
  1560 	boxText.end = aParam->iEnd;
       
  1561 	WriteTextCommand(&boxText,sizeof(boxText),aText,EWsGcOpDrawBoxTextInContextVertical,EWsGcOpDrawBoxTextInContextVerticalPtr);
       
  1562 	return KErrNone;
       
  1563 	}
       
  1564 
       
  1565 //========================Extra functions============================
       
  1566 
       
  1567 EXPORT_C void CWindowGc::CopyRect(const TPoint &anOffset,const TRect &aRect)
       
  1568 /** Copies a rectangle from any part of the screen into the window that the gc 
       
  1569 is active on.
       
  1570 
       
  1571 The copy part of the operation applies to the whole rectangle, irrespective 
       
  1572 of whether or not it within the window, however the "paste" is clipped to 
       
  1573 the drawing area.
       
  1574 
       
  1575 The rectangle is specified in window coordinates (if the top-left of the rectangle 
       
  1576 is (0,0) then the area of the screen it specifies has its top-left at the 
       
  1577 top left corner of the window, if it is (-10,-10) then it starts 10 pixels 
       
  1578 above and to the left of the window). 
       
  1579 
       
  1580 Note: shadows in the source rectangle will be copied. None of the area drawn to 
       
  1581 will gain shadowing (even if the window is already in shadow).
       
  1582 
       
  1583 This version of this function is only really suitable for testing.
       
  1584 
       
  1585 @param anOffset The offset from the original position to the point where the 
       
  1586 rectangle is copied. 
       
  1587 @param aRect The rectangular area to be copied. This is in window co-ordinates, 
       
  1588 e.g. the top left corner of the window is position (0,0) with respect to the 
       
  1589 rectangle.
       
  1590 @see CBitmapContext::CopyRect() */
       
  1591 	{
       
  1592 	iPimpl->WriteAnyPendingStateChanges();
       
  1593 	TWsGcCmdCopyRect copyRect(anOffset,aRect);
       
  1594 	Write(&copyRect,sizeof(copyRect),EWsGcOpCopyRect);
       
  1595 	}
       
  1596 
       
  1597 EXPORT_C void CWindowGc::BitBlt(const TPoint &aPoint, const CFbsBitmap *aBitmap)
       
  1598 /** Performs a bitmap block transfer.
       
  1599 
       
  1600 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1601 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1602 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1603 stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
       
  1604 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1605 
       
  1606 @param aPoint The position for the top left corner of the bitmap. 
       
  1607 @param aBitmap A memory-resident bitmap. 
       
  1608 @see CBitmapContext::BitBlt() */
       
  1609 	{
       
  1610 	if (aBitmap == NULL || !aBitmap->Handle())
       
  1611 		return; 
       
  1612 	iPimpl->WriteAnyPendingStateChanges();
       
  1613 	TWsGcCmdGdiBlt2 gdiBlit(aPoint,aBitmap->Handle());
       
  1614 	Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiBlt2);
       
  1615 	AddToBitmapArray(aBitmap->Handle());
       
  1616 	}
       
  1617 
       
  1618 EXPORT_C void CWindowGc::BitBlt(const TPoint &aDestination,const CFbsBitmap *aBitmap,const TRect &aSource)
       
  1619 /** Performs a bitmap block transfer of a rectangular piece of a bitmap.
       
  1620 
       
  1621 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1622 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1623 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1624 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1625 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1626 
       
  1627 Note: if the rectangle aSource is larger than the bitmap then the bitmap will be padded 
       
  1628 with white.
       
  1629 
       
  1630 @param aDestination The position for the top left corner of the bitmap. 
       
  1631 @param aBitmap A memory-resident bitmap 
       
  1632 @param aSource A rectangle defining the piece of the bitmap to be drawn, with 
       
  1633 co-ordinates relative to the top left corner of the bitmap 
       
  1634 @see CBitmapContext::BitBlt() */
       
  1635 	{
       
  1636 	if (aBitmap == NULL || !aBitmap->Handle())
       
  1637 		return; 
       
  1638 	iPimpl->WriteAnyPendingStateChanges();
       
  1639 	TWsGcCmdGdiBlt3 gdiBlit(aDestination,aBitmap->Handle(),aSource);
       
  1640 	Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiBlt3);
       
  1641 	AddToBitmapArray(aBitmap->Handle());
       
  1642 	}
       
  1643 
       
  1644 EXPORT_C void CWindowGc::BitBltMasked(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask)
       
  1645 /** Performs a masked bitmap block transfer of a memory resident source bitmap.
       
  1646 
       
  1647 The mask bitmap can be used as either a positive or negative mask. Masked 
       
  1648 pixels are not mapped to the destination rectangle.
       
  1649 
       
  1650 A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black 
       
  1651 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1652 being transferred to the destination rectangle. With aInvertMask=ETrue, white 
       
  1653 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1654 being transferred to the destination rectangle.
       
  1655 
       
  1656 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1657 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1658 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1659 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1660 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1661 
       
  1662 @param aPoint A position for the top left corner of the bitmap. 
       
  1663 @param aBitmap A memory-resident source bitmap. 
       
  1664 @param aSourceRect A rectangle defining the piece of the bitmap to be drawn, 
       
  1665 with co-ordinates relative to the top left corner of the bitmap 
       
  1666 @param aMaskBitmap A mask bitmap. 
       
  1667 @param aInvertMask If false, a source pixel that is masked by a black pixel 
       
  1668 is not transferred to the destination rectangle. If true, then a source pixel 
       
  1669 that is masked by a white pixel is not transferred to the destination rectangle. 
       
  1670 
       
  1671 @see CBitmapContext::BitBltMasked() */
       
  1672 	{
       
  1673 	if (aBitmap == NULL || !aBitmap->Handle() || aMaskBitmap == NULL || !aMaskBitmap->Handle())
       
  1674 		return; 
       
  1675 	iPimpl->WriteAnyPendingStateChanges();
       
  1676 	TWsGcCmdBltMasked gdiBlitMasked(aPoint,aBitmap->Handle(),aSourceRect,aMaskBitmap->Handle(),aInvertMask);
       
  1677 	Write(&gdiBlitMasked,sizeof(gdiBlitMasked),EWsGcOpGdiBltMasked);
       
  1678 	AddToBitmapArray(aBitmap->Handle());
       
  1679 	AddToBitmapArray(aMaskBitmap->Handle());
       
  1680 	}
       
  1681 
       
  1682 EXPORT_C void CWindowGc::BitBlt(const TPoint &aPoint, const CWsBitmap *aBitmap)
       
  1683 /** Performs a bitmap block transfer on a bitmap to which the window server already 
       
  1684 has a handle.
       
  1685 
       
  1686 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1687 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1688 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1689 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1690 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1691 
       
  1692 This function should be used in preference to the CFbsBitmap overload if the 
       
  1693 bitmap is to be used more than once, as it is a lot quicker.
       
  1694 
       
  1695 @param aPoint The position for the top left corner of the bitmap. 
       
  1696 @param aBitmap A window server bitmap. 
       
  1697 @see CBitmapContext::BitBlt() */
       
  1698 	{
       
  1699 	if (aBitmap == NULL || !aBitmap->Handle())
       
  1700 		return; 
       
  1701 	iPimpl->WriteAnyPendingStateChanges();
       
  1702 	TWsGcCmdGdiBlt2 gdiBlit(aPoint,aBitmap->WsHandle());
       
  1703 	Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiWsBlt2);
       
  1704 	AddToBitmapArray(aBitmap->Handle());
       
  1705 	}
       
  1706 
       
  1707 EXPORT_C void CWindowGc::BitBlt(const TPoint &aDestination,const CWsBitmap  *aBitmap,const TRect &aSource)
       
  1708 /** Performs a bitmap block transfer of a rectangular piece of a bitmap to which 
       
  1709 the window server already has a handle.
       
  1710 
       
  1711 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1712 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1713 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1714 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1715 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1716 
       
  1717 This function should be used in preference to the CFbsBitmap overload if the 
       
  1718 bitmap is to be used more than once, as it is a lot quicker.
       
  1719 
       
  1720 Note: if the rectangle aSource is larger than the bitmap then the bitmap will be padded 
       
  1721 with white.
       
  1722 	
       
  1723 @param aDestination The position for the top left corner of the bitmap. 
       
  1724 @param aBitmap A window server bitmap. 
       
  1725 @param aSource A rectangle defining the piece of the bitmap to be drawn, with 
       
  1726 co-ordinates relative to the top left corner of the bitmap 
       
  1727 @see CBitmapContext::BitBlt() */
       
  1728 	{
       
  1729 	if (aBitmap == NULL || !aBitmap->Handle())
       
  1730 		return; 
       
  1731 	iPimpl->WriteAnyPendingStateChanges();
       
  1732 	TWsGcCmdGdiBlt3 gdiBlit(aDestination,aBitmap->WsHandle(),aSource);
       
  1733 	Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiWsBlt3);
       
  1734 	AddToBitmapArray(aBitmap->Handle());
       
  1735 	}
       
  1736 
       
  1737 EXPORT_C void CWindowGc::BitBltMasked(const TPoint& aPoint,const CWsBitmap * aBitmap,const TRect& aSourceRect,const CWsBitmap * aMaskBitmap,TBool aInvertMask)
       
  1738 /** Performs a masked bitmap block transfer of a window server bitmap.
       
  1739 
       
  1740 The mask bitmap can be used as either a positive or negative mask. Masked 
       
  1741 pixels are not mapped to the destination rectangle.
       
  1742 
       
  1743 A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black 
       
  1744 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1745 being transferred to the destination rectangle. With aInvertMask=ETrue, white 
       
  1746 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1747 being transferred to the destination rectangle.
       
  1748 
       
  1749 This function should be used in preference to the CFbsBitmap overload if the 
       
  1750 bitmap is to be used more than once, as it is a lot quicker.
       
  1751 
       
  1752 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1753 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1754 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1755 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1756 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1757 
       
  1758 @param aPoint A position for the top left corner of the bitmap. 
       
  1759 @param aBitmap A window server bitmap. 
       
  1760 @param aSourceRect A rectangle defining the piece of the bitmap to be drawn, 
       
  1761 with co-ordinates relative to the top left corner of the bitmap. 
       
  1762 @param aMaskBitmap A window server mask bitmap. 
       
  1763 @param aInvertMask If false, a source pixel that is masked by a black pixel 
       
  1764 is not transferred to the destination rectangle. If true, then a source pixel 
       
  1765 that is masked by a white pixel is not transferred to the destination rectangle. 
       
  1766 
       
  1767 @see CBitmapContext::BitBltMasked() */
       
  1768 	{
       
  1769 	if (aBitmap == NULL || !aBitmap->Handle() || aMaskBitmap == NULL || !aMaskBitmap->Handle())
       
  1770 		return;
       
  1771 	iPimpl->WriteAnyPendingStateChanges();
       
  1772 	TWsGcCmdBltMasked gdiBlitMasked(aPoint,aBitmap->WsHandle(),aSourceRect,aMaskBitmap->WsHandle(),aInvertMask);
       
  1773 	Write(&gdiBlitMasked,sizeof(gdiBlitMasked),EWsGcOpGdiWsBltMasked);
       
  1774 	AddToBitmapArray(aBitmap->Handle());
       
  1775 	AddToBitmapArray(aMaskBitmap->Handle()); 
       
  1776 	}
       
  1777 
       
  1778 /**
       
  1779 This method has been deprecated. It is no longer possible to re-map pixel colours
       
  1780 within a rectangle. Calling it has no effect.
       
  1781 @param aRect Ignored.
       
  1782 @param aColors Ignored.
       
  1783 @param aNumPairs Ignored.
       
  1784 @param aMapForwards Ignored.
       
  1785 @deprecated
       
  1786 */
       
  1787 EXPORT_C void CWindowGc::MapColors(const TRect& /*aRect*/, const TRgb* /*aColors*/, TInt /*aNumPairs*/, TBool /*aMapForwards*/)
       
  1788 	{
       
  1789 	}
       
  1790 
       
  1791 EXPORT_C void CWindowGc::Clear(const TRect &aRect)
       
  1792 /** Clears a rectangular area of a window.
       
  1793 
       
  1794 The cleared area is filled with the current brush colour.
       
  1795 
       
  1796 @param aRect The rectangle to clear. 
       
  1797 @see CBitmapContext::Clear() */
       
  1798 	{
       
  1799 	iPimpl->WriteAnyPendingStateChanges();
       
  1800 	WriteRect(aRect,EWsGcOpClearRect);
       
  1801 	}
       
  1802 
       
  1803 EXPORT_C void CWindowGc::Clear()
       
  1804 /** Clears the whole window.
       
  1805 
       
  1806 The cleared area is filled with the current brush colour.
       
  1807 
       
  1808 @see CBitmapContext::Clear() */
       
  1809 	{
       
  1810 	iPimpl->WriteAnyPendingStateChanges();
       
  1811 	Write(EWsGcOpClear);
       
  1812 	}
       
  1813 
       
  1814 EXPORT_C void CWindowGc::Reset()
       
  1815 /** Resets the graphics context to its default settings.
       
  1816 
       
  1817 The drawing mode is set to TDrawMode::EDrawModePen (pen and brush colours used as 
       
  1818 they are); there is no clipping rectangle; the pen settings are black, 
       
  1819 solid, single pixel size; the brush style is null; no text font is selected.
       
  1820 
       
  1821 @see CGraphicsContext::Reset() */
       
  1822 	{
       
  1823 	Write(EWsGcOpReset);
       
  1824 	iPimpl->iFont=NULL;
       
  1825 	iPimpl->iShadowColor = KDefaultShadowColor;
       
  1826     iPimpl->ResetPendingState();
       
  1827     iPimpl->iForceWrite = ETrue; // needed because brush colour set to window background colour in CPlaybackGc::CommandL and CWsGc::SetGcAttribute
       
  1828 	}
       
  1829 
       
  1830 /**
       
  1831 This method has been deprecated. Dithering is no longer supported. Calling it
       
  1832 has no effect.
       
  1833 @param aPoint Ignored.
       
  1834 @deprecated
       
  1835 */
       
  1836 EXPORT_C void CWindowGc::SetDitherOrigin(const TPoint& /*aPoint*/)
       
  1837 	{
       
  1838 	}
       
  1839 
       
  1840 EXPORT_C void CWindowGc::SetFaded(TBool aFaded)
       
  1841 /** Sets whether the graphics context is faded.
       
  1842 
       
  1843 Fading is used to make a window appear less colourful so that other windows 
       
  1844 stand out. For example, a window would be faded when a dialogue is displayed 
       
  1845 in front of it.
       
  1846 
       
  1847 @param aFaded ETrue to fade the graphics context, EFalse to unfade it. */
       
  1848 	{
       
  1849 	iPimpl->WriteAnyPendingStateChanges();
       
  1850 	WriteInt(aFaded,EWsGcOpSetFaded);
       
  1851 	}
       
  1852 
       
  1853 EXPORT_C void CWindowGc::SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap)
       
  1854 /** Sets the fading parameters.
       
  1855 
       
  1856 This function allows you to override the map used when drawing with a faded 
       
  1857 graphics context. However if you draw to a faded window with a faded graphics 
       
  1858 context, then fading on the graphics context is ignored and it will use the 
       
  1859 fading of the window.
       
  1860 
       
  1861 Fading is used to make a window appear less colourful so that other windows stand 
       
  1862 out. For example, a window would be faded when a dialogue is displayed 
       
  1863 in front of it. 
       
  1864 
       
  1865 You can either make a faded window closer to white or closer to black. 
       
  1866 The fading map allows you to over-ride the default fading parameters set in 
       
  1867 RWsSession::SetDefaultFadingParameters(). 
       
  1868 
       
  1869 Fading re-maps colours to fall between the specified black and white map values. 
       
  1870 If aBlackMap=0 and aWhiteMap=255 then the colours are mapped unchanged. As the 
       
  1871 values converge, the colours are mapped to a smaller range, so the differences 
       
  1872 between colours in the faded graphics context decrease. If the values are reversed 
       
  1873 then the colours are inverted (i.e. where the gc would be black, it is now white). 
       
  1874 
       
  1875 @param aBlackMap Black map fading parameter. Unfaded this is 0. 
       
  1876 @param aWhiteMap White map fading parameter. Unfaded this is 255. 
       
  1877 @see RWsSession::SetDefaultFadingParameters()
       
  1878 @see RWindowTreeNode::SetFaded() */
       
  1879 	{
       
  1880 	WriteInt(WservEncoding::Encode8BitValues(aBlackMap,aWhiteMap),EWsGcOpSetFadeParams);
       
  1881 	}
       
  1882 
       
  1883 EXPORT_C TInt CWindowGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect,const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
       
  1884 /**
       
  1885 Performs an alpha blending of the source data, aSrcBmp, with the window, using
       
  1886 the data from aAlphaBmp as an alpha blending factor.
       
  1887 The formula used is:
       
  1888 (S * A + W * (255 - A)) / 255, where:
       
  1889 - S - a pixel from aSrcBmp;
       
  1890 - W - a pixel from the window;
       
  1891 - A - a pixel from aAlphaBmp;
       
  1892 The contents of source and alpha bitmap are preserved.
       
  1893 The calculated alpha blended pixels are written to the destination - the window image.
       
  1894 
       
  1895 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1896 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1897 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1898 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1899 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1900 
       
  1901 This method is supported from version 8.1
       
  1902 @param aDestPt Position in the target the result should be drawn to.
       
  1903 @param aSrcBmp A pointer to the source bitmap.
       
  1904 @param aSrcRect The part of the source bitmap that should be used.
       
  1905 @param aAlphaBmp A pointer to the bitmap used as an alpha blending factor.
       
  1906 @param aAlphaPt Position of the first pixel in the alpha bitmap that should be used as a source 
       
  1907                 for the alpha blending. The size of the area is the same as the 
       
  1908                 source bitmap area - aSrcRect parameter.
       
  1909 @see CFbsBitGc::AlphaBlendBitmaps()
       
  1910 */
       
  1911 	{
       
  1912    	iPimpl->WriteAnyPendingStateChanges();
       
  1913 	TWsGcCmdAlphaBlendBitmaps alphaBlend(aDestPt, aSrcBmp->Handle(), aSrcRect, aAlphaBmp->Handle(), aAlphaPt);
       
  1914 	Write(&alphaBlend,sizeof(alphaBlend),EWsGcOpGdiAlphaBlendBitmaps);
       
  1915 	AddToBitmapArray(aSrcBmp->Handle());
       
  1916 	AddToBitmapArray(aAlphaBmp->Handle());
       
  1917 	return KErrNone;
       
  1918 	}
       
  1919 
       
  1920 EXPORT_C TInt CWindowGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CWsBitmap* aSrcBmp, const TRect& aSrcRect,const CWsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
       
  1921 /**
       
  1922 The method performs an alpha blending of the source data, aSrcBmp, with the window, using
       
  1923 the data from aAlphaBmp as an alpha blending factor.
       
  1924 For information on how this function works, see the other overload.
       
  1925 
       
  1926 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1927 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1928 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1929 stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
       
  1930 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1931 
       
  1932 This method is supported from version 8.1
       
  1933 @param aDestPt Position in the target the result should be drawn to.
       
  1934 @param aSrcBmp A pointer to the source bitmap.
       
  1935 @param aSrcRect The part of the source bitmap that should be used.
       
  1936 @param aAlphaBmp A pointer to the bitmap used as an alpha blending factor.
       
  1937 @param aAlphaPt Position of the first pixel in the alpha bitmap that should be used as a source 
       
  1938                 for the alpha blending. The size of the area is the same as the 
       
  1939                 source bitmap area - aSrcRect parameter.
       
  1940 @see CFbsBitGc::AlphaBlendBitmaps()
       
  1941 */
       
  1942 	{
       
  1943 	iPimpl->WriteAnyPendingStateChanges();
       
  1944 	TWsGcCmdAlphaBlendBitmaps alphaBlend(aDestPt, aSrcBmp->WsHandle(), aSrcRect, aAlphaBmp->WsHandle(), aAlphaPt);
       
  1945 	Write(&alphaBlend,sizeof(alphaBlend),EWsGcOpGdiWsAlphaBlendBitmaps);
       
  1946 	AddToBitmapArray(aSrcBmp->Handle());
       
  1947 	AddToBitmapArray(aAlphaBmp->Handle());
       
  1948 	return KErrNone;
       
  1949 	}
       
  1950 
       
  1951 /**
       
  1952 This method has been deprecated. Calling it has no effect.
       
  1953 @param aDrawOpaque Ignored.
       
  1954 @deprecated
       
  1955 */
       
  1956 EXPORT_C void CWindowGc::SetOpaque(TBool aDrawOpaque)
       
  1957 	{
       
  1958 	iPimpl->WriteAnyPendingStateChanges();
       
  1959 	WriteInt(aDrawOpaque, EWsGcOpSetOpaque);
       
  1960 	}
       
  1961 
       
  1962 /** APIExtension can contain as many additional methods as is required by 
       
  1963 CGraphicsContext after its original conception. It takes 3 parameters.
       
  1964 Function is exported due to constrains of retaining BC with earlier versions.
       
  1965 This is not used directly by external methods, instead it is called by a named 
       
  1966 method in CGraphicsContext which passes the relivant arguements including an 
       
  1967 unique identifier for the required action.
       
  1968 @param aUid The unique identifier for the method that is required. Selected 
       
  1969 internally by a series of "if" statements. 
       
  1970 @see Valid Uid identifiers are listed in header gdi.h
       
  1971 @see CGraphicsContext
       
  1972 @param aOutput is a TAny pointer to a reference. Used to output data as the structure
       
  1973 does not need to be instantiated before the function call this adds greater 
       
  1974 flexibility.
       
  1975 @param aInput is a TAny pointer used to input data.
       
  1976 */	
       
  1977 EXPORT_C TInt CWindowGc::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput)
       
  1978 	{
       
  1979 	if (aUid == KGetUnderlineMetrics)
       
  1980 		{		
       
  1981 		return APIExGetUnderlineMetrics(aOutput);
       
  1982 		}
       
  1983 	else if (aUid == KSetShadowColor)
       
  1984 		{
       
  1985 		return APIExSetShadowColor(aInput);
       
  1986 		}
       
  1987 	else if (aUid == KGetShadowColor)
       
  1988 		{
       
  1989 		return APIExGetShadowColor(aOutput);
       
  1990 		}
       
  1991 	else if (aUid == KDrawTextInContextUid)
       
  1992 		{
       
  1993 		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
       
  1994 		return APIExDrawText(contextParam->iText, &contextParam->iParam, contextParam->iPosition);
       
  1995 		}
       
  1996 	else if (aUid == KDrawBoxTextInContextUid)
       
  1997 		{
       
  1998 		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
       
  1999 		return APIExDrawText(contextParam->iText,&contextParam->iParam,contextParam->iBox,contextParam->iBaselineOffset,contextParam->iAlign,contextParam->iMargin);
       
  2000 		}
       
  2001 	else if (aUid == KDrawTextInContextVerticalUid)
       
  2002 		{
       
  2003 		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
       
  2004 		return APIExDrawTextVertical(contextParam->iText, &contextParam->iParam, contextParam->iPosition,contextParam->iUp);
       
  2005 		}
       
  2006 	else if (aUid == KDrawBoxTextInContextVerticalUid)
       
  2007 		{
       
  2008 		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
       
  2009 		return APIExDrawTextVertical(contextParam->iText,&contextParam->iParam,contextParam->iBox,contextParam->iBaselineOffset,contextParam->iUp,contextParam->iAlign,contextParam->iMargin);
       
  2010 		}
       
  2011 	else if (aUid == KApiExtensionInterfaceUid)
       
  2012 		{
       
  2013 		return APIExInterface(aOutput, *static_cast<TUid*>(aInput));
       
  2014 		}
       
  2015 	/* Future cases may be placed here later.*/
       
  2016 	else
       
  2017 		return CBitmapContext::APIExtension(aUid, aOutput, aInput);
       
  2018 	}
       
  2019 
       
  2020 //The methods listed above in APIExtension follow here with the prefix APIEx.
       
  2021 TInt CWindowGc::APIExGetUnderlineMetrics(TAny*& aOutput)
       
  2022 	{
       
  2023 	const TInt width = Max(iPimpl->iFont->HeightInPixels() / 10,1);
       
  2024 	TTwoTInt* ptr = (TTwoTInt*)aOutput;
       
  2025 	ptr->iTop = 1 + width / 2;
       
  2026 	ptr->iBottom = (ptr->iTop) + width;
       
  2027 	return KErrNone;
       
  2028 	}
       
  2029 
       
  2030 TInt CWindowGc::APIExSetShadowColor(TAny* aShadowColor)
       
  2031 	{
       
  2032 	const TRgb shadowColor = *(reinterpret_cast<TRgb*> (aShadowColor));
       
  2033 	WriteInt(shadowColor.Internal(), EWsGcOpSetShadowColor);
       
  2034 	iPimpl->iShadowColor = shadowColor;
       
  2035 	return KErrNone;
       
  2036 	}
       
  2037 
       
  2038 TInt CWindowGc::APIExGetShadowColor(TAny*& aOutput)
       
  2039 	{
       
  2040 	TRgb* ptr = (TRgb*)aOutput;
       
  2041 	ptr->SetInternal(iPimpl->iShadowColor.Internal());
       
  2042 	return KErrNone;
       
  2043 	}
       
  2044 
       
  2045 //Default implementation of reserved virtual
       
  2046 EXPORT_C void CWindowGc::Reserved_CGraphicsContext_2()
       
  2047 	{
       
  2048 	CBitmapContext::Reserved_CGraphicsContext_2();
       
  2049 	}
       
  2050 
       
  2051 //Default implementation of reserved virtual
       
  2052 EXPORT_C void CWindowGc::Reserved_CBitmapContext_1()
       
  2053 	{
       
  2054 	CBitmapContext::Reserved_CBitmapContext_1();
       
  2055 	}
       
  2056 
       
  2057 //Default implementation of reserved virtual
       
  2058 EXPORT_C void CWindowGc::Reserved_CBitmapContext_2()
       
  2059 	{
       
  2060 	CBitmapContext::Reserved_CBitmapContext_2();
       
  2061 	}
       
  2062 
       
  2063 //Default implementation of reserved virtual
       
  2064 EXPORT_C void CWindowGc::Reserved_CBitmapContext_3()
       
  2065 	{
       
  2066 	CBitmapContext::Reserved_CBitmapContext_3();
       
  2067 	}
       
  2068 	
       
  2069 // was Reserved_CWindowGc_1
       
  2070 EXPORT_C void CWindowGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect)
       
  2071 /** Draws an abstract artwork.
       
  2072 It does nothing if aDestRect values fall outside the window area.
       
  2073 
       
  2074 @param aId the identifier for the artwork
       
  2075 @param aDestRect the destination rect within the active window for this artwork
       
  2076 
       
  2077 @since 9.2
       
  2078 @released
       
  2079 */
       
  2080 	{
       
  2081 	iPimpl->WriteAnyPendingStateChanges();
       
  2082 	TWsGcCmdDrawWsGraphic drawWsGraphic(aId,aDestRect);
       
  2083 	Write(&drawWsGraphic,sizeof(drawWsGraphic),EWsGcOpDrawWsGraphic);
       
  2084 	}
       
  2085 
       
  2086 // Reserved_CWindowGc_2
       
  2087 EXPORT_C void CWindowGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect,const TDesC8& aData)
       
  2088 /** Draws an abstract artwork.
       
  2089 It does nothing if aDestRect values fall outside the window area.
       
  2090 
       
  2091 @param aId the identifier for the artwork
       
  2092 @param aDestRect the destination rect within the active window for this artwork
       
  2093 @param aData opaque datagram to associate with this occasion of drawing.  The format is dependent upon the artwork
       
  2094 
       
  2095 @since 9.2
       
  2096 @released
       
  2097 */
       
  2098 	{
       
  2099 	iPimpl->WriteAnyPendingStateChanges();
       
  2100 	TWsGcCmdDrawWsGraphic drawWsGraphic(aId,aDestRect);
       
  2101 	drawWsGraphic.iDataLen = aData.Size();
       
  2102 	WriteTextCommand(&drawWsGraphic, sizeof(drawWsGraphic),	aData, EWsGcOpDrawWsGraphic, EWsGcOpDrawWsGraphicPtr);	
       
  2103 	}
       
  2104 
       
  2105 /**
       
  2106 Gets an extension interface specified by the supplied UID, or NULL if it isn't supported.
       
  2107 
       
  2108 @param aInterfaceId The UID of the requested interface
       
  2109 @return A pointer to the interface, or NULL if the interface isn't supported
       
  2110 @publishedPartner
       
  2111 @prototype
       
  2112 */
       
  2113 EXPORT_C TAny* CWindowGc::Interface(TUid aInterfaceId)
       
  2114 	{
       
  2115 	TAny* interface = NULL;
       
  2116 	if(KErrNone == APIExtension(KApiExtensionInterfaceUid, interface, &aInterfaceId))
       
  2117 		return interface;
       
  2118 	return NULL;
       
  2119 	}
       
  2120 
       
  2121 /**
       
  2122 Gets an extension interface specified by the supplied UID, or NULL if it isn't supported.
       
  2123 
       
  2124 @param aInterfaceId The UID of the requested interface
       
  2125 @return A pointer to the interface, or NULL if the interface isn't supported
       
  2126 @publishedPartner
       
  2127 @prototype
       
  2128 */
       
  2129 EXPORT_C const TAny* CWindowGc::Interface(TUid aInterfaceId) const
       
  2130 	{
       
  2131 	return const_cast<CWindowGc*>(this)->Interface(aInterfaceId);
       
  2132 	}
       
  2133 
       
  2134 TInt CWindowGc::APIExInterface(TAny*& aInterface, TUid aInterfaceId)
       
  2135 	{
       
  2136 	if(aInterfaceId == KMWsDrawResourceInterfaceUid)
       
  2137 		{
       
  2138 		aInterface = static_cast<MWsDrawResource*>(iPimpl);
       
  2139 		return KErrNone;
       
  2140 		}
       
  2141 	return KErrNotSupported;
       
  2142 	}
       
  2143 
       
  2144 void CWindowGc::DrawResource(const TPoint& aPos, const RWsDrawableSource& aSource, TGraphicsRotation aRotation)
       
  2145 	{
       
  2146 	iPimpl->WriteAnyPendingStateChanges();
       
  2147 	TWsGcCmdDrawResourceToPos drawWsResource(aSource.WsHandle(), aPos, aRotation);
       
  2148 	Write(&drawWsResource, sizeof(drawWsResource), EWsGcOpDrawResourceToPos);
       
  2149 	}
       
  2150 
       
  2151 void CWindowGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, TGraphicsRotation aRotation)
       
  2152 	{
       
  2153 	iPimpl->WriteAnyPendingStateChanges();
       
  2154 	TWsGcCmdDrawResourceToRect drawWsResource(aSource.WsHandle(), aDestRect, aRotation);
       
  2155 	Write(&drawWsResource, sizeof(drawWsResource), EWsGcOpDrawResourceToRect);
       
  2156 	}
       
  2157 
       
  2158 void CWindowGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TRect& aSrcRect, TGraphicsRotation aRotation)
       
  2159 	{
       
  2160 	iPimpl->WriteAnyPendingStateChanges();
       
  2161 	TWsGcCmdDrawResourceFromRectToRect drawWsResource(aSource.WsHandle(), aDestRect, aSrcRect, aRotation);
       
  2162 	Write(&drawWsResource, sizeof(drawWsResource), EWsGcOpDrawResourceFromRectToRect);
       
  2163 	}
       
  2164 
       
  2165 void CWindowGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TDesC8& aParam)
       
  2166 	{
       
  2167 	iPimpl->WriteAnyPendingStateChanges();
       
  2168 	TWsGcCmdDrawResourceWithData drawWsResource(aSource.WsHandle(), aDestRect, &aParam);
       
  2169 	Write(&drawWsResource, sizeof(drawWsResource),EWsGcOpDrawResourceWithData);
       
  2170 	}
       
  2171 
       
  2172 //Default implementation of reserved virtual
       
  2173 EXPORT_C void CWindowGc::Reserved_CWindowGc_3()
       
  2174 	{
       
  2175 	}
       
  2176 
       
  2177 //Default implementation of reserved virtual
       
  2178 EXPORT_C void CWindowGc::Reserved_CWindowGc_4()
       
  2179 	{
       
  2180 	}
       
  2181 
       
  2182 //Default implementation of reserved virtual
       
  2183 EXPORT_C void CWindowGc::Reserved_CWindowGc_5()
       
  2184 	{
       
  2185 	}
       
  2186 
       
  2187 /**
       
  2188 Default constructor. 
       
  2189 Only for embedding instances of RWsDrawableSource into other classes as data members. 
       
  2190 Before a RWsDrawableSource can be used the other constructor must be called. 
       
  2191  */
       
  2192 EXPORT_C RWsDrawableSource::RWsDrawableSource()
       
  2193 	: iDrawableId(KSgNullDrawableId), iScreenNumber(KSgScreenIdMain)
       
  2194 	{
       
  2195 	}
       
  2196 
       
  2197 /**
       
  2198 Constructor.
       
  2199 @param aWs Session to the window server
       
  2200  
       
  2201 @pre Connection to the window server is established
       
  2202  */
       
  2203 EXPORT_C RWsDrawableSource::RWsDrawableSource(RWsSession &aWs)
       
  2204 	: MWsClientClass(aWs.iBuffer), iDrawableId(KSgNullDrawableId), iScreenNumber(KSgScreenIdMain)
       
  2205 	{
       
  2206 	}
       
  2207 
       
  2208 /**
       
  2209 Create window server object for resource drawing operation via window server.
       
  2210 
       
  2211 This object will be identified by a unique handle and will be associated with drawable resource which is passed as a parameter.
       
  2212 
       
  2213 This object will be created for drawing onto the default screen only.
       
  2214  
       
  2215 @see CWindowGc
       
  2216 @param  aDrawable Drawable resource.
       
  2217  
       
  2218 @post Drawable source is created and can be used by window server. The reference counter of the underlying
       
  2219 		image resource is incremented. 
       
  2220 
       
  2221 @return KErrNone if successful, KErrArgument if the image resource is not valid,
       
  2222 		KErrAlreadyExists if this handle is already associated with a 
       
  2223 		specific resource,  otherwise one of the system-wide error codes.
       
  2224  */
       
  2225 EXPORT_C TInt RWsDrawableSource::Create(const RSgDrawable& aDrawable)
       
  2226 	{
       
  2227 	return Create(aDrawable, KSgScreenIdMain);
       
  2228 	}
       
  2229 
       
  2230 /**
       
  2231 Create window server object for resource drawing operation via window server.
       
  2232 
       
  2233 This object will be identified by  unique handle and will be associated with drawable resource which is passed as a parameter.
       
  2234 
       
  2235 This object will be created for drawing onto the specified screen only.
       
  2236 
       
  2237 @see CWindowGc
       
  2238 @param  aDrawable Drawable resource.
       
  2239 @param  aScreenNumber The screen onto which this drawable resource can be drawn.
       
  2240  
       
  2241 @post Drawable source is created and can be used by window server. The reference counter of the underlying
       
  2242 		image resource is incremented. 
       
  2243 
       
  2244 @return KErrNone if successful, KErrArgument if the image resource is not valid
       
  2245 		or if the specified screen is invalid, KErrAlreadyExists if this handle
       
  2246 		is already associated with a specific resource, otherwise one of the
       
  2247 		system-wide error codes.
       
  2248  */
       
  2249 EXPORT_C TInt RWsDrawableSource::Create(const RSgDrawable& aDrawable, TInt aScreenNumber)
       
  2250 	{
       
  2251 	if (iWsHandle)
       
  2252 		{
       
  2253 		return KErrAlreadyExists;
       
  2254 		}
       
  2255 	CGraphicsResourceWrapperFactory* grwFactory = new CGraphicsResourceWrapperFactory();
       
  2256 	if (!grwFactory)
       
  2257 		return KErrNoMemory;
       
  2258 	CGraphicsResourceWrapper* graphicsResource = grwFactory->NewGraphicsResourceWrapper();
       
  2259 	if(!graphicsResource)
       
  2260 		{
       
  2261 		delete grwFactory;
       
  2262 		return KErrNotSupported;
       
  2263 		}
       
  2264 	if (graphicsResource->IsNull(aDrawable) || aScreenNumber < 0)
       
  2265 		{
       
  2266 		delete graphicsResource;
       
  2267 		delete grwFactory;
       
  2268 		return KErrArgument;
       
  2269 		}
       
  2270 	TWsClCmdCreateDrawableSource create(graphicsResource->Id(aDrawable), aScreenNumber);
       
  2271 	TInt ret;
       
  2272 	if ((ret = iBuffer->WriteReplyWs(&create, sizeof(TWsClCmdCreateDrawableSource), EWsClOpCreateDrawableSource)) < 0)
       
  2273 		{
       
  2274 		delete graphicsResource;
       
  2275 		delete grwFactory;
       
  2276 		return ret;
       
  2277 		}
       
  2278 	iWsHandle = ret;
       
  2279 	iDrawableId = graphicsResource->Id(aDrawable);
       
  2280 	iScreenNumber = aScreenNumber;
       
  2281 	delete graphicsResource;
       
  2282 	delete grwFactory;
       
  2283 	return KErrNone;
       
  2284 	}
       
  2285 
       
  2286 /**
       
  2287 Destroy the window server drawable source. 
       
  2288 Calling this method on a object that is not associated with any RSgDrawable 
       
  2289 resource will have no effect. Once Close() is called, this drawable source object can be reused.
       
  2290 
       
  2291 @post	The window server drawable object is destroyed. The instance is no longer associated
       
  2292 		with a RSgDrawable specific resource. The reference counter of the underlying
       
  2293 		image resource is decremented. 
       
  2294 */
       
  2295 EXPORT_C void RWsDrawableSource::Close()
       
  2296 	{
       
  2297 	if (iWsHandle)
       
  2298 		{
       
  2299 		Write(EWsDrawableSourceOpFree);
       
  2300 		iWsHandle = 0;
       
  2301 		iDrawableId = KSgNullDrawableId;
       
  2302 		iScreenNumber = KSgScreenIdMain;
       
  2303 		}
       
  2304 	}
       
  2305 
       
  2306 /**
       
  2307  Get the unique ID of the associated drawable resource.
       
  2308  */
       
  2309 EXPORT_C const TSgDrawableId& RWsDrawableSource::DrawableId() const
       
  2310 	{
       
  2311 	return iDrawableId;
       
  2312 	}
       
  2313 
       
  2314 /**
       
  2315  Get the screen number of the drawable source.
       
  2316  */
       
  2317 EXPORT_C TInt RWsDrawableSource::ScreenNumber() const
       
  2318 	{
       
  2319 	return iScreenNumber;
       
  2320 	}