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