windowing/windowserver/nga/CLIENT/RSCRDEV.CPP
changeset 0 5d03bc08d59c
child 18 5e30ef2e26cb
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1995-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 screen device
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32hal.h>
       
    20 #include "../SERVER/w32cmd.h"
       
    21 #include "CLIENT.H"
       
    22 #include "w32comm.h"
       
    23 #include "scrdevextension.h"
       
    24 
       
    25 const TInt KDefaultScreenNumber = 0 ;
       
    26 
       
    27 EXPORT_C CWsScreenDevice::CWsScreenDevice()
       
    28 /** Default constructor. Developers should use the other constructor overload. */
       
    29 	{
       
    30 	}
       
    31 
       
    32 EXPORT_C CWsScreenDevice::CWsScreenDevice(RWsSession &aWs) : MWsClientClass(aWs.iBuffer)
       
    33 /** Constructs a new screen device attached to a particular window server session.
       
    34 
       
    35 @param aWs The window server session this screen should be attached to. */
       
    36 	{
       
    37 	}
       
    38 
       
    39 /** Interface Extension capability
       
    40 	Use of this interface going forward will allow the published client interface to be dynamically extended.
       
    41 	Note that the pointer returned is only good for the lifetime of the called CBase derived object.
       
    42 
       
    43 	@param  aInterfaceId	uniqueid or well known id of interface
       
    44 	@return	pointer to interface object matching this ID or NULL if no match.
       
    45 */
       
    46 EXPORT_C TAny* CWsScreenDevice::GetInterface(TUint aInterfaceId)
       
    47 	{
       
    48 	return iExtension->GetInterface(aInterfaceId);
       
    49 	}
       
    50 
       
    51 /** Returns whether the given screen size mode is dynamic or not.
       
    52 	Dynamic screen size modes may change their size in pixels and/or twips 
       
    53 	and other attributes at run time, so they must not be cached. Static size 
       
    54 	mode attributes will not change at run time, but may not make full use of the display.
       
    55 	Invalid size modes shall return EFalse.
       
    56 
       
    57 	@param aSizeMode The screen size mode to check.
       
    58 	@return ETrue if the given screen size mode is dynamic, EFalse otherwise.
       
    59 */
       
    60 EXPORT_C TBool CWsScreenDevice::IsModeDynamic(TInt aSizeMode) const 
       
    61 	{
       
    62 	if (aSizeMode < 0)
       
    63 		{
       
    64 		return EFalse;
       
    65 		}
       
    66 	return((TBool)WriteReply(&aSizeMode, sizeof(aSizeMode), EWsSdOpIsScreenModeDynamic));
       
    67 	}
       
    68 
       
    69 /** Returns whether the current screen size mode is dynamic or not.
       
    70 
       
    71 	@return ETrue if current screen size mode is dynamic, EFalse otherwise.
       
    72 	@see IsModeDynamic
       
    73 */
       
    74 EXPORT_C TBool CWsScreenDevice::IsCurrentModeDynamic() const 
       
    75 	{
       
    76 	const TInt KCurrentMode = -1; 
       
    77 	return((TBool)WriteReply(&KCurrentMode, sizeof(KCurrentMode), EWsSdOpIsScreenModeDynamic));
       
    78 	}
       
    79 
       
    80 EXPORT_C TInt CWsScreenDevice::CreateContext(CGraphicsContext *&aGc)
       
    81 /** Creates a graphics context for this device.
       
    82 
       
    83 This function always causes a flush of the window server buffer.
       
    84 
       
    85 @param aGc On successful return, contains a new graphics context referring 
       
    86 to this screen device. 
       
    87 @return KErrNone if successful, otherwise one of the system-wide error codes. 
       
    88 @see CGraphicsDevice::CreateContext() */
       
    89 	{
       
    90 	if ((aGc=new CWindowGc(this))==NULL)
       
    91 		return(KErrNoMemory);
       
    92 	TInt err=((CWindowGc *)aGc)->Construct();
       
    93 	if (err!=KErrNone)
       
    94 		{
       
    95 		delete aGc;
       
    96 		aGc=NULL;
       
    97 		}
       
    98 	return(err);
       
    99 	}
       
   100 
       
   101 EXPORT_C CWsScreenDevice::~CWsScreenDevice()
       
   102 /** Destructor. */
       
   103 	{
       
   104 	if (iBuffer)
       
   105 		{
       
   106 		if (iWsHandle)
       
   107 			Write(EWsSdOpFree);
       
   108 		}
       
   109 	if (iExtension)
       
   110 		{
       
   111 		delete TypeFaceStore();
       
   112 		delete iExtension;
       
   113 		}
       
   114 	}
       
   115 
       
   116 #pragma warning(disable : 4710)
       
   117 /** 
       
   118 Completes construction of the object.
       
   119 
       
   120 This method invokes Construct(TInt aDefaultScreenNumber) with default Screen number.
       
   121 @return KErrNone if successful, otherwise another of the system-wide error codes. 
       
   122 */
       
   123 EXPORT_C TInt CWsScreenDevice::Construct()
       
   124 	{
       
   125 	return Construct( KDefaultScreenNumber ) ;
       
   126 	}
       
   127 
       
   128 
       
   129 EXPORT_C TInt CWsScreenDevice::Construct(TInt aDefaultScreenNumber)
       
   130 /** Completes construction of the object.
       
   131 
       
   132 This function always causes a flush of the window server buffer.
       
   133 @param aDefaultScreenNumber - This is the screen on which an application will start
       
   134 @return KErrNone if successful, otherwise another of the system-wide error 
       
   135 codes. 
       
   136 @panic TW32Panic 17 in debug builds if called on an already constructed object.*/
       
   137 	{
       
   138 	__ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction));
       
   139 	TInt ret;
       
   140 	TWsClCmdCreateScreenDevice createScreenDevice;
       
   141 	createScreenDevice.screenNumber = aDefaultScreenNumber;
       
   142 	createScreenDevice.clientScreenDevicePointer = (TUint)this;
       
   143 	if ( ( ret=iBuffer->WriteReplyWs(&createScreenDevice,sizeof(createScreenDevice),EWsClOpCreateScreenDevice ) ) < 0 )
       
   144 		iBuffer=NULL;
       
   145 	else
       
   146 		{
       
   147 		iWsHandle=ret;
       
   148 		//If the extension fails to allocate then clients will be refused access to the extension interface.
       
   149 		TRAP(ret,iExtension=new(ELeave) CScrDevExtension(iBuffer,iWsHandle));
       
   150 		if (ret>=KErrNone)
       
   151 			{
       
   152 			TRAP(ret,iExtension->SetTypefaceStore(CFbsTypefaceStore::NewL(this)));
       
   153 			}
       
   154 		if (IsCurrentModeDynamic())
       
   155 			{
       
   156 			iDisplaySizeInPixels=TSize(-1,-1);
       
   157 			iPhysicalScreenSizeInTwips=TSize(-1,-1);
       
   158 			
       
   159 			}
       
   160 		else
       
   161 			{
       
   162 			iDisplaySizeInPixels=SizeInPixels();
       
   163 			iPhysicalScreenSizeInTwips=SizeInTwips();
       
   164 			}
       
   165 		if (iDisplaySizeInPixels.iWidth==0)
       
   166 			{
       
   167 			TMachineInfoV1Buf macInfo;
       
   168 			UserHal::MachineInfo(macInfo);
       
   169 			iPhysicalScreenSizeInTwips=macInfo().iPhysicalScreenSize;
       
   170 			iDisplaySizeInPixels=macInfo().iDisplaySizeInPixels;
       
   171 			}
       
   172 		}
       
   173 	return(ret);
       
   174 	}
       
   175 #pragma warning(default : 4710)
       
   176 
       
   177 EXPORT_C TDisplayMode CWsScreenDevice::DisplayMode() const
       
   178 /** Gets the device's display mode.
       
   179 
       
   180 This function always causes a flush of the window server buffer.
       
   181 
       
   182 @return The device's display mode. 
       
   183 @see CGraphicsDevice::DisplayMode() */
       
   184 	{
       
   185 	return((TDisplayMode)WriteReply(EWsSdOpDisplayMode));
       
   186 	}
       
   187 
       
   188 EXPORT_C TRect CWsScreenDevice::PointerRect() const
       
   189 /** Gets the active area for the pointing device. 
       
   190 
       
   191 This is a device-dependent parameter, and will typically depend on the screen 
       
   192 size and other factors.
       
   193 
       
   194 This function always causes a flush of the window server buffer.
       
   195 
       
   196 @return The active area, measured in pixels. */
       
   197 	{
       
   198 	TPckgBuf<TRect> rectPkg;
       
   199   	WriteReplyP(&rectPkg,EWsSdOpPointerRect);
       
   200 	return(rectPkg());
       
   201 	}
       
   202 
       
   203 EXPORT_C TSize CWsScreenDevice::SizeInPixels() const
       
   204 /** Gets the size of the screen device area in pixels.
       
   205 
       
   206 This function always causes a flush of the window server buffer.
       
   207 
       
   208 @return The x and y dimensions of the screen device area, in pixels. 
       
   209 @see CGraphicsDevice::SizeInPixels() */
       
   210 	{
       
   211 	TPckgBuf<TSize> sizePkg;
       
   212   	WriteReplyP(&sizePkg,EWsSdOpPixelSize);
       
   213 	return(sizePkg());
       
   214 	}
       
   215 
       
   216 EXPORT_C TSize CWsScreenDevice::SizeInTwips() const
       
   217 /** Gets the size of the screen device area in twips.
       
   218 
       
   219 This function always causes a flush of the window server buffer.
       
   220 
       
   221 @return The x and y dimensions of the screen device area, in twips. 
       
   222 @see CGraphicsDevice::SizeInTwips() */
       
   223 	{
       
   224 	TPckgBuf<TSize> sizePkg;
       
   225   	WriteReplyP(&sizePkg,EWsSdOpTwipsSize);
       
   226 	return(sizePkg());
       
   227 	}
       
   228 
       
   229 TSize CWsScreenDevice::DisplaySizeInPixels() const
       
   230 	{
       
   231 	if (iDisplaySizeInPixels == TSize(-1,-1))
       
   232 		{
       
   233 		return SizeInPixels();
       
   234 		}
       
   235 	return iDisplaySizeInPixels;
       
   236 	}
       
   237 
       
   238 TSize CWsScreenDevice::PhysicalScreenSizeInTwips() const
       
   239 	{
       
   240 	if (iPhysicalScreenSizeInTwips == TSize(-1,-1))
       
   241 		{
       
   242 		return SizeInTwips();
       
   243 		}
       
   244 	return iPhysicalScreenSizeInTwips;
       
   245 	}
       
   246 
       
   247 EXPORT_C TInt CWsScreenDevice::HorizontalTwipsToPixels(TInt aTwips) const
       
   248 /** Translates a twips to a pixel value.
       
   249 
       
   250 @param aTwips The value in twips. 
       
   251 @return The equivalent number of pixels. 
       
   252 @see MGraphicsDeviceMap::HorizontalTwipsToPixels() */
       
   253 	{
       
   254 	TInt64 twips=aTwips;
       
   255 	TSize displaySizeInPixels = DisplaySizeInPixels();
       
   256 	TSize physicalScreenSizeInTwips = PhysicalScreenSizeInTwips();
       
   257 	twips=(twips*displaySizeInPixels.iWidth+(physicalScreenSizeInTwips.iWidth/2))/physicalScreenSizeInTwips.iWidth;
       
   258 	return I64INT(twips);
       
   259 	}
       
   260 
       
   261 EXPORT_C TInt CWsScreenDevice::VerticalTwipsToPixels(TInt aTwips) const
       
   262 /** Translates a vertical dimension of a screen device in twips into pixels.
       
   263 
       
   264 @param aTwips A vertical dimension of a device in twips. 
       
   265 @return The vertical dimension in pixels. */
       
   266 	{
       
   267 	TInt64 twips=aTwips;
       
   268 	TSize displaySizeInPixels = DisplaySizeInPixels();
       
   269 	TSize physicalScreenSizeInTwips = PhysicalScreenSizeInTwips();
       
   270 	twips=(twips*displaySizeInPixels.iHeight+(physicalScreenSizeInTwips.iHeight/2))/physicalScreenSizeInTwips.iHeight;
       
   271 	return I64INT(twips);
       
   272 	}
       
   273 
       
   274 EXPORT_C TInt CWsScreenDevice::HorizontalPixelsToTwips(TInt aPixels) const
       
   275 /** Translates a specified pixel value to a twips value. 
       
   276 
       
   277 @param aPixels The value in pixels to be translated. 
       
   278 @return The equivalent number of twips. */
       
   279 	{
       
   280 	TInt64 pixels=aPixels;
       
   281 	TSize displaySizeInPixels = DisplaySizeInPixels();
       
   282 	TSize physicalScreenSizeInTwips = PhysicalScreenSizeInTwips();
       
   283 	pixels=(pixels*physicalScreenSizeInTwips.iWidth+(displaySizeInPixels.iWidth/2))/displaySizeInPixels.iWidth;
       
   284 	return I64INT(pixels);
       
   285 	}
       
   286 
       
   287 EXPORT_C TInt CWsScreenDevice::VerticalPixelsToTwips(TInt aPixels) const
       
   288 /** Translates a vertical dimension of a screen device in pixels into twips.
       
   289 
       
   290 @param aPixels A vertical dimension of a device in pixels. 
       
   291 @return The vertical dimension in twips. 
       
   292 @see MGraphicsDeviceMap::VerticalPixelsToTwips() */
       
   293 	{
       
   294 	TInt64 pixels=aPixels;
       
   295 	TSize displaySizeInPixels = DisplaySizeInPixels();
       
   296 	TSize physicalScreenSizeInTwips = PhysicalScreenSizeInTwips();
       
   297 	pixels=(pixels*physicalScreenSizeInTwips.iHeight+(displaySizeInPixels.iHeight/2))/displaySizeInPixels.iHeight;
       
   298 	return I64INT(pixels);
       
   299 	}
       
   300 
       
   301 EXPORT_C void CWsScreenDevice::GetPixel(TRgb &aColor,const TPoint &aPixel) const
       
   302 /** Gets the RGB colour of an individual pixel on a screen device.
       
   303 
       
   304 This function always causes a flush of the window server buffer.
       
   305 
       
   306 @param aColor On return, contains the RGB colour of the pixel. 
       
   307 @param aPixel The x,y co-ordinates of the pixel. The top left pixel is (0,0).
       
   308 @see CBitmapDevice::GetPixel() */
       
   309 	{
       
   310 	aColor.SetInternal(((TUint32)WriteReply(&aPixel,sizeof(aPixel),EWsSdOpPixel)));
       
   311 	}
       
   312 
       
   313 EXPORT_C void CWsScreenDevice::GetScanLine(TDes8 &aScanLine,const TPoint &aStartPixel,TInt aPixelLength, TDisplayMode aDispMode) const
       
   314 /** Gets a scanline into a buffer. 
       
   315 
       
   316 The pixels are converted from the bitmapped graphics device display mode format 
       
   317 to the format of the specified device display mode.
       
   318 
       
   319 By specifying the start pixel and number of pixels either the whole or a portion 
       
   320 of a bitmapped graphics device pixel row may be copied.
       
   321 
       
   322 This function always causes a flush of the window server buffer.
       
   323 
       
   324 @param aScanLine A buffer into which pixels are copied, it must be sufficiently 
       
   325 large to store all the scanline pixels. 
       
   326 @param aStartPixel The (x,y) co-ordinates of the first pixel of the bitmap scanline 
       
   327 to be put into the buffer. 
       
   328 @param aPixelLength The number of pixels to put into the buffer.
       
   329 @param aDispMode The display mode into which to convert the pixels. 
       
   330 @see CBitmapDevice::GetScanLine() */
       
   331 	{
       
   332 	TWsSdCmdGetScanLine getScanLine(aStartPixel,aPixelLength,aDispMode);
       
   333 	WriteReplyP(&getScanLine,sizeof(getScanLine),&aScanLine,EWsSdOpGetScanLine);
       
   334 	}
       
   335 
       
   336 EXPORT_C TBool CWsScreenDevice::RectCompare(const TRect &aRect1,const TRect &aRect2) const
       
   337 /** Compares two areas of the screen to see if they have the same content. 
       
   338 
       
   339 If there are any sprites on the screen they are not included in the comparison.
       
   340 
       
   341 This function always causes a flush of the window server buffer.
       
   342 
       
   343 @param aRect1 A rectangle. 
       
   344 @param aRect2 Another rectangle. 
       
   345 @return ETrue if the two screen areas are identical. */
       
   346  	{
       
   347 	return RectCompare(aRect1,aRect2,ERemoveSprite);
       
   348 	}
       
   349 
       
   350 EXPORT_C TBool CWsScreenDevice::RectCompare(const TRect &aRect1,const TRect &aRect2,TUint aFlags) const
       
   351 /** Compares two areas of the screen to see if they have the same content.
       
   352  
       
   353 This function always causes a flush of the window server buffer.
       
   354 
       
   355 @param aRect1 A rectangle. 
       
   356 @param aRect2 Another rectangle.
       
   357 @param aFlags EIncludeSprite to include any visible sprites in the comparison, ERemoveSprite to remove the sprites,
       
   358 or EIncludeTextCursor to include any visible text cursors in the comparison. EIncludeSprite and EIncludeTextCursor 
       
   359 can be combined (logically ORed) to include both visible sprites and visible text cursors in the comparison. These 
       
   360 values are defined in the enum TSpriteInCompare in this class.
       
   361 @return ETrue if the two screen areas are identical. */
       
   362 	{
       
   363 	TWsSdCmdRectCompare rectCompare(aRect1,aRect2,aFlags);
       
   364  	return(WriteReply(&rectCompare,sizeof(rectCompare),EWsSdOpRectCompare));
       
   365  	}
       
   366 
       
   367 EXPORT_C TInt CWsScreenDevice::CopyScreenToBitmap(const CFbsBitmap *aBitmap) const
       
   368 /** Saves the entire screen to a bitmap.
       
   369 
       
   370 This function always causes a flush of the window server buffer.
       
   371 
       
   372 @param aBitmap Bitmap to be filled with the screen image. 
       
   373 @return KErrNone if successful, otherwise one of the system-wide error codes. */
       
   374 	{
       
   375 	AddToBitmapArray(aBitmap->Handle());
       
   376 	TWsSdCmdCopyScreenToBitmap rectCompare(aBitmap->Handle());
       
   377 	return(WriteReply(&rectCompare,sizeof(rectCompare),EWsSdOpCopyScreenToBitmap));
       
   378 	}
       
   379 
       
   380 EXPORT_C TInt CWsScreenDevice::CopyScreenToBitmap(const CFbsBitmap *aBitmap, const TRect &aRect) const
       
   381 /** Saves a region of the screen to a bitmap.
       
   382 
       
   383 This function always causes a flush of the window server buffer.
       
   384 
       
   385 @param aBitmap Bitmap to be filled with the screen region image. 
       
   386 @param aRect Screen region to be saved. 
       
   387 @return KErrNone if successful, otherwise one of the system-wide error codes. */
       
   388 	{
       
   389 	AddToBitmapArray(aBitmap->Handle());
       
   390 	TWsSdCmdCopyScreenToBitmap2 rectCompare(aRect, aBitmap->Handle());
       
   391 	return(WriteReply(&rectCompare,sizeof(rectCompare),EWsSdOpCopyScreenToBitmap2));
       
   392 	}
       
   393 
       
   394 EXPORT_C TInt CWsScreenDevice::GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec)
       
   395 /** Gets the nearest font, in twips, to that in the specified font specification. 
       
   396 
       
   397 This function is replaced by GetNearestFontToDesignHeightInTwips()
       
   398 
       
   399 The font and bitmap server returns a pointer to the nearest matching font 
       
   400 from those available, in aFont.
       
   401 
       
   402 @param aFont On return, this is set to point to the device font closest to the font 
       
   403 specification passed in the second argument.
       
   404 @param aFontSpec An absolute font specification. 
       
   405 @return KErrNone if successful, otherwise another of the system-wide error 
       
   406 codes. 
       
   407 @see MGraphicsDeviceMap::GetNearestFontInTwips()
       
   408 @deprecated */
       
   409 	{
       
   410 	return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
       
   411 	}
       
   412 CFbsTypefaceStore* CWsScreenDevice::TypeFaceStore()const
       
   413 /** Helper member fn to access the movable typeface store.
       
   414  **/
       
   415 	{
       
   416 	return iExtension->TypefaceStore();
       
   417 	}
       
   418 
       
   419 
       
   420 EXPORT_C TInt CWsScreenDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont,const TFontSpec& aFontSpec)
       
   421 /** Gets the nearest font in twips to that specified.
       
   422 
       
   423 The font and bitmap server returns a pointer to the nearest matching font 
       
   424 from those available. Matches to design height of font - this gives no
       
   425 guarantees on the actual physical size of the font.
       
   426 
       
   427 This function replaces GetNearestFontInTwips
       
   428 
       
   429 @param aFont On return, the pointer is set to point to the device font which 
       
   430 most closely approximates to the required font specification.
       
   431 @param aFontSpec An absolute font specification. 
       
   432 @return KErrNone, if successful; otherwise, another of the system-wide error 
       
   433 codes.
       
   434 @see MGraphicsDeviceMap::GetNearestFontToDesignHeightInTwips() */
       
   435 	{
       
   436 	return TypeFaceStore()->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
       
   437 	}
       
   438 
       
   439 /** Gets the nearest font, in twips, to that specified. 
       
   440 
       
   441 The font and bitmap server returns a pointer to the nearest matching font 
       
   442 from those available. Matches to max height of font - this does its best 
       
   443 to return a font that will fit within the maximum height specified (but 
       
   444 note that variations due to hinting algorithms may rarely result in this 
       
   445 height being exceeded by up to one pixel). Problems can also be 
       
   446 encountered with bitmap fonts where the typeface exists but doesn't have 
       
   447 a font small enough.
       
   448 
       
   449 @param aFont On return, the pointer is set to point to the device font which 
       
   450 most closely approximates to the required font specification.
       
   451 @param aFontSpec An absolute font specification. 
       
   452 @param aMaxHeight The maximum height within which the font must fit - this
       
   453 overrides the height specified in the TFontSpec. If maximum height
       
   454 is greater than 1024 pixels, the function returns KErrTooBig. And returns 
       
   455 KErrArgument if equals to 1 pixel.
       
   456 @return KErrNone, if successful; otherwise, another of the system-wide error 
       
   457 codes.
       
   458 @see MGraphicsDeviceMap::GetNearestFontToMaxHeightInTwips() */
       
   459 EXPORT_C TInt CWsScreenDevice::GetNearestFontToMaxHeightInTwips(CFont*& aFont,const TFontSpec& aFontSpec,TInt aMaxHeight)
       
   460 	{
       
   461 	return TypeFaceStore()->GetNearestFontToMaxHeightInTwips(aFont, aFontSpec, aMaxHeight);
       
   462 	}
       
   463 
       
   464 EXPORT_C TInt CWsScreenDevice::GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec)
       
   465 /** Gets the nearest font to that specified for use by a bitmapped graphics device. 
       
   466 
       
   467 This function is replaced by GetNearestFontToDesignHeightInPixels()
       
   468 
       
   469 The font and bitmap server returns a pointer to the nearest matching font 
       
   470 from those available, in aFont.
       
   471 
       
   472 @param aFont On return, this is set to point to the device font that is  
       
   473 closest to the font specification passed in the second argument 
       
   474 @param aFontSpec An absolute font specification 
       
   475 @return KErrNone if successful, otherwise another of the system-wide error 
       
   476 codes. 
       
   477 @see CBitmapDevice::GetNearestFontInPixels()
       
   478 @deprecated */
       
   479 	{
       
   480 	return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
       
   481 	}
       
   482 
       
   483 EXPORT_C TInt CWsScreenDevice::GetNearestFontToDesignHeightInPixels(CFont*& aFont,const TFontSpec& aFontSpec)
       
   484 /** Gets the nearest font in pixels to that specified. 
       
   485 
       
   486 The font and bitmap server returns a pointer to the nearest matching font 
       
   487 from those available. Matches to design height of font - this gives no
       
   488 guarantees on the actual physical size of the font.
       
   489 
       
   490 This function replaces GetNearestFontInTwips
       
   491 
       
   492 @param aFont On return, the pointer is set to point to the device font which 
       
   493 most closely approximates to the required font specification.
       
   494 @param aFontSpec An absolute font specification. 
       
   495 @return KErrNone, if successful; otherwise, another of the system-wide error 
       
   496 codes.
       
   497 @see CBitmapDevice::GetNearestFontToDesignHeightInPixels() */
       
   498 	{
       
   499 	return TypeFaceStore()->GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
       
   500 	}
       
   501 
       
   502 /** Gets the nearest font in pixels to that specified. 
       
   503 
       
   504 The font and bitmap server returns a pointer to the nearest matching font 
       
   505 from those available. Matches to max height of font - this does its best 
       
   506 to return a font that will fit within the maximum height specified (but 
       
   507 note that variations due to hinting algorithms may rarely result in this 
       
   508 height being exceeded by up to one pixel). Problems can also be 
       
   509 encountered with bitmap fonts where the typeface exists but doesn't have 
       
   510 a font small enough.
       
   511 
       
   512 @param aFont On return, the pointer is set to point to the device font which 
       
   513 most closely approximates to the required font specification.
       
   514 @param aFontSpec An absolute font specification. 
       
   515 @param aMaxHeight The maximum height within which the font must fit - this
       
   516 overrides the height specified in the TFontSpec. If maximum height
       
   517 is greater than 1024 pixels, the function returns KErrTooBig. And returns 
       
   518 KErrArgument if equals to 1 pixel.
       
   519 @return KErrNone, if successful; otherwise, another of the system-wide error 
       
   520 codes.
       
   521 @see CBitmapDevice::GetNearestFontToMaxHeightInPixels() */
       
   522 EXPORT_C TInt CWsScreenDevice::GetNearestFontToMaxHeightInPixels(CFont*& aFont,const TFontSpec& aFontSpec,TInt aMaxHeight)
       
   523 	{
       
   524 	return TypeFaceStore()->GetNearestFontToMaxHeightInPixels(aFont, aFontSpec, aMaxHeight);
       
   525 	}
       
   526 
       
   527 EXPORT_C TInt CWsScreenDevice::NumTypefaces() const
       
   528 /** Gets the number of typefaces supported by the screen device.
       
   529 
       
   530 @return The number of typefaces supported. 
       
   531 @see CGraphicsDevice::NumTypefaces() */
       
   532 	{
       
   533 	return(TypeFaceStore()->NumTypefaces());
       
   534 	}
       
   535 
       
   536 EXPORT_C void CWsScreenDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
       
   537 /** Gets typeface information for a particular typeface index number.
       
   538 
       
   539 This information is returned in aTypefaceSupport, and includes: the typeface 
       
   540 name and typeface attributes (in a TTypeface object), the number of font heights, 
       
   541 the maximum and minimum font heights and whether it is a scalable typeface.
       
   542 
       
   543 @param aTypefaceSupport On return, if the function executed successfully, 
       
   544 this contains the typeface information.
       
   545 @param aTypefaceIndex A typeface index number, in the range zero to (NumTypefaces() 
       
   546 - 1). 
       
   547 @see CGraphicsDevice::TypefaceSupport() */
       
   548 	{
       
   549 	TypeFaceStore()->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);
       
   550 	}
       
   551 
       
   552 EXPORT_C TInt CWsScreenDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
       
   553 /** Gets the height in twips of the specified font. 
       
   554 
       
   555 The value returned is rounded up or down to the nearest font height in twips.
       
   556 
       
   557 The specified font is the one with height index number aHeightIndex of the 
       
   558 typeface with index number aTypefaceIndex.
       
   559 
       
   560 @param aTypefaceIndex A typeface index number, in the range: 0 to (NumTypefaces() - 1). 
       
   561 @param aHeightIndex A font height index number, in the range: 0 to (iNumHeights - 1). 
       
   562 @return The height of the font in twips. 
       
   563 @see CGraphicsDevice::FontHeightInTwips() */
       
   564 	{
       
   565 	return(TypeFaceStore()->FontHeightInTwips(aTypefaceIndex,aHeightIndex));
       
   566 	}
       
   567 
       
   568 EXPORT_C TInt CWsScreenDevice::FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const
       
   569 /** Gets the height of the specified font in pixels.
       
   570 
       
   571 The value returned is rounded up or down to the nearest font height in pixels.
       
   572 
       
   573 The specified font is the one with height index number aHeightIndex of the 
       
   574 typeface with index number aTypefaceIndex.
       
   575 
       
   576 @param aTypefaceIndex A typeface index number, in the range: 0 to (NumTypefaces() - 1). 
       
   577 @param aHeightIndex A font height index number, in the range: 0 to (iNumHeights - 1).
       
   578 @return The height of the font in pixels. 
       
   579 @see CBitmapDevice::FontHeightInPixels() */
       
   580 	{
       
   581 	return(TypeFaceStore()->FontHeightInPixels(aTypefaceIndex,aHeightIndex));
       
   582 	}
       
   583 
       
   584 EXPORT_C TInt CWsScreenDevice::GetFontById(CFont *&aFont,TUid aUid,const TAlgStyle& aAlgStyle)
       
   585 /** Gets a font by its bitmap UID. 
       
   586 
       
   587 Within a font file each font has its own UID. An algorithmic style is not 
       
   588 part of the actual font description, but is applied to it. For example algorithmic 
       
   589 bolding applies an algorithm to increase the apparent weight of each character 
       
   590 in the font. Note that the algorithm is applied blindly, and that a typeface 
       
   591 may already have a style e.g. it may already be bold or italic. Thus a bold 
       
   592 face will appear extra-bold if algorithmic bolding is applied to it. Algorithmic 
       
   593 effects are not necessarily a substitute for typeface design and should be 
       
   594 used with care.
       
   595 
       
   596 @param aFont On a successful return, contains a pointer to the new CFont. 
       
   597 @param aUid UID of the bitmap font. 
       
   598 @param aAlgStyle The algorithmic style to apply. 
       
   599 @return KErrNone if successful, otherwise one of the system-wide error codes. */
       
   600 	{
       
   601 	return(TypeFaceStore()->GetFontById(aFont,aUid,aAlgStyle));
       
   602 	}
       
   603 
       
   604 EXPORT_C TInt CWsScreenDevice::AddFile(const TDesC& aName,TInt& aId)
       
   605 /** Adds a font file to the device's typeface store. The specified font
       
   606 file must be accessible to any process, i.e. not located inside an
       
   607 application's private directory.
       
   608 
       
   609 @param aName Name of the font file. 
       
   610 @param aId ID for the font file. 
       
   611 @return KErrNone if successful, otherwise one of the system-wide error codes. 
       
   612 @see CBitmapDevice::AddFile() */
       
   613 	{
       
   614 	return(TypeFaceStore()->AddFile(aName, aId));
       
   615 	}
       
   616 
       
   617 EXPORT_C void CWsScreenDevice::RemoveFile(TInt aId)
       
   618 /** Removes a font file from the font store.
       
   619 
       
   620 @param aId The ID of the font file to be removed, default 0. 
       
   621 @see CBitmapDevice::RemoveFile() */
       
   622 	{
       
   623 	TypeFaceStore()->RemoveFile(aId);
       
   624 	}
       
   625 
       
   626 EXPORT_C void CWsScreenDevice::ReleaseFont(CFont* aFont)
       
   627 /** Releases a specified font.
       
   628 
       
   629 This function is used to indicate that the specified font is no longer needed 
       
   630 for use by the screen device. As fonts can be shared between applications, 
       
   631 this function does not delete the copy of the font from RAM, unless the font 
       
   632 was only being used by this device.
       
   633 
       
   634 @param aFont A pointer to the font to be released. 
       
   635 @see MGraphicsDeviceMap::ReleaseFont() */
       
   636 	{
       
   637 	TypeFaceStore()->ReleaseFont(aFont);
       
   638 	}
       
   639 
       
   640 EXPORT_C void CWsScreenDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
       
   641 /** Gets the attributes of the device's palette.
       
   642  
       
   643 This function always causes a flush of the window server buffer.
       
   644 
       
   645 @param aModifiable On return, indicates whether or not the device's palette 
       
   646 is modifiable (true) or fixed (false).
       
   647 @param aNumEntries On return, holds the number of entries in the device's 
       
   648 palette. 
       
   649 @see CFbsScreenDevice::PaletteAttributes() */
       
   650 	{
       
   651 	TInt ret=WriteReply(EWsSdOpPaletteAttributes);
       
   652 	aModifiable=ret&EWsSdSetableBitFlag;
       
   653 	aNumEntries=ret&(~EWsSdSetableBitFlag);
       
   654 	}
       
   655 
       
   656 EXPORT_C void CWsScreenDevice::SetPalette(CPalette* aPalette)
       
   657 /** Sets the screen device's palette.
       
   658 
       
   659 This function always causes a flush of the window server buffer.
       
   660 
       
   661 @param aPalette The screen device's new palette.
       
   662 @deprecated SetCustomPalette() should be used instead.
       
   663 @panic W32 6 aPalette is NULL.
       
   664 @capability WriteDeviceData */
       
   665 	{
       
   666 #if defined(__WINS__)
       
   667 	__ASSERT_DEBUG(SetCustomPalette(aPalette)==KErrNone,Panic(EW32PanicSilentFail));
       
   668 #endif
       
   669 	SetCustomPalette(aPalette);
       
   670 	}
       
   671 
       
   672 EXPORT_C TInt CWsScreenDevice::SetCustomPalette(const CPalette* aPalette)
       
   673 /** Sets the custom palette.
       
   674  
       
   675 This function always causes a flush of the window server buffer.
       
   676 
       
   677 @param aPalette The custom palette.
       
   678 @return KErrNone if sucessful, or one of the system error codes.
       
   679 @panic W32 6 aPalette is NULL.
       
   680 @capability WriteDeviceData */
       
   681 	{
       
   682 	__ASSERT_ALWAYS(aPalette,Panic(EW32PanicNullPalette));
       
   683 	TPtr8 palette(NULL,0);
       
   684 	CONST_CAST(CPalette*,aPalette)->GetDataPtr(0,aPalette->Entries(),palette);
       
   685 	TPtr8 empty(NULL,0);
       
   686 	return WriteReplyByProvidingRemoteReadAccess(&empty, sizeof(empty), &palette, EWsSdOpSetPalette);
       
   687 	}
       
   688 
       
   689 EXPORT_C TInt CWsScreenDevice::GetPalette(CPalette*& aPalette) const
       
   690 /** Gets the screen device's palette.
       
   691  
       
   692 This function always causes a flush of the window server buffer.
       
   693 
       
   694 @param aPalette On return, contains the screen device's palette. The caller 
       
   695 takes responsibility for discarding the palette.
       
   696 @return KErrNone if successful, otherwise another of the system-wide error 
       
   697 codes. 
       
   698 @see CFbsScreenDevice::GetPalette() */
       
   699 	{
       
   700 	TBool modifiable;		//Dummy parameter
       
   701 	TInt numEntries;
       
   702 	TInt ret;
       
   703 	PaletteAttributes(modifiable,numEntries);
       
   704 	aPalette=NULL;
       
   705 Retry:
       
   706 	TRAP(ret,aPalette=CPalette::NewL(numEntries));
       
   707 	if (ret==KErrNone)
       
   708 		{
       
   709 		TPtr8 palette(NULL,0);
       
   710 		aPalette->GetDataPtr(0,numEntries,palette);
       
   711 		ret=WriteReplyIntP(numEntries,&palette,EWsSdOpGetPalette);
       
   712 		if (ret!=KErrNone)
       
   713 			{
       
   714 			delete aPalette;
       
   715 			aPalette=NULL;
       
   716 			if (ret>0)		//The mode of the screen display changed
       
   717 				{
       
   718 				numEntries=ret;
       
   719 				goto Retry;
       
   720 				}
       
   721 			}
       
   722 		}
       
   723 	return ret;
       
   724 	}
       
   725 
       
   726 EXPORT_C void CWsScreenDevice::SetScreenSizeAndRotation(const TPixelsTwipsAndRotation &aSizeAndRotation)
       
   727 /** Sets the current screen size in twips and pixels, and the rotation for the 
       
   728 screen device.
       
   729 
       
   730 @param aSizeAndRotation The new rotation and the screen size in both pixels 
       
   731 and twips. */
       
   732 	{
       
   733 	TSize displaySizeInPixels = DisplaySizeInPixels();
       
   734 	TSize physicalScreenSizeInTwips = PhysicalScreenSizeInTwips();
       
   735 	// Need to reset the cache if the ratio of twip/pixels changes
       
   736 	// Using multiply as this is much quicker than divide on ARM
       
   737 	// No need to flush cache if this is a width/height swap
       
   738 	if((physicalScreenSizeInTwips.iWidth * aSizeAndRotation.iPixelSize.iWidth != aSizeAndRotation.iTwipsSize.iWidth * displaySizeInPixels.iWidth
       
   739 		|| physicalScreenSizeInTwips.iHeight * aSizeAndRotation.iPixelSize.iHeight != aSizeAndRotation.iTwipsSize.iHeight * displaySizeInPixels.iHeight)
       
   740 		&& !(aSizeAndRotation.iPixelSize.iHeight == displaySizeInPixels.iWidth
       
   741 		&& aSizeAndRotation.iPixelSize.iWidth == displaySizeInPixels.iHeight
       
   742 		&& physicalScreenSizeInTwips.iHeight == aSizeAndRotation.iTwipsSize.iWidth
       
   743 		&& physicalScreenSizeInTwips.iWidth == aSizeAndRotation.iTwipsSize.iHeight))
       
   744 		{
       
   745 		TypeFaceStore()->ReleaseTwipsCache();
       
   746 		}
       
   747 	Write(&aSizeAndRotation,sizeof(aSizeAndRotation),EWsSdOpSetScreenSizeAndRotation);
       
   748 	
       
   749 	if (!(iDisplaySizeInPixels == TSize(-1,-1)) || !IsCurrentModeDynamic())
       
   750 		{
       
   751 		iDisplaySizeInPixels=aSizeAndRotation.iPixelSize;
       
   752 		iPhysicalScreenSizeInTwips=aSizeAndRotation.iTwipsSize;
       
   753 		}
       
   754 	}
       
   755 
       
   756 EXPORT_C void CWsScreenDevice::GetDefaultScreenSizeAndRotation(TPixelsTwipsAndRotation &aSizeAndRotation) const
       
   757 /** Gets the current screen size (in both pixels and twips) and rotation.
       
   758 
       
   759 This function always causes a flush of the window server buffer.
       
   760 
       
   761 @param aSizeAndRotation The default screen size and rotation, defining screen 
       
   762 size in both pixels and twips. */
       
   763 	{
       
   764 	TPckgBuf<TPixelsTwipsAndRotation> sarPkg;
       
   765   	WriteReplyP(&sarPkg,EWsSdOpGetDefaultScreenSizeAndRotation);
       
   766 	aSizeAndRotation=sarPkg();
       
   767 	}
       
   768 
       
   769 EXPORT_C void CWsScreenDevice::SetScreenSizeAndRotation(const TPixelsAndRotation &aSizeAndRotation)
       
   770 /** Sets the current screen size in pixels, and the rotation for the screen device.
       
   771 
       
   772 This function always causes a flush of the window server buffer.
       
   773 
       
   774 @param aSizeAndRotation The new rotation and the screen size in pixels. */
       
   775 	{
       
   776 	TSize displaySizeInPixels = DisplaySizeInPixels();
       
   777 	if(displaySizeInPixels != aSizeAndRotation.iPixelSize
       
   778 		&& !(aSizeAndRotation.iPixelSize.iHeight == displaySizeInPixels.iWidth
       
   779 		&& aSizeAndRotation.iPixelSize.iWidth == displaySizeInPixels.iHeight))
       
   780 		{
       
   781 		// Reset the twips cache.
       
   782 		TypeFaceStore()->ReleaseTwipsCache();
       
   783 		}
       
   784 	Write(&aSizeAndRotation,sizeof(aSizeAndRotation),EWsSdOpSetScreenSizeAndRotation2);
       
   785 	if (!(iDisplaySizeInPixels == TSize(-1,-1)) || !IsCurrentModeDynamic())
       
   786 		{
       
   787 		iDisplaySizeInPixels=aSizeAndRotation.iPixelSize;
       
   788 		iPhysicalScreenSizeInTwips=SizeInTwips();
       
   789 		}
       
   790 	}
       
   791 
       
   792 EXPORT_C void CWsScreenDevice::GetDefaultScreenSizeAndRotation(TPixelsAndRotation &aSizeAndRotation) const
       
   793 /** Gets the current screen size (in pixels) and the rotation.
       
   794 
       
   795 This function always causes a flush of the window server buffer.
       
   796 
       
   797 @param aSizeAndRotation The default screen size in pixels and the rotation. */
       
   798 	{
       
   799 	TPckgBuf<TPixelsAndRotation> sarPkg;
       
   800   	WriteReplyP(&sarPkg,EWsSdOpGetDefaultScreenSizeAndRotation2);
       
   801 	aSizeAndRotation=sarPkg();
       
   802 	}
       
   803 
       
   804 EXPORT_C TDisplayMode CWsScreenDevice::GetScreenModeDisplayMode(const TInt &aMode) const
       
   805 /** Gets the display mode of the screen for the specified screen mode
       
   806 
       
   807 This function always causes a flush of the window server buffer.
       
   808 
       
   809 @param aMode The index of the screen mode for which the display mode is required
       
   810 @return The display mode for the specified screen mode. */
       
   811 	{
       
   812 	return STATIC_CAST(TDisplayMode,WriteReplyInt(aMode,EWsSdOpGetScreenModeDisplayMode));
       
   813 	}
       
   814  
       
   815 EXPORT_C TPoint CWsScreenDevice::GetDefaultScreenModeOrigin() const
       
   816 /** Gets the origin for the current screen mode
       
   817 
       
   818 This function always causes a flush of the window server buffer.
       
   819 
       
   820 @param aOrigin The default offset of the current 
       
   821 screen mode from the physical screen. */
       
   822 	{
       
   823 	TPckgBuf<TPoint> pntPkg;
       
   824   	WriteReplyP(&pntPkg,EWsSdOpGetDefaultScreenModeOrigin);
       
   825 	return pntPkg();
       
   826 	}
       
   827 
       
   828 EXPORT_C TPoint CWsScreenDevice::GetScreenModeOrigin(TInt aMode) const
       
   829 /** Get the origin of the screen for the specified screen mode.
       
   830 
       
   831 This function always causes a flush of the window server buffer.
       
   832 
       
   833 @param aMode The index of the screen mode for which the screen origin is required. 
       
   834 @param aOrigin The origin of the specified screen mode. */
       
   835 	{
       
   836 	TPckgBuf<TPoint> pntPkg;
       
   837 	WriteReplyP(&aMode,sizeof(aMode),&pntPkg,EWsSdOpGetScreenModeOrigin);
       
   838 	return pntPkg();
       
   839 	}
       
   840 
       
   841 EXPORT_C TSize CWsScreenDevice::GetScreenModeScale(TInt aMode) const
       
   842 /** Gets the scale for the specified screen mode.
       
   843 
       
   844 This function always causes a flush of the window server buffer.
       
   845 
       
   846 @param aMode The index of the screen mode for which the screen scale is required. 
       
   847 @return The scale for the specified screen mode. */
       
   848 	{
       
   849 	TPckgBuf<TSize> pntPkg;
       
   850 	WriteReplyP(&aMode,sizeof(aMode),&pntPkg,EWsSdOpGetScreenModeScale);
       
   851 	return pntPkg();
       
   852 	}
       
   853 
       
   854 EXPORT_C TSize CWsScreenDevice::GetCurrentScreenModeScale() const
       
   855 /** Gets the scale for the current screen mode.
       
   856 
       
   857 This function always causes a flush of the window server buffer.
       
   858 
       
   859 @return The scale for the current screen mode. */
       
   860 	{
       
   861 	TPckgBuf<TSize> pntPkg;
       
   862 	WriteReplyP(&pntPkg,EWsSdOpGetCurrentScreenModeScale);
       
   863 	return pntPkg();
       
   864 	}
       
   865 
       
   866 EXPORT_C TPoint CWsScreenDevice::GetCurrentScreenModeScaledOrigin() const
       
   867 /** Gets the current screen mode's scaled origin.
       
   868 
       
   869 The formula used is (A+B-1)/B
       
   870 
       
   871 where:
       
   872 
       
   873 - A is the screen mode origin in physical coordinates,
       
   874 - B is the screen mode scale width.
       
   875 
       
   876 The result obtained is the scaled origin of the present screen mode.
       
   877 
       
   878 @return The scaled origin for the current screen mode. */
       
   879 	{
       
   880 	TPckgBuf<TPoint> pntPkg;
       
   881 	WriteReplyP(&pntPkg,EWsSdOpGetCurrentScreenModeScaledOrigin);
       
   882 	return pntPkg();
       
   883 	}
       
   884 
       
   885 EXPORT_C TPoint CWsScreenDevice::GetScreenModeScaledOrigin(TInt aMode) const
       
   886 /** Gets the specfied screen mode's scaled origin.
       
   887 
       
   888 The functionality is same as CWsScreenDevice::GetCurrentScreenModeScaledOrigin().
       
   889 
       
   890 It always causes a flush of the window server buffer.
       
   891 
       
   892 @param aMode The index of the screen mode for which the scaled origin is required. 
       
   893 @return The scaled origin for the specified screen mode. */
       
   894 	{
       
   895 	TPckgBuf<TPoint> pntPkg;
       
   896 	WriteReplyP(&aMode,sizeof(aMode),&pntPkg,EWsSdOpGetScreenModeScaledOrigin);
       
   897 	return pntPkg();
       
   898 	}
       
   899 
       
   900 /**
       
   901 @internalComponent
       
   902 @released
       
   903 
       
   904 Used for testing purposes only.
       
   905 
       
   906 @return The present screen mode.
       
   907 */
       
   908 EXPORT_C TSizeMode CWsScreenDevice::GetCurrentScreenModeAttributes() const
       
   909 	{
       
   910 	TPckgBuf<TSizeMode> pntPkg;
       
   911 	WriteReplyP(&pntPkg,EWsSdOpGetCurrentScreenModeAttributes);
       
   912 	return pntPkg();
       
   913 	}
       
   914 
       
   915 /**
       
   916 @internalComponent
       
   917 @released
       
   918 
       
   919 Used for testing purposes only.
       
   920 
       
   921 @param aModeAtt Screen size mode to be set.
       
   922 */
       
   923 EXPORT_C void CWsScreenDevice::SetCurrentScreenModeAttributes(const TSizeMode &aModeAtt)
       
   924 	{
       
   925 	Write(&aModeAtt,sizeof(aModeAtt),EWsSdOpSetCurrentScreenModeAttributes);
       
   926 	}
       
   927 
       
   928 EXPORT_C void CWsScreenDevice::SetAppScreenMode(TInt aMode)
       
   929 /** Sets the application's screen mode; this also sets all the attributes
       
   930 of the screen mode.
       
   931 
       
   932 Note: although this API was added in Symbian OS v8.0, the functionality is 
       
   933 only available from Symbian OS v8.1 onwards.
       
   934 
       
   935 @param aMode The index of the application's new screen mode.*/
       
   936 	{
       
   937 	WriteInt(aMode,EWsSdOpSetAppScreenMode);
       
   938 	}
       
   939 
       
   940 EXPORT_C TInt CWsScreenDevice::NumScreenModes() const
       
   941 /** Gets the number of available screen modes. 
       
   942 
       
   943 Each mode has a different size, and one or more possible rotations/orientations.
       
   944 
       
   945 This function always causes a flush of the window server buffer.
       
   946 
       
   947 @return The number of screen modes. */
       
   948 	{
       
   949 	return(WriteReply(EWsSdOpGetNumScreenModes));
       
   950 	}
       
   951 
       
   952 EXPORT_C TInt CWsScreenDevice::CurrentScreenMode() const
       
   953 /** Gets the current screen mode index.
       
   954 
       
   955 This function always causes a flush of the window server buffer.
       
   956 
       
   957 @return The index into the list of available screen modes of the current screen 
       
   958 mode. */
       
   959 	{
       
   960 	return WriteReply(EWsSdOpGetScreenMode);
       
   961 	}
       
   962 
       
   963 EXPORT_C void CWsScreenDevice::SetScreenMode(TInt aMode)
       
   964 /**
       
   965 @publishedPartner
       
   966 @released
       
   967 
       
   968 Sets the current screen mode.
       
   969 
       
   970 Note that this function is only useful for testing. This is because the screen mode 
       
   971 normally reflects the state of real hardware, e.g. whether the cover is open 
       
   972 or closed on a phone that supports screen flipping.
       
   973  
       
   974 This function always causes a flush of the window server buffer.
       
   975 
       
   976 @param aMode The screen mode index, starting from zero.
       
   977 @capability WriteDeviceData */
       
   978 	{
       
   979 	WriteInt(aMode,EWsSdOpSetScreenMode);
       
   980 	if (IsCurrentModeDynamic())
       
   981 		{
       
   982 		iDisplaySizeInPixels=TSize(-1,-1);
       
   983 		iPhysicalScreenSizeInTwips=TSize(-1,-1);
       
   984 		}
       
   985 	else
       
   986 		{
       
   987 		iDisplaySizeInPixels=SizeInPixels();
       
   988 		iPhysicalScreenSizeInTwips=SizeInTwips();
       
   989 		}
       
   990 	}
       
   991 
       
   992 EXPORT_C void CWsScreenDevice::GetScreenModeSizeAndRotation(TInt aMode, TPixelsTwipsAndRotation &aSizeAndRotation) const
       
   993 /** Get the screen rotation and size, in both pixels and twips, for the specified 
       
   994 screen mode.
       
   995  
       
   996 This function always causes a flush of the window server buffer.
       
   997 
       
   998 @param aMode The index of the screen mode for which the screen size and rotation 
       
   999 are required. 
       
  1000 @param aSizeAndRotation The orientation of the specified screen mode, and its 
       
  1001 size in both pixels and twips. */
       
  1002 	{
       
  1003 	TPckgBuf<TPixelsTwipsAndRotation> sarPkg;
       
  1004   	WriteReplyP(&aMode,sizeof(aMode),&sarPkg,EWsSdOpGetScreenModeSizeAndRotation);
       
  1005 	aSizeAndRotation=sarPkg();
       
  1006 	}
       
  1007 
       
  1008 EXPORT_C void CWsScreenDevice::GetScreenModeSizeAndRotation(TInt aMode, TPixelsAndRotation &aSizeAndRotation) const
       
  1009 /** Get the screen rotation and size (in pixels) for the specified screen mode.
       
  1010  
       
  1011 This function always causes a flush of the window server buffer.
       
  1012 
       
  1013 @param aMode The index of the screen mode for which the screen size and rotation 
       
  1014 are required. 
       
  1015 @param aSizeAndRotation The orientation of the specified screen mode, and its 
       
  1016 size in pixels. */
       
  1017 	{
       
  1018 	TPckgBuf<TPixelsAndRotation> sarPkg;
       
  1019   	WriteReplyP(&aMode,sizeof(aMode),&sarPkg,EWsSdOpGetScreenModeSizeAndRotation2);
       
  1020 	aSizeAndRotation=sarPkg();
       
  1021 	}
       
  1022 
       
  1023 EXPORT_C void CWsScreenDevice::SetCurrentRotations(TInt aMode, CFbsBitGc::TGraphicsOrientation aRotation) const
       
  1024 /** 
       
  1025 @publishedPartner
       
  1026 @released
       
  1027 
       
  1028 Sets the screen rotation that should be used with a particular screen size. 
       
  1029 
       
  1030 After calling this function, whenever you change into the screen size specified 
       
  1031 by aMode you will have the rotation aRotation. The setting remains in force 
       
  1032 until it is explicitly changed using this function. 
       
  1033 
       
  1034 Panics if the specified rotation is not allowed by the given screen mode.
       
  1035 
       
  1036 @param aMode The index of the screen mode the rotation applies to. 
       
  1037 @param aRotation The new screen orientation.
       
  1038 @see GetRotationsList()
       
  1039 @capability WriteDeviceData */
       
  1040 	{
       
  1041 	TWsSdCmdSetScreenRotation screenRotation(aMode,aRotation);
       
  1042 	Write(&screenRotation,sizeof(screenRotation),EWsSdOpSetModeRotation);
       
  1043 	}
       
  1044 
       
  1045 EXPORT_C TInt CWsScreenDevice::GetRotationsList(TInt aMode, CArrayFixFlat<TInt> *aRotationList) const
       
  1046 /** Gets the list of valid rotations for a particular screen size.
       
  1047 
       
  1048 The list is initialised in wsini.ini.
       
  1049  
       
  1050 This function always causes a flush of the window server buffer.
       
  1051 
       
  1052 @param aMode The index of the screen mode for which the rotation list 
       
  1053 is required. 
       
  1054 @param aRotationList The list of valid screen orientations. 
       
  1055 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1056 codes. 
       
  1057 @see SetCurrentRotations() */
       
  1058 	{
       
  1059 	TUint modeList=(TUint)WriteReplyInt(aMode,EWsSdOpGetRotationList);
       
  1060 	TUint modeBit=1<<CFbsBitGc::EGraphicsOrientationNormal;
       
  1061 	TBool rots[4];
       
  1062 	TInt rotations=0;
       
  1063 	TInt ii;
       
  1064 	for (ii=0;ii<4;ii++)
       
  1065 		{
       
  1066 		rots[ii]=(modeList&modeBit);
       
  1067 		if (rots[ii])
       
  1068 			++rotations;
       
  1069 		modeBit=modeBit<<1;
       
  1070 		}
       
  1071 	if (!aRotationList)
       
  1072 		return rotations;
       
  1073 	TRAPD(err,aRotationList->ResizeL(rotations));
       
  1074 	if (err!=KErrNone)
       
  1075 		return(err);
       
  1076 	rotations=0;
       
  1077 	for (ii=0;ii<4;ii++)
       
  1078 		{
       
  1079 		if (rots[ii])
       
  1080 			(*aRotationList)[rotations++]=REINTERPRET_CAST(CFbsBitGc::TGraphicsOrientation&,ii);
       
  1081 		}
       
  1082 	return KErrNone;
       
  1083 	}
       
  1084 
       
  1085 EXPORT_C TScreenModeEnforcement CWsScreenDevice::ScreenModeEnforcement() const
       
  1086 /** Gets the current screen mode enforcement settings.
       
  1087 
       
  1088 The global screen mode enforcement setting defines the requirements that a 
       
  1089 group window must meet to be displayed. The requirements may have been set 
       
  1090 in wsini.ini, or using SetScreenModeEnforcement(). 
       
  1091  
       
  1092 This function always causes a flush of the window server buffer.
       
  1093 
       
  1094 @return The screen mode enforcement requirements. */
       
  1095 	{
       
  1096 	return((TScreenModeEnforcement)WriteReply(EWsSdOpScreenModeEnforcement));
       
  1097 	}
       
  1098 
       
  1099 EXPORT_C void CWsScreenDevice::SetScreenModeEnforcement(TScreenModeEnforcement aMode) const
       
  1100 /** 
       
  1101 @publishedPartner
       
  1102 @released
       
  1103 
       
  1104 Sets the screen mode enforcement requirements.
       
  1105 
       
  1106 This global setting defines the requirements that a group window must meet 
       
  1107 to be displayed. The value may be set using this function, but is more likely 
       
  1108 to be defined in wsini.ini. 
       
  1109 
       
  1110 @param aMode The screen mode enforcement requirements.
       
  1111 @capability WriteDeviceData */
       
  1112 	{
       
  1113 	WriteInt(aMode,EWsSdOpSetScreenModeEnforcement);
       
  1114 	}
       
  1115 
       
  1116 EXPORT_C TInt CWsScreenDevice::GetScreenNumber() const
       
  1117 /** Get device's screen number 
       
  1118 
       
  1119 @return The device's screen number
       
  1120 @see CWsScreenDevice::Construct( TInt aDefaultScreenNumber ) */
       
  1121 	{
       
  1122 	return WriteReply(EWsSdOpGetScreenNumber);
       
  1123 	}
       
  1124 
       
  1125 /** Gets the available screen size modes.
       
  1126 
       
  1127 This function retrieves all available screen size modes which are supported by
       
  1128 the server.
       
  1129 
       
  1130 @param aModeList On return, the list of available screen size modes.
       
  1131 @return The number of supported screen size modes if successful otherwise returns KErrNoMemory if 
       
  1132 there is insufficient memory to create the array. */
       
  1133 EXPORT_C TInt CWsScreenDevice::GetScreenSizeModeList(RArray<TInt>* aModeList) const
       
  1134 	{
       
  1135 	__ASSERT_ALWAYS(aModeList, Panic(EW32PanicNullArray));
       
  1136 	aModeList->Reset();
       
  1137 	TInt count=WriteReply(EWsSdOpGetNumScreenModes);
       
  1138 	TInt totSize=count*sizeof(TInt);
       
  1139 	TInt* allocMem=static_cast<TInt*>(User::Alloc(totSize));
       
  1140 	if(allocMem==NULL)
       
  1141 		{
       
  1142 		return KErrNoMemory;
       
  1143 		}
       
  1144 	TPtr8 listPtr(reinterpret_cast<TUint8*>(allocMem), totSize);
       
  1145 	count=WriteReplyP(&listPtr, EWsSdOpGetScreenSizeModeList);
       
  1146 	new(aModeList) RArray<TInt>(allocMem, count);
       
  1147 	return count;	
       
  1148 	}	
       
  1149 
       
  1150 EXPORT_C TInt CWsScreenDevice::SetBackLight(TBool aBackLight)
       
  1151 /** Set the back light state. 
       
  1152 
       
  1153 If the back light is disabled, or the client process SID does not match the EikSrv
       
  1154 one (0x10003a4a), KErrPermissionDenied is returned. If the system is in a low power
       
  1155 state, KErrBadPower may be returned.
       
  1156 
       
  1157 @param aBackLight, ETrue Set the backlight on, EFlase set the backlight off.
       
  1158 @return KErrNone if successful, otherwise a system-wide error code. */
       
  1159 	{
       
  1160 	return(WriteReplyInt(aBackLight,EWsClOpSetBackLight));
       
  1161 	}