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