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\ewsrv\co_twin.cpp sl@0: // sl@0: // sl@0: sl@0: #include "ws_std.h" sl@0: sl@0: extern "C" sl@0: EXPORT_C TAny* NewConsole() sl@0: // sl@0: // Create a new console window. sl@0: // sl@0: { sl@0: return new CConsoleTextWin; sl@0: } sl@0: sl@0: CConsoleTextWin *CConsoleTextWin::NewL(const TDesC &aTitle,TSize aSize) sl@0: // sl@0: // Create a new console window. Leave on any error. sl@0: // sl@0: { sl@0: sl@0: CConsoleTextWin *pC=new(ELeave) CConsoleTextWin; sl@0: User::LeaveIfError(pC->iConsole.Init(aTitle,aSize)); sl@0: return(pC); sl@0: } sl@0: sl@0: CConsoleTextWin::CConsoleTextWin() sl@0: // sl@0: // Constrcutor sl@0: // sl@0: {} sl@0: sl@0: CConsoleTextWin::~CConsoleTextWin() sl@0: // sl@0: // Destructor sl@0: // sl@0: { sl@0: sl@0: iConsole.Close(); sl@0: } sl@0: sl@0: TInt CConsoleTextWin::Create(const TDesC &aTitle,TSize aSize) sl@0: // sl@0: // Create a new console window. sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.Init(aTitle,aSize); sl@0: if (r==KErrNone) sl@0: { sl@0: r=iConsole.Control(_L("+Maximize +NewLine -Lock -Wrap")); sl@0: } sl@0: return(r); sl@0: } sl@0: sl@0: void CConsoleTextWin::Read(TRequestStatus &aStatus) sl@0: // sl@0: // Asynchronous get keystroke from window sl@0: // sl@0: { sl@0: sl@0: iConsole.Read(iKey,aStatus); sl@0: } sl@0: sl@0: sl@0: void ConsServerCheck(TInt aResult, TInt aLine) sl@0: { sl@0: if(aResult!=KErrNone) sl@0: { sl@0: #ifdef _DEBUG sl@0: RDebug::Printf("EConsServerFailed with %d at line %d",aResult,aLine); sl@0: #endif sl@0: (void)aLine; sl@0: Panic(EConsServerFailed); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CConsoleTextWin::ReadCancel() sl@0: // sl@0: // Cancel asynchronous read request sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.ReadCancel(); sl@0: ConsServerCheck(r,__LINE__); sl@0: } sl@0: sl@0: void CConsoleTextWin::Write(const TDesC &aDes) sl@0: // sl@0: // Write to the console. sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.Write(aDes); sl@0: ConsServerCheck(r,__LINE__); sl@0: } sl@0: sl@0: TPoint CConsoleTextWin::CursorPos() const sl@0: // sl@0: // Read current cursor position relative to the window sl@0: // sl@0: { sl@0: sl@0: TPoint p; sl@0: TInt r=iConsole.CursorPos(p); sl@0: ConsServerCheck(r,__LINE__); sl@0: return(p); sl@0: } sl@0: sl@0: void CConsoleTextWin::SetCursorPosAbs(const TPoint &aPosition) sl@0: // sl@0: // Position the cursor in the window buffer sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.SetCursorPosAbs(aPosition); sl@0: ConsServerCheck(r,__LINE__); sl@0: } sl@0: sl@0: void CConsoleTextWin::SetCursorPosRel(const TPoint &aVector) sl@0: // sl@0: // Position the cursor in the window buffer sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.SetCursorPosRel(aVector); sl@0: ConsServerCheck(r,__LINE__); sl@0: } sl@0: sl@0: void CConsoleTextWin::SetCursorHeight(TInt aPercentage) sl@0: // sl@0: // Set the percentage height of the cursor sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.SetCursorHeight(aPercentage); sl@0: ConsServerCheck(r,__LINE__); sl@0: } sl@0: sl@0: void CConsoleTextWin::SetTitle(const TDesC &aTitle) sl@0: // sl@0: // Set the console window title sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.SetTitle(aTitle); sl@0: ConsServerCheck(r,__LINE__); sl@0: } sl@0: sl@0: void CConsoleTextWin::ClearScreen() sl@0: // sl@0: // Clear screen sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.ClearScreen(); sl@0: ConsServerCheck(r,__LINE__); sl@0: } sl@0: sl@0: void CConsoleTextWin::ClearToEndOfLine() sl@0: // sl@0: // Clear window from current cursor position to the end of the line sl@0: // sl@0: { sl@0: sl@0: TInt r=iConsole.ClearToEndOfLine(); sl@0: ConsServerCheck(r,__LINE__); sl@0: } sl@0: sl@0: TSize CConsoleTextWin::ScreenSize() const sl@0: // sl@0: // Return the current screen size sl@0: // sl@0: { sl@0: sl@0: TSize s; sl@0: TInt r=iConsole.Size(s); sl@0: ConsServerCheck(r,__LINE__); sl@0: return(s); sl@0: } sl@0: sl@0: TKeyCode CConsoleTextWin::KeyCode() const sl@0: // sl@0: // Return the current keycode sl@0: // sl@0: { sl@0: sl@0: return(iKey.Code()); sl@0: } sl@0: sl@0: TUint CConsoleTextWin::KeyModifiers() const sl@0: // sl@0: // Return the current key modifiers sl@0: // sl@0: { sl@0: sl@0: return(iKey.Modifiers()); sl@0: } sl@0: sl@0: void CConsoleTextWin::SetTextAttribute(TTextAttribute anAttribute) sl@0: // sl@0: // Set text attribute sl@0: // sl@0: { sl@0: sl@0: iConsole.SetTextAttribute(anAttribute); sl@0: } sl@0: sl@0: RConsole &CConsoleTextWin::Console() sl@0: // sl@0: // Return the console object. sl@0: // sl@0: { sl@0: sl@0: return(iConsole); sl@0: }