windowing/windowserver/nonnga/CLIENT/RGC.CPP
changeset 0 5d03bc08d59c
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 <graphics/gdi/gdiconsts.h>
       
    24 #include <graphics/gdi/gdistructs.h>
       
    25 
       
    26 NONSHARABLE_STRUCT(CWindowGc::CPimpl): public CBase
       
    27 /** @internalComponent @released */
       
    28 	{
       
    29 	friend class CWindowGc;
       
    30 
       
    31 	CPimpl();
       
    32 	CFbsFont *iFont;
       
    33 	};
       
    34 
       
    35 CWindowGc::CPimpl::CPimpl() : iFont(NULL)
       
    36 	{
       
    37 	}
       
    38 
       
    39 enum {EPolygonMaxHeaderSize=sizeof(TWsCmdHeader)+sizeof(TWsGcCmdSegmentedDrawPolygonData)};
       
    40 
       
    41 EXPORT_C CWindowGc::CWindowGc(CWsScreenDevice *aDevice) : MWsClientClass(aDevice->iBuffer), iPimpl(NULL), iDevice(aDevice)
       
    42 /** Constructor which creates, but does not initialise a graphics context. 
       
    43 
       
    44 @param aDevice Any screen device owned by the same session. Its life time 
       
    45 should be at least as long as the gc itself. 
       
    46 @see CWsScreenDevice::CreateContext() */
       
    47 	{}
       
    48 
       
    49 EXPORT_C CWindowGc::~CWindowGc()
       
    50 /** Destructor. */
       
    51 	{
       
    52 	if (iBuffer && iWsHandle)
       
    53 		Write(EWsGcOpFree);
       
    54 	delete iPimpl;
       
    55 	}
       
    56 
       
    57 void CWindowGc::WriteTextCommand(TAny *cmd, TInt len,const TDesC &aBuf,TInt opcode,TInt opcodePtr) const
       
    58 	{
       
    59 	if ((aBuf.Size()+len)>(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)))
       
    60 		{
       
    61 		WriteReplyByProvidingRemoteReadAccess(cmd,len,&aBuf,opcodePtr);
       
    62 		}
       
    63 	else
       
    64 		{
       
    65 		Write(cmd,len,aBuf.Ptr(),aBuf.Size(),opcode);
       
    66 		}
       
    67 	}
       
    68 
       
    69 void CWindowGc::WriteTextCommand(TAny *cmd, TInt len,const TDesC8 &aBuf,TInt opcode,TInt opcodePtr) const
       
    70 	{
       
    71 	if ((aBuf.Size()+len)>(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)))
       
    72 		{
       
    73 		WriteReplyByProvidingRemoteReadAccess(cmd,len,&aBuf,opcodePtr);
       
    74 		}
       
    75 	else
       
    76 		{
       
    77 		Write(cmd,len,aBuf.Ptr(),aBuf.Size(),opcode);
       
    78 		}
       
    79 	}	
       
    80 	
       
    81 EXPORT_C TInt CWindowGc::Construct()
       
    82 /** Completes construction. 
       
    83 
       
    84 @return KErrNone if successful, otherwise a leave error. 
       
    85 @panic TW32Panic 17 in debug builds if called on an already constructed object.
       
    86 This function always causes a flush of the window server buffer. */
       
    87 	{
       
    88 	__ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction));
       
    89 	iPimpl = new CPimpl;
       
    90 	if (!iPimpl)
       
    91 		return KErrNoMemory;
       
    92 	TInt ret;
       
    93 	if ((ret=iBuffer->WriteReplyWs(EWsClOpCreateGc))<0)
       
    94 		return(ret);
       
    95 	iWsHandle=ret;
       
    96 	return(KErrNone);
       
    97 	}
       
    98 
       
    99 EXPORT_C void CWindowGc::Activate(RDrawableWindow &aDevice)
       
   100 /** 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.  
       
   101 
       
   102 When drawing is complete, the code using the context should call Deactivate(). 
       
   103 Draw methods invoked after an Activate() will affect the window specified. 
       
   104 A graphics context can only be active for one window at a time. A panic occurs 
       
   105 if a draw function is called before calling this function, or if Activate() 
       
   106 is called twice without an intervening Deactivate().
       
   107 
       
   108 @param aWindow The window for which the graphics context is to be activated. */
       
   109 	{
       
   110 	TUint devicePointer = WriteReplyInt(aDevice.WsHandle(),EWsGcOpActivate);
       
   111 	iDevice = (CWsScreenDevice*)devicePointer;
       
   112 	}
       
   113 
       
   114 EXPORT_C void CWindowGc::Deactivate()
       
   115 /** Frees the graphics context to be used with another window. 
       
   116 
       
   117 This method should be called when the application has completed drawing to 
       
   118 the window. */
       
   119 	{
       
   120 	Write(EWsGcOpDeactivate);
       
   121 	iPimpl->iFont=NULL;
       
   122 	}
       
   123 
       
   124 //====================Functions from GDI.H===============================
       
   125 
       
   126 EXPORT_C CGraphicsDevice* CWindowGc::Device() const
       
   127 /** Returns a pointer to the device, more specifically a CWsScreenDevice, for the screen that the WindowGc was last activated on.
       
   128 If the WindowGc has not been activated at all, it then returns the device that was passed to its constructor.
       
   129 
       
   130 The user should be careful when calling this function since it can return the screen device of any screen in the system.
       
   131 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.
       
   132 @return A pointer to the device for the screen that the WindowGc was last activated on or the device passed at construction*/
       
   133 	{
       
   134 	return(iDevice);
       
   135 	}
       
   136 
       
   137 EXPORT_C void CWindowGc::SetOrigin(const TPoint &aPoint)
       
   138 /** Sets the position of the co-ordinate origin. 
       
   139 
       
   140 All subsequent drawing operations are then done relative to this origin. The 
       
   141 default origin is (0,0), the top left corner of the window.
       
   142 
       
   143 @param aPoint A point for the origin, default (0,0). 
       
   144 @see CGraphicsContext::SetOrigin() */
       
   145 	{
       
   146 	WritePoint(aPoint,EWsGcOpSetOrigin);
       
   147 	}
       
   148 
       
   149 EXPORT_C void CWindowGc::SetClippingRect(const TRect& aRect)
       
   150 /** Sets a clipping rectangle.
       
   151 
       
   152 Graphics drawn to the window are clipped, so that only items which fall within 
       
   153 the rectangle are displayed. 
       
   154 
       
   155 Note that clipping is additive. If a clipping region has been set using SetClippingRegion() 
       
   156 then clipping will be to the intersection of that region and this rectangle.
       
   157 
       
   158 @param aRect The clipping rectangle. 
       
   159 @see SetClippingRegion() */
       
   160 	{
       
   161 	WriteRect(aRect,EWsGcOpSetClippingRect);
       
   162 	}
       
   163 
       
   164 EXPORT_C void CWindowGc::CancelClippingRect()
       
   165 /** Cancels the clipping rectangle. 
       
   166 
       
   167 @see SetClippingRect() */
       
   168 	{
       
   169 	Write(EWsGcOpCancelClippingRect);
       
   170 	}
       
   171 
       
   172 EXPORT_C TInt CWindowGc::SetClippingRegion(const TRegion &aRegion)
       
   173 /** Sets the clipping region.
       
   174 
       
   175 Drawing is always clipped to the visible area of a window. The region specified 
       
   176 by this function is in addition to that area.
       
   177 
       
   178 This function always causes a flush of the window server buffer.
       
   179 
       
   180 @param aClippingRegion New clipping region. 
       
   181 @return KErrNone if successful, KErrNoMemory if there is insufficient memory 
       
   182 to create the region on the server side, otherwise another error code. */
       
   183 	{
       
   184 	const TInt regionCount=aRegion.Count();
       
   185 	TPtrC8 ptrRect(reinterpret_cast<const TUint8*>(aRegion.RectangleList()),regionCount*sizeof(TRect));
       
   186 	return(WriteReplyByProvidingRemoteReadAccess(&regionCount,sizeof(regionCount),&ptrRect,EWsGcOpSetClippingRegion));
       
   187 	}
       
   188 
       
   189 EXPORT_C void CWindowGc::CancelClippingRegion()
       
   190 /** Cancels the current clipping region. */
       
   191 	{
       
   192 	Write(EWsGcOpCancelClippingRegion);
       
   193 	}
       
   194 
       
   195 EXPORT_C void CWindowGc::SetDrawMode(TDrawMode aDrawingMode)
       
   196 /** Sets the drawing mode. 
       
   197 
       
   198 This affects the colour that is actually drawn, because it defines the way 
       
   199 that the current screen colour logically combines with the current pen colour 
       
   200 and brush colour. 
       
   201 
       
   202 There are 13 drawing modes (see CGraphicsContext::TDrawMode enum), each giving 
       
   203 different logical combinations of pen, brush and screen colours. Each mode 
       
   204 is produced by ORing together different combinations of seven drawing mode 
       
   205 components (see CGraphicsContext::TDrawModeComponents enum).
       
   206 
       
   207 The three most important modes are TDrawMode::EDrawModePEN, TDrawMode::EDrawModeNOTSCREEN 
       
   208 and TDrawMode::EDrawModeXOR. The default drawing mode is TDrawMode::EDrawModePEN.
       
   209 
       
   210 The drawing mode is over-ridden for line and shape drawing functions when 
       
   211 a wide pen line has been selected. It is forced to TDrawMode::EDrawModePEN. 
       
   212 This is to prevent undesired effects at line joins (vertexes).
       
   213 
       
   214 Notes:
       
   215 
       
   216 TDrawMode::EDrawModeAND gives a "colour filter" effect. For example:
       
   217 
       
   218 ANDing with white gives the original colour 
       
   219 
       
   220 ANDing with black gives black 
       
   221 
       
   222 TDrawMode::EDrawModeOR gives a "colour boost" effect. For example:
       
   223 
       
   224 ORing with black gives the original colour 
       
   225 
       
   226 ORing with white gives white 
       
   227 
       
   228 TDrawMode::EDrawModeXOR gives an "Exclusive OR" effect. For example:
       
   229 
       
   230 white XOR black gives white 
       
   231 
       
   232 white XOR white gives black 
       
   233 
       
   234 black XOR black gives black
       
   235 
       
   236 @param aDrawingMode A drawing mode. 
       
   237 @see CGraphicsContext::SetDrawMode() */
       
   238 	{
       
   239 	WriteInt(aDrawingMode,EWsGcOpSetDrawMode);
       
   240 	}
       
   241 
       
   242 EXPORT_C void CWindowGc::UseFont(const CFont *aFont)
       
   243 /** Sets this context's font.
       
   244 
       
   245 The font is used for text drawing. If the font is already in the font and 
       
   246 bitmap server's memory the GDI will share that copy.
       
   247 
       
   248 Note that this function must be called prior to drawing text or the calling 
       
   249 thread will panic.
       
   250 
       
   251 @param aFont A device font. 
       
   252 @see CGraphicsContext::UseFont() */
       
   253 	{
       
   254 	if (iPimpl->iFont!=(CFbsFont *)aFont)
       
   255 		{
       
   256 		iPimpl->iFont=(CFbsFont *)aFont;
       
   257 		WriteInt(iPimpl->iFont->Handle(),EWsGcOpUseFont);
       
   258 		}
       
   259 	}
       
   260 
       
   261 EXPORT_C void CWindowGc::DiscardFont()
       
   262 /** Discards a font. 
       
   263 
       
   264 This frees up the memory used (if the font is not being shared with some other 
       
   265 process).
       
   266 
       
   267 Note that if no font is in use when this function is called, then there is no effect.
       
   268 
       
   269 @see CGraphicsContext::DiscardFont() */
       
   270 	{
       
   271 	Write(EWsGcOpDiscardFont);
       
   272 	iPimpl->iFont=NULL;
       
   273 	}
       
   274 
       
   275 EXPORT_C void CWindowGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
       
   276 /** Sets the underline style for all subsequently drawn text.
       
   277 
       
   278 @param aUnderlineStyle The underline style: either on or off.
       
   279 @see CGraphicsContext::SetUnderlineStyle() */
       
   280 	{
       
   281 	WriteInt(aUnderlineStyle,EWsGcOpSetUnderlineStyle);
       
   282 	}
       
   283 
       
   284 EXPORT_C void CWindowGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
       
   285 /** Sets the strikethrough style for all subsequently drawn text.
       
   286 
       
   287 @param aStrikethroughStyle The strikethrough style: either on or off. 
       
   288 @see CGraphicsContext::SetStrikethroughStyle() */
       
   289 	{
       
   290 	WriteInt(aStrikethroughStyle,EWsGcOpSetStrikethroughStyle);
       
   291 	}
       
   292 
       
   293 void CWindowGc::SetJustification(TInt aExcessWidth,TInt aNumGaps, TInt aOpcode)
       
   294 	{
       
   295 	TWsGcCmdSetJustification justification;
       
   296 
       
   297 	justification.excessWidth=aExcessWidth;
       
   298 	justification.numGaps=aNumGaps;
       
   299 	Write(&justification,sizeof(justification),aOpcode);
       
   300 	}
       
   301 
       
   302 EXPORT_C void CWindowGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps)
       
   303 /** Sets word justification.
       
   304 
       
   305 This function is particularly useful for doing WYSIWYG underlining or strikethrough, 
       
   306 as it ensures that the lines extend correctly into the gaps between words. It is not 
       
   307 intended for regular use by developers.
       
   308 
       
   309 @param aExcessWidth The excess width (in pixels) to be distributed between 
       
   310 the specified number of gaps (starting immediately) 
       
   311 @param aNumGaps The number of gaps between words 
       
   312 @see CGraphicsContext::SetWordJustification() */
       
   313 	{
       
   314 	SetJustification(aExcessWidth, aNumGaps, EWsGcOpSetWordJustification);
       
   315 	}
       
   316 
       
   317 EXPORT_C void CWindowGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars)
       
   318 /** Sets the character justification.
       
   319 
       
   320 This function is used primarily to get accurate WYSIWYG, and is not intended 
       
   321 for regular use by developers.
       
   322 
       
   323 The text line that is to be justified has a certain number of characters (this 
       
   324 includes the spaces between the words). It also has a distance (in pixels) 
       
   325 between the end of the last word and the actual end of the line (right hand 
       
   326 margin, usually). These excess width pixels are distributed amongst all the 
       
   327 characters, increasing the gaps between them, to achieve full justification 
       
   328 of the text line.
       
   329 
       
   330 This function is particularly useful for WYSIWYG underlining or strikethrough, 
       
   331 as it ensures that the lines extend into the gaps between characters.
       
   332 
       
   333 See CGraphicsContext::SetCharJustification() for more information.
       
   334 
       
   335 @param aExcessWidth The excess width (in pixels) to be distributed between 
       
   336 the specified number of characters. 
       
   337 @param aNumChars The number of characters involved 
       
   338 @see CGraphicsContext::SetCharJustification() */
       
   339 	{
       
   340 	SetJustification(aExcessWidth, aNumChars, EWsGcOpSetCharJustification);
       
   341 	}
       
   342 
       
   343 EXPORT_C void CWindowGc::SetPenColor(const TRgb &aColor)
       
   344 /** Sets the pen colour.
       
   345 
       
   346 The effective pen colour depends on the drawing mode (see SetDrawMode()).
       
   347 
       
   348 The default pen colour is black.
       
   349 
       
   350 @param aColor The RGB colour for the pen. 
       
   351 @see CGraphicsContext::SetPenColor() */
       
   352 	{
       
   353 	WriteInt(aColor.Internal(),EWsGcOpSetPenColor);
       
   354 	}
       
   355 
       
   356 EXPORT_C void CWindowGc::SetPenStyle(TPenStyle aPenStyle)
       
   357 /** Sets the line drawing style for the pen. 
       
   358 
       
   359 The pen is used when drawing lines and for the outline of filled shapes. There 
       
   360 are 6 pen styles (see CGraphicsContext::TPenStyle enum). If no pen style is 
       
   361 set, the default is TPenStyle::ESolidPen.
       
   362 
       
   363 To use a pen style, its full context must be given, e.g. for a null pen: CGraphicsContext::TPenStyle::ENullPen.
       
   364 
       
   365 @param aPenStyle A pen style. 
       
   366 @see CGraphicsContext::SetPenStyle() */
       
   367 	{
       
   368 	WriteInt(aPenStyle,EWsGcOpSetPenStyle);
       
   369 	}
       
   370 
       
   371 EXPORT_C void CWindowGc::SetPenSize(const TSize& aSize)
       
   372 /** Sets the line drawing size for the pen.
       
   373 
       
   374 Lines of size greater than one pixel are drawn with rounded ends that extend 
       
   375 beyond the end points, (as if the line is drawn using a circular pen tip of 
       
   376 the specified size). Rounded ends of lines drawn with a wide pen are always 
       
   377 drawn in TDrawMode::EDrawModePEN mode, overriding whatever mode has been set 
       
   378 using SetDrawMode().
       
   379 
       
   380 @param aSize A line size, the default being 1 pixel. 
       
   381 @see CGraphicsContext::SetPenSize() */
       
   382 	{
       
   383 	WriteSize(aSize,EWsGcOpSetPenSize);
       
   384 	}
       
   385 
       
   386 EXPORT_C void CWindowGc::SetBrushColor(const TRgb &aColor)
       
   387 /** Sets the brush colour. 
       
   388 
       
   389 The effective brush colour depends on the drawing mode (see SetDrawMode()). 
       
   390 If no brush colour has been set, it defaults to white. However the default 
       
   391 brush style is null, so when drawing to a window, the default appears to be 
       
   392 the window's background colour.
       
   393 
       
   394 @param aColor The RGB colour for the brush. 
       
   395 @see CGraphicsContext::SetBrushColor() */
       
   396 	{
       
   397 	WriteInt(aColor.Internal(),EWsGcOpSetBrushColor);
       
   398 	}
       
   399 
       
   400 EXPORT_C void CWindowGc::SetBrushStyle(TBrushStyle aBrushStyle)
       
   401 /** Sets the line drawing style for the brush.
       
   402 
       
   403 The GDI provides ten brush styles, including six built-in hatching patterns 
       
   404 (see CGraphicsContext::TBrushStyle).
       
   405 
       
   406 Use TBrushStyle::ENullBrush to draw the outline of a fillable shape on its 
       
   407 own, without filling.
       
   408 
       
   409 If the TBrushStyle::EPatternedBrush style is set, but no bitmap pattern has 
       
   410 been selected using UseBrushPattern(), then the brush defaults to TBrushStyle::ENullBrush.
       
   411 
       
   412 Hatching lines are done in the current brush colour, set using SetBrushColor(). 
       
   413 Hatching can be overlaid on other graphics. The hatching pattern starts at 
       
   414 the brush origin, set using SetBrushOrigin().
       
   415 
       
   416 @param aBrushStyle The brush style. 
       
   417 @see CGraphicsContext::SetBrushStyle() */
       
   418 	{
       
   419 	WriteInt(aBrushStyle,EWsGcOpSetBrushStyle);
       
   420 	}
       
   421 
       
   422 EXPORT_C void CWindowGc::SetBrushOrigin(const TPoint &aOrigin)
       
   423 /** Sets the brush pattern origin. 
       
   424 
       
   425 This specifies the position of the pixel in the top left corner of a reference 
       
   426 pattern tile, (in absolute device co-ordinates). Other copies of the pattern 
       
   427 tile are then drawn around the reference one. Thus the brush origin can be 
       
   428 set as the top left corner of a shape.
       
   429 
       
   430 The brush pattern may be a built-in style (see SetBrushStyle()), or a bitmap. 
       
   431 To use a bitmap, the brush must have a pattern set (see UseBrushPattern()) 
       
   432 and the brush style must be set to TBrushStyle::EPatternedBrush.
       
   433 
       
   434 Notes:
       
   435 
       
   436 If SetBrushOrigin() is not used, then the origin defaults to (0,0).
       
   437 
       
   438 This brush origin remains in effect for all fillable shapes drawn subsequently, 
       
   439 until a new brush origin is set. Shapes can thus be considered as windows 
       
   440 onto a continuous pattern field (covering the whole clipping region of a screen 
       
   441 device, or the whole device area of a printer).
       
   442 
       
   443 @param aOrigin The origin point for the brush. 
       
   444 @see CGraphicsContext::SetBrushOrigin() */
       
   445 	{
       
   446 	WritePoint(aOrigin,EWsGcOpSetBrushOrigin);
       
   447 	}
       
   448 
       
   449 EXPORT_C void CWindowGc::UseBrushPattern(const CFbsBitmap *aDevice)
       
   450 /** Sets the brush pattern to the specified bitmap. 
       
   451 
       
   452 For the brush to actually use the bitmap, TBrushStyle::EPatternedBrush must 
       
   453 be used to set the brush style (see SetBrushStyle()). When the brush pattern 
       
   454 is no longer required, use DiscardBrushPattern() to free up the memory used, 
       
   455 (if the bitmap is not being shared). If UseBrushPattern() is used again without 
       
   456 using DiscardBrushPattern() then the previous pattern is discarded automatically.
       
   457 
       
   458 Notes:
       
   459 
       
   460 When loading a bitmap, the GDI checks to see if the bitmap is already in memory. 
       
   461 If the bitmap is already there, then that copy is shared.
       
   462 
       
   463 The brush does not need to have a pattern set at all. There are several built-in 
       
   464 hatching patterns, which can be selected using SetBrushStyle().
       
   465 
       
   466 @param aDevice A bitmap pattern for the brush 
       
   467 @see CGraphicsContext::UseBrushPattern() */
       
   468 	{
       
   469 	WriteInt(aDevice->Handle(),EWsGcOpUseBrushPattern);
       
   470 	AddToBitmapArray(aDevice->Handle());
       
   471 	}
       
   472 
       
   473 EXPORT_C void CWindowGc::DiscardBrushPattern()
       
   474 /** Discards a non-built-in brush pattern. 
       
   475 
       
   476 This frees up the memory used for the bitmap, if it is not being shared by 
       
   477 another process.
       
   478 
       
   479 If no brush pattern has been set when this function is called, it has no effect.
       
   480 
       
   481 @see CGraphicsContext::DiscardBrushPattern() */
       
   482 	{
       
   483 	Write(EWsGcOpDiscardBrushPattern);
       
   484 	}
       
   485 
       
   486 EXPORT_C void CWindowGc::Plot(const TPoint &aPoint)
       
   487 /** Draws a single point. 
       
   488 
       
   489 The point is drawn with the current pen settings using the current drawing 
       
   490 mode.
       
   491 
       
   492 Note: if the pen size is greater than one pixel, a filled circle of the current 
       
   493 pen colour is drawn, with the pen size as the diameter and the plotted point 
       
   494 as the centre. If the pen size is an even number of pixels, the extra pixels 
       
   495 are drawn below and to the right of the centre. See SetPenSize().
       
   496 
       
   497 @param aPoint The point to be drawn. 
       
   498 @see CGraphicsContext::Plot() */
       
   499 	{
       
   500 	WritePoint(aPoint,EWsGcOpPlot);
       
   501 	}
       
   502 
       
   503 EXPORT_C void CWindowGc::DrawLine(const TPoint &aPoint1,const TPoint &aPoint2)
       
   504 /** Draws a straight line between two points.
       
   505 
       
   506 @param aPoint1 The point at the start of the line. 
       
   507 @param aPoint2 The point at the end of the line. 
       
   508 @see CGraphicsContext::DrawLine() */
       
   509 	{
       
   510 	TWsGcCmdDrawLine drawLine(aPoint1,aPoint2);
       
   511 	Write(&drawLine,sizeof(drawLine),EWsGcOpDrawLine);
       
   512 	}
       
   513 
       
   514 EXPORT_C void CWindowGc::MoveTo(const TPoint &aPoint)
       
   515 /** Moves the internal drawing position relative to the co-ordinate origin, without 
       
   516 drawing a line.
       
   517 
       
   518 A subsequent call to DrawLineTo() or DrawLineBy() will then use the new internal 
       
   519 drawing position as the start point for the line drawn.
       
   520 
       
   521 Notes:
       
   522 
       
   523 The operations DrawLine(), DrawLineTo(), DrawLineBy() and DrawPolyline() also 
       
   524 change the internal drawing position to the last point of the drawn line(s).
       
   525 
       
   526 The internal drawing position is set to the co-ordinate origin if no drawing 
       
   527 or moving operations have yet taken place.
       
   528 
       
   529 @param aPoint The point to move the internal drawing position to. 
       
   530 @see CGraphicsContext::MoveTo()
       
   531 @see CGraphicsContext::MoveBy() */
       
   532 	{
       
   533 	WritePoint(aPoint,EWsGcOpMoveTo);
       
   534 	}
       
   535 
       
   536 EXPORT_C void CWindowGc::MoveBy(const TPoint &aPoint)
       
   537 /** Moves the internal drawing position by a vector, without drawing a line.
       
   538 
       
   539 The internal drawing position is moved relative to its current co-ordinates.
       
   540 
       
   541 @param aPoint The vector to move the internal drawing position by. 
       
   542 @see CGraphicsContext::MoveBy()
       
   543 @see CGraphicsContext::MoveTo() */
       
   544 	{
       
   545 	WritePoint(aPoint,EWsGcOpMoveBy);
       
   546 	}
       
   547 
       
   548 EXPORT_C void CWindowGc::DrawLineTo(const TPoint &aPoint)
       
   549 /** Draws a straight line from the current internal drawing position to a point.
       
   550 
       
   551 @param aPoint The point at the end of the line. 
       
   552 @see CGraphicsContext::DrawLineTo() */
       
   553 	{
       
   554 	WritePoint(aPoint,EWsGcOpDrawTo);
       
   555 	}
       
   556 
       
   557 EXPORT_C void CWindowGc::DrawLineBy(const TPoint &aPoint)
       
   558 /** Draws a straight line relative to the current internal drawing position, using 
       
   559 a vector.
       
   560 
       
   561 The start point of the line is the current internal drawing position. The 
       
   562 vector aVector is added to the internal drawing position to give the end point 
       
   563 of the line
       
   564 
       
   565 @param aPoint The vector to add to the current internal drawing position, 
       
   566 giving the end point of the line. 
       
   567 @see CGraphicsContext::DrawLineBy() */
       
   568 	{
       
   569 	WritePoint(aPoint,EWsGcOpDrawBy);
       
   570 	}
       
   571 
       
   572 void CWindowGc::doDrawPolyLine(const CArrayFix<TPoint> *aPointArray, const TPoint* aPointList,TInt aNumPoints)
       
   573 	{
       
   574 	TWsGcOpcodes opcode=EWsGcOpDrawPolyLine;
       
   575 	TWsGcCmdDrawPolyLine polyLine;
       
   576 	TInt maxBufLen=(iBuffer->BufferSize()-sizeof(TWsCmdHeader)-sizeof(polyLine))/sizeof(TPoint);
       
   577 	TInt sent=0;
       
   578 	while(sent<aNumPoints)
       
   579 		{
       
   580 		TInt availableLen;
       
   581 		const TPoint *ptr;
       
   582 		if (aPointArray)
       
   583 			{
       
   584 			ptr=&(*aPointArray)[sent];
       
   585 			availableLen=aPointArray->End(sent)-ptr;
       
   586 			}
       
   587 		else
       
   588 			{
       
   589 			ptr=aPointList+sent;
       
   590 			availableLen=aNumPoints-sent;
       
   591 			}
       
   592 		polyLine.numPoints=Min(availableLen,maxBufLen);
       
   593 		sent+=polyLine.numPoints;
       
   594 		polyLine.more=(sent!=aNumPoints);
       
   595 		Write(&polyLine,sizeof(polyLine),ptr,polyLine.numPoints*sizeof(TPoint),opcode);
       
   596 		polyLine.last=ptr[polyLine.numPoints-1];
       
   597 		opcode=EWsGcOpDrawPolyLineContinued;
       
   598 		} 
       
   599 	}
       
   600 
       
   601 EXPORT_C void CWindowGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
       
   602 /** Draws a polyline using points in a list. 
       
   603 
       
   604 A polyline is a series of concatenated straight lines joining a set of points.
       
   605 
       
   606 @param aPointList Pointer to a list of points on the polyline. 
       
   607 @param aNumPoints The number of points in the point list. 
       
   608 @see CGraphicsContext::DrawPolyLine() */
       
   609 	{
       
   610 	doDrawPolyLine(NULL,aPointList,aNumPoints);
       
   611 	}
       
   612 
       
   613 EXPORT_C void CWindowGc::DrawPolyLine(const CArrayFix<TPoint> *aPointArray)
       
   614 /** Draws a polyline using points in an array. 
       
   615 
       
   616 A polyline is a series of concatenated straight lines joining a set of points.
       
   617 
       
   618 @param aPointArray An array containing the points on the polyline. 
       
   619 @see CGraphicsContext::DrawPolyLine() */
       
   620 	{
       
   621 	doDrawPolyLine(aPointArray,NULL,aPointArray->Count());
       
   622 	}
       
   623 
       
   624 TInt CWindowGc::doDrawPolygon(const CArrayFix<TPoint> *aPointArray,const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
       
   625 	{
       
   626 	if (aNumPoints<=0)
       
   627 		return(KErrNone);
       
   628 	TWsGcCmdSegmentedDrawPolygonData polyData;
       
   629 	polyData.index=0;
       
   630 	TInt maxBufLen=(iBuffer->BufferSize()-EPolygonMaxHeaderSize)/sizeof(TPoint);
       
   631 	FOREVER
       
   632 		{
       
   633 		const TPoint *ptr;
       
   634 		TInt availableLen;
       
   635 		if (aPointArray)
       
   636 			{
       
   637 			ptr=&(*aPointArray)[polyData.index];
       
   638 			availableLen=aPointArray->End(polyData.index)-ptr;
       
   639 			}
       
   640 		else
       
   641 			{
       
   642 			ptr=aPointList+polyData.index;
       
   643 			availableLen=aNumPoints-polyData.index;
       
   644 			}
       
   645 		polyData.numPoints=Min(availableLen,maxBufLen);
       
   646 		if (polyData.index==0)	// First time around
       
   647 			{
       
   648 			if (polyData.numPoints==aNumPoints)	// Can it be done in one go?
       
   649 				{
       
   650 				TWsGcCmdDrawPolygon drawPolygon;
       
   651 				drawPolygon.numPoints=aNumPoints;
       
   652 				drawPolygon.fillRule=aFillRule;
       
   653 				Write(&drawPolygon,sizeof(drawPolygon),ptr,aNumPoints*sizeof(TPoint),EWsGcOpDrawPolygon);
       
   654 				break;
       
   655 				}
       
   656 			TWsGcCmdStartSegmentedDrawPolygon start;
       
   657 			start.totalNumPoints=aNumPoints;
       
   658 			TInt err=WriteReply(&start,sizeof(start),EWsGcOpStartSegmentedDrawPolygon);
       
   659 			if (err!=KErrNone)
       
   660 				return(err);
       
   661 			}
       
   662 		Write(&polyData,sizeof(polyData),ptr,polyData.numPoints*sizeof(TPoint),EWsGcOpSegmentedDrawPolygonData);
       
   663 		polyData.index+=polyData.numPoints;
       
   664 		if (polyData.index==aNumPoints)
       
   665 			{
       
   666 			TWsGcCmdDrawSegmentedPolygon draw;
       
   667 			draw.fillRule=aFillRule;
       
   668 			Write(&draw,sizeof(draw),EWsGcOpDrawSegmentedPolygon);
       
   669 			break;
       
   670 			}
       
   671 		}
       
   672 	return(KErrNone);
       
   673 	}
       
   674 
       
   675 EXPORT_C TInt CWindowGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
       
   676 /** Draws and fills a polygon using points defined in a list.
       
   677 
       
   678 The first TPoint in the list defines the start of the first side of the polygon. 
       
   679 The second TPoint defines the second vertex (the end point of the first side 
       
   680 and the start point of the second side) and so on. The final side of the polygon 
       
   681 is drawn using the last TPoint from the array or list, and the line drawn 
       
   682 to the start point of the first side.
       
   683 
       
   684 Self-crossing polygons can be filled according to one of two rules, TFillRule::EAlternate 
       
   685 (the default), or TFillRule::EWinding. To explain the difference between these 
       
   686 rules, the concept of a winding number needs to be introduced. The area outside 
       
   687 any of the loops of the polygon has a winding number of zero, and is never 
       
   688 filled. An inside a loop which is bounded by an area with winding number 0 
       
   689 has a winding number of 1. If an area is within a loop that is bounded by 
       
   690 an area with winding number 1, e.g. a loop within a loop, has a winding number 
       
   691 of 2, and so on.
       
   692 
       
   693 The filling of a polygon proceeds according to this algorithm:
       
   694 
       
   695 If aFillRule is TFillRule::EAlternate (default) and it has an odd winding 
       
   696 number, then fill the surrounding area.
       
   697 
       
   698 If aFillRule is TFillRule::EWinding and it has a winding number greater than 
       
   699 zero, then fill the surrounding area.
       
   700 
       
   701 This function always causes a flush of the window server buffer.
       
   702 
       
   703 @param aPointList Pointer to a list of points, specifying the vertices of 
       
   704 the polygon. 
       
   705 @param aNumPoints The number of points in the vertex list 
       
   706 @param aFillRule Either TFillRule::EAlternate (the default) or TFillRule::EWinding. 
       
   707 @return KErrNone if successful, otherwise another of the system-wide error 
       
   708 codes. 
       
   709 @see CGraphicsContext::DrawPolygon() */
       
   710 	{
       
   711 	return(doDrawPolygon(NULL,aPointList,aNumPoints,aFillRule));
       
   712 	}
       
   713 
       
   714 EXPORT_C TInt CWindowGc::DrawPolygon(const CArrayFix<TPoint> *aPointArray,TFillRule aFillRule)
       
   715 /** Draws and fills a polygon using points defined in an array.
       
   716 
       
   717 The first TPoint in the array defines the start of the first side of the polygon. 
       
   718 The second TPoint defines the second vertex (the end point of the first side 
       
   719 and the start point of the second side) and so on. The final side of the polygon 
       
   720 is drawn using the last TPoint from the array or list, and the line drawn 
       
   721 to the start point of the first side.
       
   722 
       
   723 Self-crossing polygons can be filled according to one of two rules, TFillRule::EAlternate 
       
   724 (the default), or TFillRule::EWinding. To explain the difference between these 
       
   725 rules, the concept of a winding number needs to be introduced. The area outside 
       
   726 any of the loops of the polygon has a winding number of zero, and is never 
       
   727 filled. An inside a loop which is bounded by an area with winding number 0 
       
   728 has a winding number of 1. If an area is within a loop that is bounded by 
       
   729 an area with winding number 1, e.g. a loop within a loop, has a winding number 
       
   730 of 2, and so on.
       
   731 
       
   732 The filling of a polygon proceeds according to this algorithm:
       
   733 
       
   734 If aFillRule is TFillRule::EAlternate (default) and it has an odd winding 
       
   735 number, then fill the surrounding area.
       
   736 
       
   737 If aFillRule is TFillRule::EWinding and it has a winding number greater than 
       
   738 zero, then fill the surrounding area.
       
   739 
       
   740 This function always causes a flush of the window server buffer.
       
   741 
       
   742 @param aPointArray An array of points, specifying the vertices of the polygon. 
       
   743 @param aFillRule Either TFillRule::EAlternate (the default) or TFillRule::EWinding. 
       
   744 @return KErrNone if successful, otherwise another of the system-wide error 
       
   745 codes. 
       
   746 @see CGraphicsContext::DrawPolygon() */
       
   747 	{
       
   748 	return(doDrawPolygon(aPointArray,NULL,aPointArray->Count(),aFillRule));
       
   749 	}
       
   750 
       
   751 void CWindowGc::DrawArcOrPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd, TInt aOpcode)
       
   752 	{
       
   753 	TWsGcCmdDrawArcOrPie cmd(aRect,aStart,aEnd);
       
   754 	Write(&cmd,sizeof(cmd),aOpcode);
       
   755 	}
       
   756 
       
   757 EXPORT_C void CWindowGc::DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
       
   758 /** Draws an arc (a portion of an ellipse).
       
   759 
       
   760 The point aStart is used to define one end of a line from the geometric centre 
       
   761 of the ellipse. The point of intersection between this line and the ellipse 
       
   762 defines the start point of the arc. The point aEnd is used to define one end 
       
   763 of a second line from the geometric centre of the ellipse. The point of intersection 
       
   764 between this line and the ellipse defines the end point of the arc. The pixels 
       
   765 at both the start point and the end point are drawn.
       
   766 
       
   767 The arc itself is the segment of the ellipse in an anti-clockwise direction 
       
   768 from the start point to the end point.
       
   769 
       
   770 Notes
       
   771 
       
   772 A rectangle is used in the construction of the ellipse of which the arc is 
       
   773 a segment. This rectangle is passed as an argument of type TRect.
       
   774 
       
   775 A wide line arc is drawn with the pixels distributed either side of a true 
       
   776 ellipse, in such a way that the outer edge of the line would touch the edge 
       
   777 of the construction rectangle. In other words, the ellipse used to construct 
       
   778 it is slightly smaller than that for a single pixel line size.
       
   779 
       
   780 If aStart or aEnd are the ellipse centre then the line that defines the start/end 
       
   781 of the arc defaults to one extending vertically above the centre point.
       
   782 
       
   783 If aStart and aEnd are the same point, or points on the same line through 
       
   784 the ellipse centre then a complete unfilled ellipse is drawn.
       
   785 
       
   786 Line drawing is subject to pen colour, width and style and draw mode
       
   787 
       
   788 @param aRect The rectangle in which to draw the ellipse (of which the arc is 
       
   789 a segment).
       
   790 @param aStart A point to define the start of the arc.
       
   791 @param aEnd A point to define the end of the arc.
       
   792 @see CGraphicsContext::DrawArc() */
       
   793 	{
       
   794 	DrawArcOrPie(aRect,aStart,aEnd,EWsGcOpDrawArc);
       
   795 	}
       
   796 
       
   797 EXPORT_C void CWindowGc::DrawPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
       
   798 /** Draws and fills a pie-shaped slice of an ellipse.
       
   799 
       
   800 Outlines are subject to the current pen colour, width, style and draw mode. 
       
   801 Set the pen to ENullPen for no outline. The fill is subject to brush style 
       
   802 (colour, hash or pattern), the origin and the current drawing mode. Set the 
       
   803 brush to ENullBrush for no fill.
       
   804 
       
   805 The point aStart is used to define one end of a line to the centre of the 
       
   806 ellipse. The point of intersection between this line and the ellipse defines 
       
   807 the start point of the arc bounding the pie slice. The point aEnd is used 
       
   808 to define one end of a second line to the centre of the ellipse. The point 
       
   809 of intersection between this line and the ellipse defines the end point of 
       
   810 the arc bounding the pie slice. The pixels at the end point are not drawn.
       
   811 
       
   812 The pie slice itself is the area bounded by: the arc of the ellipse in an 
       
   813 anticlockwise direction from the start point to the end point; the straight 
       
   814 line from the start point from the geometric centre of the ellipse; the 
       
   815 straight line from the end point from the geometric centre of the ellipse.
       
   816 
       
   817 The line drawn by the pen goes inside the rectangle given by the aRect argument.
       
   818 
       
   819 Notes:
       
   820 
       
   821 A rectangle is used in the construction of the pie slice. This rectangle is 
       
   822 passed as an argument of type TRect. The curved edge of the pie slice is an 
       
   823 arc of an ellipse constructed within the rectangle.
       
   824 
       
   825 A wide line edged pie slice has the arc drawn with the pixels distributed 
       
   826 either side of a true ellipse. This is done in such a way that the outer edge 
       
   827 of the line would touch the edge of the construction rectangle. In other words, 
       
   828 the ellipse used to construct it is slightly smaller than that for a single 
       
   829 pixel line size.
       
   830 
       
   831 If aStart or aEnd are the ellipse centre then the line that defines the start/end 
       
   832 of the arc defaults to one extending vertically above the centre point.
       
   833 
       
   834 If aStart and aEnd are the same point, or points on the same line through 
       
   835 the ellipse centre then a complete filled ellipse is drawn. A line is also 
       
   836 drawn from the edge to the ellipse centre.
       
   837 
       
   838 @param aRect A rectangle in which to draw the ellipse bounding the pie slice 
       
   839 @param aStart A point to define the start of the pie slice 
       
   840 @param aEnd A point to define the end of the pie slice 
       
   841 @see CGraphicsContext::DrawPie() */
       
   842 	{
       
   843 	DrawArcOrPie(aRect,aStart,aEnd,EWsGcOpDrawPie);
       
   844 	}
       
   845 
       
   846 EXPORT_C void CWindowGc::DrawEllipse(const TRect &aRect)
       
   847 /** Draws and fills an ellipse.
       
   848 
       
   849 The ellipse is drawn inside the rectangle defined by the aRect argument. Any 
       
   850 TRect that has odd pixel dimensions, has the bottom right corner trimmed to 
       
   851 give even pixel dimensions before the ellipse is constructed.
       
   852 
       
   853 The column and row of pixels containing the bottom right co-ordinate of the 
       
   854 aRect argument are not part of the rectangle.
       
   855 
       
   856 Note: a wide outline ellipse is drawn with the pixels distributed either side of 
       
   857 a true ellipse, in such a way that the outer edge of the line touches the 
       
   858 edge of the construction rectangle. In other words, the ellipse used to construct 
       
   859 it is smaller than that for a single pixel line size.
       
   860 
       
   861 @param aRect The rectangle in which to draw the ellipse 
       
   862 @see CGraphicsContext::DrawEllipse() */
       
   863 	{
       
   864 	WriteRect(aRect,EWsGcOpDrawEllipse);
       
   865 	}
       
   866 
       
   867 EXPORT_C void CWindowGc::DrawRect(const TRect &aRect)
       
   868 /** Draws and fills a rectangle. 
       
   869 
       
   870 The rectangle's border is drawn with the pen, and it is filled using the brush.
       
   871 
       
   872 @param aRect The rectangle to be drawn. 
       
   873 @see CGraphicsContext::DrawRect() */
       
   874 	{
       
   875 	WriteRect(aRect,EWsGcOpDrawRect);
       
   876 	}
       
   877 
       
   878 EXPORT_C void CWindowGc::DrawRoundRect(const TRect &aRect,const TSize &aEllipse)
       
   879 /** Draws and fills a rectangle with rounded corners.
       
   880 
       
   881 The rounded corners are each constructed as an arc of an ellipse. The dimensions 
       
   882 of each corner (corner size and corner height) are given by aEllipse. See 
       
   883 DrawArc() for a description of arc construction.
       
   884 
       
   885 The line drawn by the pen (if any) goes inside the rectangle given by the 
       
   886 TRect argument.
       
   887 
       
   888 Notes:
       
   889 
       
   890 Dotted and dashed pen styles cannot be used for the outline of a rounded rectangle.
       
   891 
       
   892 If either corner size dimension is greater than half the corresponding rectangle 
       
   893 length, the corner size dimension is reduced to half the rectangle size.
       
   894 
       
   895 @param aRect The rectangle to be drawn. 
       
   896 @param aEllipse The dimensions of each corner. 
       
   897 @see CGraphicsContext::DrawRoundRect() */
       
   898 	{
       
   899 	TWsGcCmdDrawRoundRect drawRoundRect(aRect,aEllipse);
       
   900 	Write(&drawRoundRect,sizeof(drawRoundRect),EWsGcOpDrawRoundRect);
       
   901 	}
       
   902 
       
   903 EXPORT_C void CWindowGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice)
       
   904 /** Draws a bitmap at a specified point. 
       
   905 
       
   906 The function does a compress/stretch based on its internally stored size in 
       
   907 twips. Note that if the twips value of the bitmap is not set then nothing 
       
   908 is drawn (this is the default situation).
       
   909 
       
   910 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
   911 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
   912 At some point later WSERV may need to draw that window again and it will just replay the 
       
   913 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
   914 WSERV will effectively draw a different bitmap when it replays the commands.
       
   915 
       
   916 Note: this member function uses the bitmap's size in twips and does a stretch/compress 
       
   917 blit using a linear DDA.
       
   918 
       
   919 @param aTopLeft The point where the top left pixel of the bitmap is to be 
       
   920 drawn 
       
   921 @param aDevice The source bitmap. 
       
   922 @see CGraphicsContext::DrawBitmap() */
       
   923 	{
       
   924 	TWsGcCmdDrawBitmap drawBitmap(aTopLeft,aDevice->Handle());
       
   925 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap);
       
   926 	AddToBitmapArray(aDevice->Handle());
       
   927 	}
       
   928 
       
   929 EXPORT_C void CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice)
       
   930 /** Draws a bitmap in a rectangle.
       
   931 
       
   932 The bitmap is compressed/stretched to fit the specified rectangle. Note that 
       
   933 if the twips value of the bitmap is not set then nothing is drawn (this is 
       
   934 the default situation).
       
   935 
       
   936 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
   937 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
   938 At some point later WSERV may need to draw that window again and it will just replay the 
       
   939 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
   940 WSERV will effectively draw a different bitmap when it replays the commands.
       
   941 
       
   942 Notes: this member function uses the bitmap's size in pixels and does a stretch/compress 
       
   943 blit using a linear DDA.
       
   944 
       
   945 @param aDestRect The rectangle within which the bitmap is to be drawn. 
       
   946 @param aDevice The source bitmap. 
       
   947 @see CGraphicsContext::DrawBitmap() */
       
   948 	{
       
   949 	TWsGcCmdDrawBitmap2 drawBitmap(aDestRect,aDevice->Handle());
       
   950 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap2);
       
   951 	AddToBitmapArray(aDevice->Handle());
       
   952 	}
       
   953 
       
   954 EXPORT_C void CWindowGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect)
       
   955 /** Draws a specified rectangle from a bitmap into another rectangle.
       
   956 
       
   957 The function compresses/stretches the specified rectangle from the bitmap 
       
   958 to fit the destination rectangle. Note that if the twips value of the bitmap 
       
   959 is not set then nothing is drawn (this is the default situation).
       
   960 
       
   961 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
   962 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
   963 At some point later WSERV may need to draw that window again and it will just replay the 
       
   964 stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
       
   965 WSERV will effectively draw a different bitmap when it replays the commands.
       
   966 
       
   967 Note: this member function uses rectangle sizes in pixels and does a stretch/compress 
       
   968 blit using a linear DDA.
       
   969 
       
   970 @param aDestRect The rectangle within which the bitmap is to be drawn. 
       
   971 @param aDevice A source bitmap. 
       
   972 @param aSourceRect The rectangle in the source bitmap that is copied to the 
       
   973 destination rectangle. 
       
   974 @see CGraphicsContext::DrawBitmap() */
       
   975 	{
       
   976 	TWsGcCmdDrawBitmap3 drawBitmap(aDestRect,aDevice->Handle(),aSourceRect);
       
   977 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmap3);
       
   978 	AddToBitmapArray(aDevice->Handle());
       
   979 	}
       
   980 
       
   981 /** Draws a specified rectangle from a bitmap and its mask into another rectangle.
       
   982 
       
   983 The function compresses/stretches the specified rectangle from the bitmap 
       
   984 to fit the destination rectangle. 
       
   985 The mask bitmap can be used as either a positive or negative mask. Masked 
       
   986 pixels are not mapped to the destination rectangle.
       
   987 
       
   988 A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black 
       
   989 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
   990 being transferred to the destination rectangle. With aInvertMask=ETrue, white 
       
   991 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
   992 being transferred to the destination rectangle.
       
   993 
       
   994 If mask bitmap's display mode is EColor256, the function does AplhaBlending
       
   995 and ignores aInvertMask parameter.
       
   996 
       
   997 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
   998 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
   999 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1000 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1001 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1002 
       
  1003 Note: this member function uses rectangle sizes in pixels and does a stretch/compress 
       
  1004 blit using a linear DDA.
       
  1005 
       
  1006 @param aDestRect The rectangle within which the masked bitmap is to be drawn. 
       
  1007 @param aBitmap A source bitmap. 
       
  1008 @param aSourceRect The rectangle in the source bitmap that is copied to the 
       
  1009 destination rectangle.
       
  1010 @param aMaskBitmap A mask bitmap. 
       
  1011 @param aInvertMask If false, a source pixel that is masked by a black pixel 
       
  1012 is not transferred to the destination rectangle. If true, then a source pixel 
       
  1013 that is masked by a white pixel is not transferred to the destination rectangle. */
       
  1014 EXPORT_C void CWindowGc::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask)
       
  1015 	{
       
  1016 	TWsGcCmdDrawBitmapMasked drawBitmap(aDestRect,aBitmap->Handle(),aSourceRect,aMaskBitmap->Handle(),aInvertMask);
       
  1017 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpDrawBitmapMasked);
       
  1018 	AddToBitmapArray(aBitmap->Handle());
       
  1019 	AddToBitmapArray(aMaskBitmap->Handle());
       
  1020 	}
       
  1021 
       
  1022 EXPORT_C void CWindowGc::DrawBitmapMasked(const TRect& aDestRect, const CWsBitmap* aBitmap, const TRect& aSourceRect, const CWsBitmap* aMaskBitmap, TBool aInvertMask)
       
  1023 /** Draws a specified rectangle from a wserv bitmap and its mask into 
       
  1024 another rectangle.
       
  1025 
       
  1026 The function compresses/stretches the specified rectangle from the bitmap 
       
  1027 to fit the destination rectangle. 
       
  1028 The mask bitmap can be used as either a positive or negative mask. Masked 
       
  1029 pixels are not mapped to the destination rectangle.
       
  1030 
       
  1031 A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black 
       
  1032 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1033 being transferred to the destination rectangle. With aInvertMask=ETrue, white 
       
  1034 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1035 being transferred to the destination rectangle.
       
  1036 
       
  1037 If mask bitmap's display mode is EColor256, the function does AplhaBlending
       
  1038 and ignores aInvertMask parameter.
       
  1039 
       
  1040 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1041 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1042 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1043 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1044 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1045 
       
  1046 Note: this member function uses rectangle sizes in pixels and does a stretch/compress 
       
  1047 blit using a linear DDA.
       
  1048 
       
  1049 @param aDestRect The rectangle within which the masked bitmap is to be drawn. 
       
  1050 @param aBitmap A source wserv bitmap. 
       
  1051 @param aSourceRect The rectangle in the source bitmap that is copied to the 
       
  1052 destination rectangle.
       
  1053 @param aMaskBitmap A mask wserv bitmap. 
       
  1054 @param aInvertMask If false, a source pixel that is masked by a black pixel 
       
  1055 is not transferred to the destination rectangle. If true, then a source pixel 
       
  1056 that is masked by a white pixel is not transferred to the destination rectangle. */
       
  1057 	{
       
  1058 	TWsGcCmdDrawBitmapMasked drawBitmap(aDestRect,aBitmap->WsHandle(),aSourceRect,aMaskBitmap->WsHandle(),aInvertMask);
       
  1059 	Write(&drawBitmap,sizeof(drawBitmap),EWsGcOpWsDrawBitmapMasked);
       
  1060 	AddToBitmapArray(aBitmap->Handle());
       
  1061 	AddToBitmapArray(aMaskBitmap->Handle());
       
  1062 	}
       
  1063 EXPORT_C void CWindowGc::DrawText(const TDesC &aBuf, const TPoint &aPos)
       
  1064 /** Draws horizontal text with no surrounding box. 
       
  1065 
       
  1066 The appearance of the text is subject to the drawing mode, the font, pen colour, 
       
  1067 word justification and character justification. 
       
  1068 
       
  1069 A panic occurs if this function is called when there is no font: see UseFont().
       
  1070 
       
  1071 @param aBuf The string to write. 
       
  1072 @param aPos The point specifying the position of the baseline at the left 
       
  1073 end of the text.
       
  1074 @see CGraphicsContext::DrawText() */
       
  1075 	{
       
  1076 	TWsGcCmdDrawText printText(aPos,aBuf.Length());
       
  1077 	WriteTextCommand(&printText,sizeof(printText),aBuf,EWsGcOpDrawText,EWsGcOpDrawTextPtr);
       
  1078 	}
       
  1079 
       
  1080 EXPORT_C void CWindowGc::DrawText(const TDesC &aBuf,const TRect &aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
       
  1081 /** Draws horizontal text within a cleared box.
       
  1082 
       
  1083 The appearance of the text is subject to the drawing mode, the font, pen colour, 
       
  1084 word justification and character justification. It is also subject to the 
       
  1085 background brush (set brush to ENullBrush for no effect on background).
       
  1086 
       
  1087 A panic occurs if this function is called when there is no font: see UseFont().
       
  1088 
       
  1089 Note: the text is clipped to the box. You must ensure that the specified string 
       
  1090 is not too large.
       
  1091 
       
  1092 @param aBuf The text to write.
       
  1093 @param aBox The box to draw the text in. 
       
  1094 @param aBaselineOffset An offset from the top of the box to the text baseline. 
       
  1095 Note that the baseline is the line on which letters sit, for instance below r, s, t, and 
       
  1096 above the tail of q, and y. 
       
  1097 @param aHoriz The text alignment mode (default is left, rather than centre 
       
  1098 or right). 
       
  1099 @param aLeftMrg The left margin for left-aligned text, or the right margin 
       
  1100 for right-aligned text (default is zero). 
       
  1101 @see CGraphicsContext::DrawText() */
       
  1102 	{
       
  1103 	if (aBuf.Size()<(TInt)(iBuffer->BufferSize()-sizeof(TWsCmdHeader)-sizeof(TWsGcCmdBoxTextOptimised2))) 
       
  1104 		{
       
  1105 		if (aHoriz==ELeft && aLeftMrg==0)
       
  1106 			{
       
  1107 			TWsGcCmdBoxTextOptimised1 boxTextOpt1(aBox,aBaselineOffset,aBuf.Length());
       
  1108 			Write(&boxTextOpt1,sizeof(boxTextOpt1),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextOptimised1);
       
  1109 			}
       
  1110 		else
       
  1111 			{
       
  1112 			TWsGcCmdBoxTextOptimised2 boxTextOpt2(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length());
       
  1113 			Write(&boxTextOpt2,sizeof(boxTextOpt2),aBuf.Ptr(),aBuf.Size(),EWsGcOpDrawBoxTextOptimised2);
       
  1114 			}
       
  1115 		}
       
  1116 	else
       
  1117 		{
       
  1118 		TWsGcCmdBoxText boxText(aBox,aBaselineOffset,aHoriz,aLeftMrg,aBuf.Length(),iPimpl->iFont->TextWidthInPixels(aBuf));
       
  1119 		WriteTextCommand(&boxText,sizeof(boxText),aBuf,EWsGcOpDrawBoxText,EWsGcOpDrawBoxTextPtr);
       
  1120 		}
       
  1121 	}
       
  1122 
       
  1123 EXPORT_C void CWindowGc::DrawTextVertical(const TDesC& aText,const TPoint& aPos,TBool aUp)
       
  1124 /** Draws vertical text in the specified direction.
       
  1125 
       
  1126 A panic occurs if this function is called when there is no font: see UseFont().
       
  1127 
       
  1128 @param aText The text to be drawn. 
       
  1129 @param aPos Point of origin of the text baseline. 
       
  1130 @param aUp Direction. ETrue for up, EFalse for down. */
       
  1131 	{
       
  1132 	TWsGcCmdDrawTextVertical printText(aPos,aText.Length(),aUp);
       
  1133 	WriteTextCommand(&printText,sizeof(printText),aText,EWsGcOpDrawTextVertical,EWsGcOpDrawTextVerticalPtr);
       
  1134 	}
       
  1135 
       
  1136 EXPORT_C void CWindowGc::DrawTextVertical(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
       
  1137 /** Draws text vertically in the specified direction, within a box of the specified 
       
  1138 size.
       
  1139 
       
  1140 A panic occurs if this function is called when there is no font: see UseFont().
       
  1141 
       
  1142 @param aText The text to be drawn. 
       
  1143 @param aBox The bounding box within which the text should be drawn, and which 
       
  1144 it is clipped to.
       
  1145 @param aBaselineOffset The height of the top of the characters from their text 
       
  1146 baseline. 
       
  1147 @param aUp The direction. ETrue for up, EFalse for down.
       
  1148 @param aVert The text alignment. 
       
  1149 @param aMargin The margin. */
       
  1150 	{
       
  1151 	TWsGcCmdBoxTextVertical boxText(aBox);
       
  1152 	boxText.baselineOffset=aBaselineOffset;
       
  1153 	boxText.up=aUp;
       
  1154 	boxText.vert=aVert;
       
  1155 	boxText.margin=aMargin;
       
  1156 	boxText.length=aText.Length();
       
  1157 	boxText.width=iPimpl->iFont->TextWidthInPixels(aText);
       
  1158 	WriteTextCommand(&boxText,sizeof(boxText),aText,EWsGcOpDrawBoxTextVertical,EWsGcOpDrawBoxTextVerticalPtr);
       
  1159 	}
       
  1160 
       
  1161 //========================Extra functions============================
       
  1162 
       
  1163 EXPORT_C void CWindowGc::CopyRect(const TPoint &anOffset,const TRect &aRect)
       
  1164 /** Copies a rectangle from any part of the screen into the window that the gc 
       
  1165 is active on.
       
  1166 
       
  1167 The copy part of the operation applies to the whole rectangle, irrespective 
       
  1168 of whether or not it within the window, however the "paste" is clipped to 
       
  1169 the drawing area.
       
  1170 
       
  1171 The rectangle is specified in window coordinates (if the top-left of the rectangle 
       
  1172 is (0,0) then the area of the screen it specifies has its top-left at the 
       
  1173 top left corner of the window, if it is (-10,-10) then it starts 10 pixels 
       
  1174 above and to the left of the window). 
       
  1175 
       
  1176 Note: shadows in the source rectangle will be copied. None of the area drawn to 
       
  1177 will gain shadowing (even if the window is already in shadow).
       
  1178 
       
  1179 This version of this function is only really suitable for testing.
       
  1180 
       
  1181 @param anOffset The offset from the original position to the point where the 
       
  1182 rectangle is copied. 
       
  1183 @param aRect The rectangular area to be copied. This is in window co-ordinates, 
       
  1184 e.g. the top left corner of the window is position (0,0) with respect to the 
       
  1185 rectangle.
       
  1186 @see CBitmapContext::CopyRect() */
       
  1187 	{
       
  1188 	TWsGcCmdCopyRect copyRect(anOffset,aRect);
       
  1189 	Write(&copyRect,sizeof(copyRect),EWsGcOpCopyRect);
       
  1190 	}
       
  1191 
       
  1192 EXPORT_C void CWindowGc::BitBlt(const TPoint &aPoint, const CFbsBitmap *aBitmap)
       
  1193 /** Performs a bitmap block transfer.
       
  1194 
       
  1195 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1196 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1197 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1198 stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
       
  1199 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1200 
       
  1201 @param aPoint The position for the top left corner of the bitmap. 
       
  1202 @param aBitmap A memory-resident bitmap. 
       
  1203 @see CBitmapContext::BitBlt() */
       
  1204 	{
       
  1205 	if (aBitmap == NULL || !aBitmap->Handle())
       
  1206 		return; 
       
  1207 	TWsGcCmdGdiBlt2 gdiBlit(aPoint,aBitmap->Handle());
       
  1208 	Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiBlt2);
       
  1209 	AddToBitmapArray(aBitmap->Handle());
       
  1210 	}
       
  1211 
       
  1212 EXPORT_C void CWindowGc::BitBlt(const TPoint &aDestination,const CFbsBitmap *aBitmap,const TRect &aSource)
       
  1213 /** Performs a bitmap block transfer of a rectangular piece of a bitmap.
       
  1214 
       
  1215 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1216 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1217 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1218 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1219 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1220 
       
  1221 Note: if the rectangle aSource is larger than the bitmap then the bitmap will be padded 
       
  1222 with white.
       
  1223 
       
  1224 @param aDestination The position for the top left corner of the bitmap. 
       
  1225 @param aBitmap A memory-resident bitmap 
       
  1226 @param aSource A rectangle defining the piece of the bitmap to be drawn, with 
       
  1227 co-ordinates relative to the top left corner of the bitmap 
       
  1228 @see CBitmapContext::BitBlt() */
       
  1229 	{
       
  1230 	if (aBitmap == NULL || !aBitmap->Handle())
       
  1231 		return; 
       
  1232 	TWsGcCmdGdiBlt3 gdiBlit(aDestination,aBitmap->Handle(),aSource);
       
  1233 	Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiBlt3);
       
  1234 	AddToBitmapArray(aBitmap->Handle());
       
  1235 	}
       
  1236 
       
  1237 EXPORT_C void CWindowGc::BitBltMasked(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask)
       
  1238 /** Performs a masked bitmap block transfer of a memory resident source bitmap.
       
  1239 
       
  1240 The mask bitmap can be used as either a positive or negative mask. Masked 
       
  1241 pixels are not mapped to the destination rectangle.
       
  1242 
       
  1243 A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black 
       
  1244 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1245 being transferred to the destination rectangle. With aInvertMask=ETrue, white 
       
  1246 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1247 being transferred to the destination rectangle.
       
  1248 
       
  1249 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1250 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1251 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1252 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1253 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1254 
       
  1255 @param aPoint A position for the top left corner of the bitmap. 
       
  1256 @param aBitmap A memory-resident source bitmap. 
       
  1257 @param aSourceRect A rectangle defining the piece of the bitmap to be drawn, 
       
  1258 with co-ordinates relative to the top left corner of the bitmap 
       
  1259 @param aMaskBitmap A mask bitmap. 
       
  1260 @param aInvertMask If false, a source pixel that is masked by a black pixel 
       
  1261 is not transferred to the destination rectangle. If true, then a source pixel 
       
  1262 that is masked by a white pixel is not transferred to the destination rectangle. 
       
  1263 
       
  1264 @see CBitmapContext::BitBltMasked() */
       
  1265 	{
       
  1266 	if (aBitmap == NULL || !aBitmap->Handle() || aMaskBitmap == NULL || !aMaskBitmap->Handle())
       
  1267 		return; 
       
  1268 	TWsGcCmdBltMasked gdiBlitMasked(aPoint,aBitmap->Handle(),aSourceRect,aMaskBitmap->Handle(),aInvertMask);
       
  1269 	Write(&gdiBlitMasked,sizeof(gdiBlitMasked),EWsGcOpGdiBltMasked);
       
  1270 	AddToBitmapArray(aBitmap->Handle());
       
  1271 	AddToBitmapArray(aMaskBitmap->Handle());
       
  1272 	}
       
  1273 
       
  1274 EXPORT_C void CWindowGc::BitBlt(const TPoint &aPoint, const CWsBitmap *aBitmap)
       
  1275 /** Performs a bitmap block transfer on a bitmap to which the window server already 
       
  1276 has a handle.
       
  1277 
       
  1278 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1279 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1280 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1281 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1282 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1283 
       
  1284 This function should be used in preference to the CFbsBitmap overload if the 
       
  1285 bitmap is to be used more than once, as it is a lot quicker.
       
  1286 
       
  1287 @param aPoint The position for the top left corner of the bitmap. 
       
  1288 @param aBitmap A window server bitmap. 
       
  1289 @see CBitmapContext::BitBlt() */
       
  1290 	{
       
  1291 	if (aBitmap == NULL || !aBitmap->Handle())
       
  1292 		return; 
       
  1293 	TWsGcCmdGdiBlt2 gdiBlit(aPoint,aBitmap->WsHandle());
       
  1294 	Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiWsBlt2);
       
  1295 	AddToBitmapArray(aBitmap->Handle());
       
  1296 	}
       
  1297 
       
  1298 EXPORT_C void CWindowGc::BitBlt(const TPoint &aDestination,const CWsBitmap  *aBitmap,const TRect &aSource)
       
  1299 /** Performs a bitmap block transfer of a rectangular piece of a bitmap to which 
       
  1300 the window server already has a handle.
       
  1301 
       
  1302 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1303 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1304 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1305 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1306 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1307 
       
  1308 This function should be used in preference to the CFbsBitmap overload if the 
       
  1309 bitmap is to be used more than once, as it is a lot quicker.
       
  1310 
       
  1311 Note: if the rectangle aSource is larger than the bitmap then the bitmap will be padded 
       
  1312 with white.
       
  1313 	
       
  1314 @param aDestination The position for the top left corner of the bitmap. 
       
  1315 @param aBitmap A window server bitmap. 
       
  1316 @param aSource A rectangle defining the piece of the bitmap to be drawn, with 
       
  1317 co-ordinates relative to the top left corner of the bitmap 
       
  1318 @see CBitmapContext::BitBlt() */
       
  1319 	{
       
  1320 	if (aBitmap == NULL || !aBitmap->Handle())
       
  1321 		return; 
       
  1322 	TWsGcCmdGdiBlt3 gdiBlit(aDestination,aBitmap->WsHandle(),aSource);
       
  1323 	Write(&gdiBlit,sizeof(gdiBlit),EWsGcOpGdiWsBlt3);
       
  1324 	AddToBitmapArray(aBitmap->Handle());
       
  1325 	}
       
  1326 
       
  1327 EXPORT_C void CWindowGc::BitBltMasked(const TPoint& aPoint,const CWsBitmap * aBitmap,const TRect& aSourceRect,const CWsBitmap * aMaskBitmap,TBool aInvertMask)
       
  1328 /** Performs a masked bitmap block transfer of a window server bitmap.
       
  1329 
       
  1330 The mask bitmap can be used as either a positive or negative mask. Masked 
       
  1331 pixels are not mapped to the destination rectangle.
       
  1332 
       
  1333 A black and white (binary) mask bitmap is used. With aInvertMask=EFalse, black 
       
  1334 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1335 being transferred to the destination rectangle. With aInvertMask=ETrue, white 
       
  1336 pixels in the mask bitmap stop corresponding pixels in the source bitmap from 
       
  1337 being transferred to the destination rectangle.
       
  1338 
       
  1339 This function should be used in preference to the CFbsBitmap overload if the 
       
  1340 bitmap is to be used more than once, as it is a lot quicker.
       
  1341 
       
  1342 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1343 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1344 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1345 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1346 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1347 
       
  1348 @param aPoint A position for the top left corner of the bitmap. 
       
  1349 @param aBitmap A window server bitmap. 
       
  1350 @param aSourceRect A rectangle defining the piece of the bitmap to be drawn, 
       
  1351 with co-ordinates relative to the top left corner of the bitmap. 
       
  1352 @param aMaskBitmap A window server mask bitmap. 
       
  1353 @param aInvertMask If false, a source pixel that is masked by a black pixel 
       
  1354 is not transferred to the destination rectangle. If true, then a source pixel 
       
  1355 that is masked by a white pixel is not transferred to the destination rectangle. 
       
  1356 
       
  1357 @see CBitmapContext::BitBltMasked() */
       
  1358 	{
       
  1359 	if (aBitmap == NULL || !aBitmap->Handle() || aMaskBitmap == NULL || !aMaskBitmap->Handle())
       
  1360 		return;
       
  1361 	TWsGcCmdBltMasked gdiBlitMasked(aPoint,aBitmap->WsHandle(),aSourceRect,aMaskBitmap->WsHandle(),aInvertMask);
       
  1362 	Write(&gdiBlitMasked,sizeof(gdiBlitMasked),EWsGcOpGdiWsBltMasked);
       
  1363 	AddToBitmapArray(aBitmap->Handle());
       
  1364 	AddToBitmapArray(aMaskBitmap->Handle()); 
       
  1365 	}
       
  1366 
       
  1367 EXPORT_C void CWindowGc::MapColors(const TRect &aRect,const TRgb *aColors,TInt aNumPairs,TBool aMapForwards)
       
  1368 /** Re-maps pixel colours within a rectangle.
       
  1369 
       
  1370 aColors is an array of paired colour values. The rectangle is scanned and 
       
  1371 the colour value of each pixel is looked up in the array, and if found is 
       
  1372 replaced by the value with which it is paired. The arguments specify the rectangle, 
       
  1373 the array of pairs, the number of pairs in the array, and the 'direction' 
       
  1374 of lookup. If no entry is found for the colour value of a given pixel it remains 
       
  1375 unchanged.
       
  1376 
       
  1377 This function was designed for cursor display. A cursor is normally displayed 
       
  1378 as the XOR of the background against which it appears. However in some graphics 
       
  1379 modes, certain colours XOR to very similar shades. MapColors() allows more 
       
  1380 pleasing maps to be specified.
       
  1381 
       
  1382 The effect of this function when applied to transparent pixels when the opaque
       
  1383 flag is set is undefined. See SetOpaque().
       
  1384 @param aRect Rectangle to be mapped. 
       
  1385 @param aColors Array of colour value pairs, one value in a pair is the lookup 
       
  1386 value and the other is the replacement value. 
       
  1387 @param aNumPairs Number of pairs in the array. aColors must have twice this 
       
  1388 number of elements. By default the aColors array is assumed to specify 2 colours 
       
  1389 (i.e. it specifies a single mapping).
       
  1390 @param aMapForwards Direction of lookup. ETrue to map forwards, i.e. treat 
       
  1391 the first value in the pair as the lookup value and the second as the replacement 
       
  1392 value; EFalse does the opposite. */
       
  1393 	{
       
  1394 	if (aNumPairs>16)
       
  1395 		Panic(EW32PanicMapColorsTooManyPairs);
       
  1396 	TWsGcCmdMapColors mapColors(aRect,aNumPairs,aMapForwards);
       
  1397 	Write(&mapColors,sizeof(mapColors),aColors,aNumPairs*sizeof(TRgb)*2,EWsGcOpMapColors);
       
  1398 	}
       
  1399 
       
  1400 EXPORT_C void CWindowGc::Clear(const TRect &aRect)
       
  1401 /** Clears a rectangular area of a window.
       
  1402 
       
  1403 The cleared area is filled with the current brush colour.
       
  1404 
       
  1405 @param aRect The rectangle to clear. 
       
  1406 @see CBitmapContext::Clear() */
       
  1407 	{
       
  1408 	WriteRect(aRect,EWsGcOpClearRect);
       
  1409 	}
       
  1410 
       
  1411 EXPORT_C void CWindowGc::Clear()
       
  1412 /** Clears the whole window.
       
  1413 
       
  1414 The cleared area is filled with the current brush colour.
       
  1415 
       
  1416 @see CBitmapContext::Clear() */
       
  1417 	{
       
  1418 	Write(EWsGcOpClear);
       
  1419 	}
       
  1420 
       
  1421 EXPORT_C void CWindowGc::Reset()
       
  1422 /** Resets the graphics context to its default settings.
       
  1423 
       
  1424 The drawing mode is set to TDrawMode::EDrawModePen (pen and brush colours used as 
       
  1425 they are); there is no clipping rectangle; the pen settings are black, 
       
  1426 solid, single pixel size; the brush style is null; no text font is selected.
       
  1427 
       
  1428 @see CGraphicsContext::Reset() */
       
  1429 	{
       
  1430 	Write(EWsGcOpReset);
       
  1431 	iPimpl->iFont=NULL;
       
  1432 	}
       
  1433 
       
  1434 EXPORT_C void CWindowGc::SetDitherOrigin(const TPoint& aPoint)
       
  1435 /** Sets the origin used for colour dithering.
       
  1436 
       
  1437 @param aPoint New dither origin. */
       
  1438 	{
       
  1439 	Write(&aPoint,sizeof(aPoint),EWsGcOpSetDitherOrigin);
       
  1440 	}
       
  1441 
       
  1442 EXPORT_C void CWindowGc::SetFaded(TBool aFaded)
       
  1443 /** Sets whether the graphics context is faded.
       
  1444 
       
  1445 Fading is used to make a window appear less colourful so that other windows 
       
  1446 stand out. For example, a window would be faded when a dialogue is displayed 
       
  1447 in front of it.
       
  1448 
       
  1449 @param aFaded ETrue to fade the graphics context, EFalse to unfade it. */
       
  1450 	{
       
  1451 	WriteInt(aFaded,EWsGcOpSetFaded);
       
  1452 	}
       
  1453 
       
  1454 EXPORT_C void CWindowGc::SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap)
       
  1455 /** Sets the fading parameters.
       
  1456 
       
  1457 This function allows you to override the map used when drawing with a faded 
       
  1458 graphics context. However if you draw to a faded window with a faded graphics 
       
  1459 context, then fading on the graphics context is ignored and it will use the 
       
  1460 fading of the window.
       
  1461 
       
  1462 Fading is used to make a window appear less colourful so that other windows stand 
       
  1463 out. For example, a window would be faded when a dialogue is displayed 
       
  1464 in front of it. 
       
  1465 
       
  1466 You can either make a faded window closer to white or closer to black. 
       
  1467 The fading map allows you to over-ride the default fading parameters set in 
       
  1468 RWsSession::SetDefaultFadingParameters(). 
       
  1469 
       
  1470 Fading re-maps colours to fall between the specified black and white map values. 
       
  1471 If aBlackMap=0 and aWhiteMap=255 then the colours are mapped unchanged. As the 
       
  1472 values converge, the colours are mapped to a smaller range, so the differences 
       
  1473 between colours in the faded graphics context decrease. If the values are reversed 
       
  1474 then the colours are inverted (i.e. where the gc would be black, it is now white). 
       
  1475 
       
  1476 @param aBlackMap Black map fading parameter. Unfaded this is 0. 
       
  1477 @param aWhiteMap White map fading parameter. Unfaded this is 255. 
       
  1478 @see RWsSession::SetDefaultFadingParameters()
       
  1479 @see RWindowTreeNode::SetFaded() */
       
  1480 	{
       
  1481 	WriteInt(WservEncoding::Encode8BitValues(aBlackMap,aWhiteMap),EWsGcOpSetFadeParams);
       
  1482 	}
       
  1483 
       
  1484 EXPORT_C TInt CWindowGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect,const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
       
  1485 /**
       
  1486 Performs an alpha blending of the source data, aSrcBmp, with the window, using
       
  1487 the data from aAlphaBmp as an alpha blending factor.
       
  1488 The formula used is:
       
  1489 (S * A + W * (255 - A)) / 255, where:
       
  1490 - S - a pixel from aSrcBmp;
       
  1491 - W - a pixel from the window;
       
  1492 - A - a pixel from aAlphaBmp;
       
  1493 The contents of source and alpha bitmap are preserved.
       
  1494 The calculated alpha blended pixels are written to the destination - the window image.
       
  1495 The effect of this function when applied to transparent pixels when the opaque
       
  1496 flag is set is undefined. See SetOpaque().
       
  1497 
       
  1498 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1499 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1500 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1501 stored commands including the draw bitmap.  However, if the client has changed the content of the bitmap,
       
  1502 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1503 
       
  1504 This method is supported from version 8.1
       
  1505 @param aDestPt Position in the target the result should be drawn to.
       
  1506 @param aSrcBmp A pointer to the source bitmap.
       
  1507 @param aSrcRect The part of the source bitmap that should be used.
       
  1508 @param aAlphaBmp A pointer to the bitmap used as an alpha blending factor.
       
  1509 @param aAlphaPt Position of the first pixel in the alpha bitmap that should be used as a source 
       
  1510                 for the alpha blending. The size of the area is the same as the 
       
  1511                 source bitmap area - aSrcRect parameter.
       
  1512 @see CFbsBitGc::AlphaBlendBitmaps()
       
  1513 */
       
  1514 	{
       
  1515 	TWsGcCmdAlphaBlendBitmaps alphaBlend(aDestPt, aSrcBmp->Handle(), aSrcRect, aAlphaBmp->Handle(), aAlphaPt);
       
  1516 	Write(&alphaBlend,sizeof(alphaBlend),EWsGcOpGdiAlphaBlendBitmaps);
       
  1517 	AddToBitmapArray(aSrcBmp->Handle());
       
  1518 	AddToBitmapArray(aAlphaBmp->Handle());
       
  1519 	return KErrNone;
       
  1520 	}
       
  1521 
       
  1522 EXPORT_C TInt CWindowGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CWsBitmap* aSrcBmp, const TRect& aSrcRect,const CWsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
       
  1523 /**
       
  1524 The method performs an alpha blending of the source data, aSrcBmp, with the window, using
       
  1525 the data from aAlphaBmp as an alpha blending factor.
       
  1526 For information on how this function works, see the other overload.
       
  1527 
       
  1528 Windows that store their redraw commands will only store drawing position and a handle to bitmaps 
       
  1529 that are drawn in it. The bitmap handle is just a pointer to the bitmap in the FBSERV heap. 
       
  1530 At some point later WSERV may need to draw that window again and it will just replay the 
       
  1531 stored commands including the draw bitmap. However, if the client has changed the content of the bitmap,
       
  1532 WSERV will effectively draw a different bitmap when it replays the commands.
       
  1533 
       
  1534 This method is supported from version 8.1
       
  1535 @param aDestPt Position in the target the result should be drawn to.
       
  1536 @param aSrcBmp A pointer to the source bitmap.
       
  1537 @param aSrcRect The part of the source bitmap that should be used.
       
  1538 @param aAlphaBmp A pointer to the bitmap used as an alpha blending factor.
       
  1539 @param aAlphaPt Position of the first pixel in the alpha bitmap that should be used as a source 
       
  1540                 for the alpha blending. The size of the area is the same as the 
       
  1541                 source bitmap area - aSrcRect parameter.
       
  1542 @see CFbsBitGc::AlphaBlendBitmaps()
       
  1543 */
       
  1544 	{
       
  1545 	TWsGcCmdAlphaBlendBitmaps alphaBlend(aDestPt, aSrcBmp->WsHandle(), aSrcRect, aAlphaBmp->WsHandle(), aAlphaPt);
       
  1546 	Write(&alphaBlend,sizeof(alphaBlend),EWsGcOpGdiWsAlphaBlendBitmaps);
       
  1547 	AddToBitmapArray(aSrcBmp->Handle());
       
  1548 	AddToBitmapArray(aAlphaBmp->Handle());
       
  1549 	return KErrNone;
       
  1550 	}
       
  1551 
       
  1552 EXPORT_C void CWindowGc::SetOpaque(TBool aDrawOpaque)
       
  1553 /**
       
  1554 Sets and unsets an opaque flag on the window.  When drawing to a transparent window with the
       
  1555 opaque flag set, drawing commands will not appear transparent.  When drawing to a non-transparent
       
  1556 window this command has no effect.
       
  1557 The result of non-opaque drawing performed over the top of an area of the window to which opaque
       
  1558 drawing has already been done is undefined.
       
  1559 The result of opaque alpha blending or color mapping over the top of an area of the window to
       
  1560 which opaque drawing has not already been done is undefined.
       
  1561 This method is supported from version 8.1
       
  1562 @param aDrawOpaque If true, opaque mode is switched on. If false, normal drawing will be used.
       
  1563 */
       
  1564 	{
       
  1565 	WriteInt(aDrawOpaque, EWsGcOpSetOpaque);
       
  1566 	}
       
  1567 
       
  1568 /** APIExtension can contain as many additional methods as is required by 
       
  1569 CGraphicsContext after its original conception. It takes 3 parameters.
       
  1570 Function is exported due to constrains of retaining BC with earlier versions.
       
  1571 This is not used directly by external methods, instead it is called by a named 
       
  1572 method in CGraphicsContext which passes the relivant arguements including an 
       
  1573 unique identifier for the required action.
       
  1574 @param aUid The unique identifier for the method that is required. Selected 
       
  1575 internally by a series of "if" statements. 
       
  1576 @see Valid Uid identifiers are listed in header gdi.h
       
  1577 @see CGraphicsContext
       
  1578 @param aOutput is a TAny pointer to a reference. Used to output data as the structure
       
  1579 does not need to be instantiated before the function call this adds greater 
       
  1580 flexibility.
       
  1581 @param aInput is a TAny pointer used to input data.
       
  1582 */	
       
  1583 EXPORT_C TInt CWindowGc::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput)
       
  1584 	{
       
  1585 	if (aUid == KGetUnderlineMetrics)
       
  1586 		{		
       
  1587 		APIExGetUnderlineMetrics(aOutput);
       
  1588 		return KErrNone;	
       
  1589 		}
       
  1590 	else if (aUid == KSetShadowColor)
       
  1591 		{
       
  1592 		return APIExSetShadowColor(aInput);
       
  1593 		}
       
  1594 	/* Future cases may be placed here later.*/
       
  1595 	else
       
  1596 		return CBitmapContext::APIExtension(aUid, aOutput, aInput);
       
  1597 	}
       
  1598 
       
  1599 //The methods listed above in APIExtension follow here with the prefix APIEx.
       
  1600 TInt CWindowGc::APIExGetUnderlineMetrics(TAny*& aOutput)
       
  1601 	{
       
  1602 	const TInt width = Max(iPimpl->iFont->HeightInPixels() / 10,1);
       
  1603 	TTwoTInt* ptr = (TTwoTInt*)aOutput;
       
  1604 	ptr->iTop = 1 + width / 2;
       
  1605 	ptr->iBottom = (ptr->iTop) + width;
       
  1606 	return KErrNone;
       
  1607 	}
       
  1608 
       
  1609 TInt CWindowGc::APIExSetShadowColor(TAny* aShadowColor)
       
  1610 	{
       
  1611 	const TRgb shadowColor = *(reinterpret_cast<TRgb*> (aShadowColor));
       
  1612 	WriteInt(shadowColor.Internal(), EWsGcOpSetShadowColor);
       
  1613 	return KErrNone;
       
  1614 	}
       
  1615 
       
  1616 //Default implementation of reserved virtual
       
  1617 EXPORT_C void CWindowGc::Reserved_CGraphicsContext_2()
       
  1618 	{
       
  1619 	CBitmapContext::Reserved_CGraphicsContext_2();
       
  1620 	}
       
  1621 
       
  1622 //Default implementation of reserved virtual
       
  1623 EXPORT_C void CWindowGc::Reserved_CBitmapContext_1()
       
  1624 	{
       
  1625 	CBitmapContext::Reserved_CBitmapContext_1();
       
  1626 	}
       
  1627 
       
  1628 //Default implementation of reserved virtual
       
  1629 EXPORT_C void CWindowGc::Reserved_CBitmapContext_2()
       
  1630 	{
       
  1631 	CBitmapContext::Reserved_CBitmapContext_2();
       
  1632 	}
       
  1633 
       
  1634 //Default implementation of reserved virtual
       
  1635 EXPORT_C void CWindowGc::Reserved_CBitmapContext_3()
       
  1636 	{
       
  1637 	CBitmapContext::Reserved_CBitmapContext_3();
       
  1638 	}
       
  1639 	
       
  1640 // was Reserved_CWindowGc_1
       
  1641 EXPORT_C void CWindowGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect)
       
  1642 /** Draws an abstract artwork.
       
  1643 It does nothing if aDestRect values fall outside the window area.
       
  1644 
       
  1645 @param aId the identifier for the artwork
       
  1646 @param aDestRect the destination rect within the active window for this artwork
       
  1647 
       
  1648 @since 9.2
       
  1649 @released
       
  1650 */
       
  1651 	{
       
  1652 	TWsGcCmdDrawWsGraphic drawWsGraphic(aId,aDestRect);
       
  1653 	Write(&drawWsGraphic,sizeof(drawWsGraphic),EWsGcOpDrawWsGraphic);
       
  1654 	}
       
  1655 
       
  1656 // Reserved_CWindowGc_2
       
  1657 EXPORT_C void CWindowGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect,const TDesC8& aData)
       
  1658 /** Draws an abstract artwork.
       
  1659 It does nothing if aDestRect values fall outside the window area.
       
  1660 
       
  1661 @param aId the identifier for the artwork
       
  1662 @param aDestRect the destination rect within the active window for this artwork
       
  1663 @param aData opaque datagram to associate with this occasion of drawing.  The format is dependent upon the artwork
       
  1664 
       
  1665 @since 9.2
       
  1666 @released
       
  1667 */
       
  1668 	{
       
  1669 	TWsGcCmdDrawWsGraphic drawWsGraphic(aId,aDestRect);
       
  1670 	drawWsGraphic.iDataLen = aData.Size();
       
  1671 	WriteTextCommand(&drawWsGraphic, sizeof(drawWsGraphic),	aData, EWsGcOpDrawWsGraphic, EWsGcOpDrawWsGraphicPtr);	
       
  1672 	}
       
  1673 
       
  1674 /** @internalComponent */
       
  1675 EXPORT_C TAny* CWindowGc::Interface(TUid /*aInterfaceId*/)
       
  1676 	{
       
  1677 	return NULL; //currently no interface supported
       
  1678 	}
       
  1679 
       
  1680 /** @internalComponent */
       
  1681 EXPORT_C const TAny* CWindowGc::Interface(TUid /*aInterfaceId*/) const
       
  1682 	{
       
  1683 	return NULL; //currently no interface supported
       
  1684 	}
       
  1685 
       
  1686 //Default implementation of reserved virtual
       
  1687 EXPORT_C void CWindowGc::Reserved_CWindowGc_3()
       
  1688 	{
       
  1689 	}
       
  1690 
       
  1691 //Default implementation of reserved virtual
       
  1692 EXPORT_C void CWindowGc::Reserved_CWindowGc_4()
       
  1693 	{
       
  1694 	}
       
  1695 
       
  1696 //Default implementation of reserved virtual
       
  1697 EXPORT_C void CWindowGc::Reserved_CWindowGc_5()
       
  1698 	{
       
  1699 	}
       
  1700 
       
  1701 //The class is designed to be used for resource drawing; however this functionality is only supported in NGA architecture. 
       
  1702 //We have to provide an empty implementation here to avoid compilation errors.
       
  1703 EXPORT_C RWsDrawableSource::RWsDrawableSource()
       
  1704 	{
       
  1705 	}
       
  1706 
       
  1707 EXPORT_C RWsDrawableSource::RWsDrawableSource(RWsSession&)
       
  1708 	{
       
  1709 	}
       
  1710 
       
  1711 EXPORT_C TInt RWsDrawableSource::Create(const RSgDrawable&)
       
  1712 	{
       
  1713 	return KErrNotSupported;
       
  1714 	}
       
  1715 
       
  1716 EXPORT_C TInt RWsDrawableSource::Create(const RSgDrawable&, TInt)
       
  1717 	{
       
  1718 	return KErrNotSupported;
       
  1719 	}
       
  1720 
       
  1721 EXPORT_C const TSgDrawableId& RWsDrawableSource::DrawableId() const
       
  1722 	{
       
  1723 	return KSgNullDrawableId;
       
  1724 	}
       
  1725 
       
  1726 EXPORT_C TInt RWsDrawableSource::ScreenNumber() const
       
  1727 	{
       
  1728 	return KSgScreenIdMain;
       
  1729 	}
       
  1730 
       
  1731 EXPORT_C void RWsDrawableSource::Close()
       
  1732 	{
       
  1733 	}
       
  1734