First public contribution.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\cbase\ub_cons.cpp
27 EXPORT_C CConsoleBase::CConsoleBase()
36 EXPORT_C CConsoleBase::~CConsoleBase()
44 Gets a character from the console.
46 @return the key code from the console.
48 EXPORT_C TKeyCode CConsoleBase::Getch()
53 User::WaitForRequest(s);
54 __ASSERT_ALWAYS(s==KErrNone,Panic(EConsGetchFailed));
62 Prints characters to the console window.
64 @param aFmt The non-modifiable descriptor containing the
65 format string. The TRefByValue class provides a
66 constructor which takes a TDesC type.
68 @param ... A variable number of arguments to be converted to text
69 as dictated by the format string.
71 EXPORT_C void CConsoleBase::Printf(TRefByValue<const TDesC> aFmt,...)
74 TestOverflowTruncate overflow;
79 // coverity[uninit_use_in_call]
80 TRAP_IGNORE(aBuf.AppendFormatList(aFmt,list,&overflow)); // ignore leave in TTimeOverflowLeave::Overflow()
87 Sets the cursor's x-position.
89 @param aX The x-position.
91 EXPORT_C void CConsoleBase::SetPos(TInt aX)
94 SetCursorPosAbs(TPoint(aX,WhereY()));
101 Sets the cursor's x-position and y-position.
103 @param aX The x-position.
104 @param aY The y-position.
106 EXPORT_C void CConsoleBase::SetPos(TInt aX,TInt aY)
109 SetCursorPosAbs(TPoint(aX,aY));
116 Gets the cursor's x-position.
118 @return The cursor's x-position.
120 EXPORT_C TInt CConsoleBase::WhereX() const
123 return(CursorPos().iX);
129 Gets the cursor's y-position.
131 @return The cursor's y-position.
133 EXPORT_C TInt CConsoleBase::WhereY() const
136 return(CursorPos().iY);
145 EXPORT_C TInt CConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
147 return CBase::Extension_(aExtensionId, a0, a1);
151 void CColorConsoleBase::SetTextAttribute(TTextAttribute /*anAttribute*/)
164 EXPORT_C TInt CColorConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
166 return CConsoleBase::Extension_(aExtensionId, a0, a1);
170 NONSHARABLE_CLASS(CProxyConsole) : public CColorConsoleBase
174 TInt Construct(const TDesC& aImplDll);
176 // implement for CConsoleBase
177 TInt Create(const TDesC &aTitle,TSize aSize);
178 void Read(TRequestStatus &aStatus);
180 void Write(const TDesC &aDes);
181 TPoint CursorPos() const;
182 void SetCursorPosAbs(const TPoint &aPoint);
183 void SetCursorPosRel(const TPoint &aPoint);
184 void SetCursorHeight(TInt aPercentage);
185 void SetTitle(const TDesC &aTitle);
187 void ClearToEndOfLine();
188 TSize ScreenSize() const;
189 TKeyCode KeyCode() const;
190 TUint KeyModifiers() const;
191 // implement for CColorConsoleBase
192 void SetTextAttribute(TTextAttribute anAttribute);
193 virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
196 CColorConsoleBase* iConsole;
199 TInt CProxyConsole::Construct(const TDesC& aImplDll)
201 const TUidType type(KNullUid, KSharedLibraryUid, KConsoleDllUid);
202 TInt r=iLib.Load(aImplDll,type);
205 iConsole=(CColorConsoleBase*)(iLib.Lookup(1)());
212 CProxyConsole::~CProxyConsole()
218 TInt CProxyConsole::Create(const TDesC &aTitle,TSize aSize)
220 return iConsole->Create(aTitle,aSize);
223 void CProxyConsole::Read(TRequestStatus &aStatus)
225 iConsole->Read(aStatus);
228 void CProxyConsole::ReadCancel()
230 iConsole->ReadCancel();
233 void CProxyConsole::Write(const TDesC &aDes)
235 iConsole->Write(aDes);
238 TPoint CProxyConsole::CursorPos() const
240 return iConsole->CursorPos();
243 void CProxyConsole::SetCursorPosAbs(const TPoint &aPoint)
245 iConsole->SetCursorPosAbs(aPoint);
248 void CProxyConsole::SetCursorPosRel(const TPoint &aPoint)
250 iConsole->SetCursorPosRel(aPoint);
253 void CProxyConsole::SetCursorHeight(TInt aPercentage)
255 iConsole->SetCursorHeight(aPercentage);
258 void CProxyConsole::SetTitle(const TDesC &aTitle)
260 iConsole->SetTitle(aTitle);
263 void CProxyConsole::ClearScreen()
265 iConsole->ClearScreen();
268 void CProxyConsole::ClearToEndOfLine()
270 iConsole->ClearToEndOfLine();
273 TSize CProxyConsole::ScreenSize() const
275 return iConsole->ScreenSize();
278 TKeyCode CProxyConsole::KeyCode() const
280 return iConsole->KeyCode();
283 TUint CProxyConsole::KeyModifiers() const
285 return iConsole->KeyModifiers();
288 void CProxyConsole::SetTextAttribute(TTextAttribute anAttribute)
290 iConsole->SetTextAttribute(anAttribute);
293 TInt CProxyConsole::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
295 return iConsole->Extension_(aExtensionId, a0, a1);
299 _LIT(KConsImpl,"econs");
301 _LIT(KConsGuiImpl,"econseik");
302 _LIT(KConsNoGuiImpl,"econsnogui");
303 _LIT(KConsWservImpl, "econswserv");
309 Creates a new console object.
311 @param aTitle The title text for the console.
312 This should not be longer than 256 characters.
313 @param aSize The size of the console window.
315 @return A pointer to the new console object.
317 @see CConsoleBase::Create()
319 EXPORT_C CConsoleBase *Console::NewL(const TDesC &aTitle,TSize aSize)
321 CProxyConsole *pC=new(ELeave) CProxyConsole;
322 TInt r=pC->Construct(KConsImpl);
324 r=pC->Create(aTitle,aSize);
329 pC=new(ELeave) CProxyConsole;
332 // try and create a dummy console via ECONSNOGUI
333 r=pC->Construct(KConsNoGuiImpl);
335 else if (EmulatorMiniGui())
337 // try and create Wserv console via ECONSWSERV
338 r=pC->Construct(KConsWservImpl);
342 // try and create a GUI console via ECONSEIK instead
343 r=pC->Construct(KConsGuiImpl);
346 r=pC->Create(aTitle,aSize);