diff -r bf7481649c98 -r 7f25ef56562d windowing/windowserver/test/TClick/LOGWIN.CPP --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/windowing/windowserver/test/TClick/LOGWIN.CPP Wed Jun 23 19:41:15 2010 +0300 @@ -0,0 +1,304 @@ +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "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: +// Extracted from DEBLOGWN.CPP +// Code to run the WIN32 windows with the output +// +// + +#include +#include +#include +#include "LOGWIN.H" + +GLDEF_D struct TSharedMemory GSharedMemory; +//GLDEF_D struct HWND__ *Hwnd; +//LOCAL_D RSemaphore Sem; + +const TUint KHeapSize=0x8000; + + +TInt numLines(const CArrayVarSeg &aTextArray, TBool aOutOfMemory) + { + return (TInt)(aOutOfMemory)? + aTextArray.Count(): + aTextArray.Count()-1; + } + +TInt numVisibleLines(TInt aHeight, TInt aTextHeight) + { + return aHeight/aTextHeight; + } + +TInt32 __stdcall WndProc(struct HWND__ *aHwnd, TUint aMessage, TUint wParam, TInt32 lParam) + { + HDC hdc; + PAINTSTRUCT ps; + HFONT hfont; + RECT rect; + TInt i, + paintMin, + paintMax; + static LOGFONT logFont; + static TEXTMETRIC tm; + static TInt textHeight, + width, + height, + scrollMin=0, + scrollMax, + numLinesAbove=scrollMin, + prevNumLinesAbove; + static CArrayVarSeg *pmsg; + static TBool outOfMemory=EFalse; + + switch (aMessage) + { + case WM_CREATE: + hdc=GetDC(aHwnd); + + pmsg=new(ELeave) CArrayVarSeg(20); + { + TBuf<0x20> errorMsg; + errorMsg=_L("ERROR: out of memory"); + errorMsg.ZeroTerminate(); + TRAPD(err,pmsg->AppendL(*errorMsg.Ptr(), (errorMsg.Length()+1)*sizeof(TText))); + if (err!=KErrNone) + return(err); + } + GetTextMetrics(hdc, &tm); + textHeight=tm.tmHeight+tm.tmExternalLeading; + GetClientRect(aHwnd, &rect); + width=rect.right; + height=rect.bottom; + scrollMax=numLines(*pmsg, outOfMemory); + SetScrollPos(aHwnd, SB_VERT, numLinesAbove, TRUE); + SetScrollRange(aHwnd, SB_VERT, scrollMin, scrollMax, FALSE); + logFont.lfHeight=8; + wsprintf(logFont.lfFaceName, (LPCTSTR)_S("courier")); + + ReleaseDC(aHwnd, hdc); + return 0; + case WM_USER+EAppendText: + { + TRAPD(err,pmsg->InsertL(pmsg->Count()-1, *(TText *)lParam, wParam)); + if (err!=KErrNone) + { + pmsg->Delete(0, Max(0, (TInt)pmsg->Count()-1)); + numLinesAbove=scrollMax=scrollMin; + SetScrollPos(aHwnd, SB_VERT, numLinesAbove, TRUE); + SetScrollRange(aHwnd, SB_VERT, scrollMin, scrollMax, FALSE); + hdc=GetDC(aHwnd); + PatBlt(hdc, 0, 0, width, height, WHITENESS); + ReleaseDC(aHwnd, hdc); + return(err); + } + // adjust the scroll position so that the last line added is visible + if (numLinesAboveprevNumLinesAbove) + // scrolling towards end, therefore text moves up on screen + { + TInt numLinesToDraw=numLinesAbove-prevNumLinesAbove; + TInt numLinesToBlt=numVisibleLines(height, textHeight)-numLinesToDraw; + if (numLinesToBlt>0) + ScrollWindow(aHwnd, 0, -numLinesToDraw*textHeight, NULL, NULL); + PatBlt(hdc, 0, numLinesToBlt*textHeight, width, numLinesToDraw*textHeight, WHITENESS); + paintMin=Max(Min(numLinesAbove+numLinesToBlt, scrollMax), scrollMin); + paintMax=Min(paintMin+numLinesToDraw, scrollMax); + for (i=paintMin; i0) + ScrollWindow(aHwnd, 0, numLinesToDraw*textHeight, NULL, NULL); + PatBlt(hdc, 0, 0, width, numLinesToDraw*textHeight, WHITENESS); + paintMin=Max(Min(numLinesAbove, scrollMax), scrollMin); + paintMax=Min(paintMin+numLinesToDraw, scrollMax); + for (i=paintMin; i