diff -r 000000000000 -r bde4ae8d615e os/kernelhwsrv/kernel/eka/drivers/edisp/emul/win32/wd_wins.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/kernelhwsrv/kernel/eka/drivers/edisp/emul/win32/wd_wins.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,481 @@ +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32\drivers\edisp\emul\win32\wd_wins.cpp +// +// + +#include +#include +#include +#define WIN32_LEAN_AND_MEAN +#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union +#include +#pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union +#include "ws_std.h" + +// Driver for WINS platform using windows stock font + +#define FONTWIDTH 8 +#define FONTHEIGHT 12 + +struct rgbValues{ + TUint8 iRed; + TUint8 iGreen; + TUint8 iBlue; + }; + +const TUint8 KMonoRed0=50; +const TUint8 KMonoGreen0=100; +const TUint8 KMonoBlue0=200; +const TUint8 KMonoRed1=250; +const TUint8 KMonoGreen1=250; +const TUint8 KMonoBlue1=20; + +const TColorIndex KMonoAttributes[8]= + { + 1, // Normal foreground + 0, // Normal background + 1, // Bold foreground + 0, // Bold background + 0, // Inverse foreground + 1, // Inverse background + 0, // Highlight foreground + 1 // Highlight background + }; + +const TColorIndex KColor256Attributes[8]= + { + 38, // Normal foreground + 33, // Normal background + 36, // Bold foreground + 38, // Bold background + 33, // Inverse foreground + 38, // Inverse background + 38, // Highlight foreground + 36 // Highlight background + }; + +class CScreenDriverWins : public CScreenDriver + { + friend class CScreenDriver; +public: + CScreenDriverWins(); + virtual void Init(TSize &aScreenSize,TSize &aFontSize); + virtual void Blit(const TText *aBuffer,TInt aLength,const TPoint &aPosition); + virtual TBool ScrollUp(const TRect& aRect); + virtual void Clear(const TRect& aRect); + + virtual void SetPixel(const TPoint& aPoint,TUint8 aColour); + virtual TInt GetPixel(const TPoint& aPoint); + virtual void SetWord(const TPoint& aPoint,TInt aWord); + virtual TInt GetWord(const TPoint& aPoint); + virtual void SetLine(const TPoint& aPoint,const TPixelLine& aPixelLine); + virtual void GetLine(const TPoint& aPoint,TPixelLine& aPixelLine); + virtual void SetPaletteEntry(TColorIndex anIndex,TUint8 aRed,TUint8 aGreen,TUint8 aBlue); + virtual void GetPaletteEntry(TColorIndex anIndex,TUint8 &aRed,TUint8 &aGreen,TUint8 &aBlue); + virtual void SetForegroundColor(TColorIndex anIndex); + virtual void SetBackgroundColor(TColorIndex anIndex); + virtual void GetAttributeColors(TColorIndex* anArray); + + virtual TInt SetMode(TVideoMode aMode); + + static TBool IsHankaku(const TText aCode); + virtual TPoint GraphicsPosition(const TPoint& aPosition); + virtual void ScreenBufferScrollUp(const TRect& aRect); + virtual void ScreenBufferClear(const TRect& aRect); +private: + TText* iScreenBuffer; + +private: + HFONT iFont; + HDC iDc; + TSize iTextScreenSize; + TScreenInfoV01 iScreenInfo; + TVideoMode iMode; + rgbValues* iPalette; + }; + + +TPoint CScreenDriverWins::GraphicsPosition(const TPoint& aPosition) + { + TPoint pos(0,aPosition.iY*FONTHEIGHT); + TText* pS=iScreenBuffer+(iTextScreenSize.iWidth*aPosition.iY); + TText* pE=pS+aPosition.iX; + for (TText* pT=pS;pT= 0xff61 && aCode <= 0xff9f) + return ETrue; // HANKAKU KATAKANA code + if (aCode >= 0x2550 && aCode <= 0x259f) + return ETrue; // HANKAKU Graphics code + if (aCode < 0x100) + return ETrue; // Alphanumeric codes means HANKAKU + return EFalse; + } + +void CScreenDriverWins::ScreenBufferScrollUp(const TRect& aRect) + { + TText* src=&iScreenBuffer[(aRect.iTl.iY+1)*iTextScreenSize.iWidth+aRect.iTl.iX]; + TText* dest=&iScreenBuffer[aRect.iTl.iY*iTextScreenSize.iWidth+aRect.iTl.iX]; + for (TInt j=0;j sI(iScreenInfo); + UserSvr::ScreenInfo(sI); + iPalette=(rgbValues *)User::Alloc(256*sizeof(rgbValues)); + } + +EXPORT_C CScreenDriver *CScreenDriver::New() +// +// Return the actual screen driver. +// + { + + CScreenDriverWins *pS=new CScreenDriverWins; + if (!pS) + return(NULL); + if (!pS->iScreenInfo.iWindowHandleValid) + { + delete pS; + return(NULL); + } + pS->iTextScreenSize=pS->iScreenInfo.iScreenSize; + pS->iTextScreenSize.iWidth/=FONTWIDTH; // Convert from GDI units to character positions + pS->iTextScreenSize.iHeight/=FONTHEIGHT; + pS->iScreenBuffer=new TText[pS->iTextScreenSize.iWidth*pS->iTextScreenSize.iHeight]; + if (!pS->iScreenBuffer) + { + delete pS; + return(NULL); + } + + __LOCK_HOST; + HWND win=(HWND)pS->iScreenInfo.iWindowHandle; + pS->iDc=GetDC(win); + DWORD fontCharacterSet; + LANGID language; + fontCharacterSet=ANSI_CHARSET; + language=(LANGID)PRIMARYLANGID(GetSystemDefaultLangID()); + if (language==LANG_JAPANESE) fontCharacterSet=SHIFTJIS_CHARSET; + pS->iFont=CreateFontA(FONTHEIGHT+1, // logical font height + FONTWIDTH+1, // logical average character width + 0, // angle of escapement + 0, // base-line orientation angle + FW_DONTCARE, // font weight + 0, // italic attribute + 0, // underline attribute + 0, // strikeout attribute + fontCharacterSet, // character set identifier + OUT_RASTER_PRECIS, // output precision + CLIP_CHARACTER_PRECIS, // clipping precision + DEFAULT_QUALITY, // output quality + FIXED_PITCH, // pitch and family + "Terminal" // typeface name string + ); + if (!pS->iFont) + { + delete pS->iScreenBuffer; + delete pS; + return(NULL); + } + + // On some Windows9x PCs, the font we assume under NT isn't always present, + // but it's important we get a font with height 12. Therefore increase the + // height setting and try again. This seems always to do the trick. + TEXTMETRIC textMetrics; + HFONT oldFont=REINTERPRET_CAST(HFONT,SelectObject(pS->iDc,pS->iFont)); + TBool tryNewFont=FALSE; + if (GetTextMetrics(pS->iDc, &textMetrics) && (textMetrics.tmHeight<12)) + tryNewFont=TRUE; + SelectObject(pS->iDc, oldFont); + if (tryNewFont) + { + HFONT newFont=CreateFontA(FONTHEIGHT+2, + FONTWIDTH+1, + 0, + 0, + FW_DONTCARE, + 0, + 0, + 0, + fontCharacterSet, + OUT_RASTER_PRECIS, + CLIP_CHARACTER_PRECIS, + DEFAULT_QUALITY, + FIXED_PITCH, + "Terminal" + ); + if (newFont) + pS->iFont=newFont; + } + + return(pS); + } + +void CScreenDriverWins::Init(TSize &aScreenSize,TSize &aFontSize) +// +// Report screen information +// + { + + aFontSize=TSize(FONTWIDTH,FONTHEIGHT); + aScreenSize=iTextScreenSize; + } + +TInt CScreenDriverWins::SetMode(TVideoMode aMode) +// +// Set the screen mode +// + { + +// Reset the palette + + if (aMode==EColor256) + { + TInt x, y, z, t; + + for(t=0;t<16;t++) + { + iPalette[t].iRed=(TUint8)(t*8); + iPalette[t].iGreen=(TUint8)(t*8); + iPalette[t].iBlue=(TUint8)(t*8); + } + for(t=16;t<32;t++) + { + iPalette[t].iRed=(TUint8)(t*8+7); + iPalette[t].iGreen=(TUint8)(t*8+7); + iPalette[t].iBlue=(TUint8)(t*8+7); + } + for(x=0;x<2;x++) + for(y=0;y<2;y++) + for(z=0;z<2;z++) + { + iPalette[t].iRed=(TUint8)(x*255); + iPalette[t].iGreen=(TUint8)(y*255); + iPalette[t].iBlue=(TUint8)(z*255); + t++; + } + for(x=0;x<6;x++) + for(y=0;y<6;y++) + for(z=0;z<6;z++) + { + iPalette[t].iRed=(TUint8)(x*51); + iPalette[t].iGreen=(TUint8)(y*51); + iPalette[t].iBlue=(TUint8)(z*51); + t++; + } + iMode=aMode; + return(KErrNone); + } + if (aMode==EMono) + { + iPalette[0].iRed=KMonoRed0; + iPalette[0].iGreen=KMonoGreen0; + iPalette[0].iBlue=KMonoBlue0; + iPalette[1].iRed=KMonoRed1; + iPalette[1].iGreen=KMonoGreen1; + iPalette[1].iBlue=KMonoBlue1; + iMode=aMode; + return(KErrNone); + } + return(KErrNotSupported); + } + +void CScreenDriverWins::Blit(const TText *aBuffer, TInt aLength, const TPoint &aPosition) +// +// Write contiguous block of characters to some segment of a line on the display +// + { + + if (iDc) + { + + // Create a font of the appropriate metrics. The character + // set selection depends on the context. The text console + // was originally designed with the code page 850 line drawing + // characters, so in the 8-bit version we continue to select + // this, until we are in a position to supply a specific font + // with the SDK. In the 16-bit version, we can use an ANSI + // font and the proper line drawing characters defined in Unicode. + // For a Japanese environment, an attempt is made to select a + // font that supports the shift-JIS character set. + + __LOCK_HOST; + HFONT oldFont=REINTERPRET_CAST(HFONT,SelectObject(iDc,iFont)); + if (oldFont) + { + TPtrC buf(aBuffer,aLength); + TBuf<0x100> b; + b.Copy(buf); + TText* code =(TText*)b.Ptr(); + Mem::Copy(iScreenBuffer+((aPosition.iY*iTextScreenSize.iWidth)+aPosition.iX),code,aLength*2); + TPoint ap=GraphicsPosition(aPosition); + for (TInt i=0;i