|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32\euser\cbase\ub_cons.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "ub_std.h" |
|
19 #include <e32uid.h> |
|
20 #include <e32wins.h> |
|
21 |
|
22 |
|
23 |
|
24 /** |
|
25 Default constructor. |
|
26 */ |
|
27 EXPORT_C CConsoleBase::CConsoleBase() |
|
28 { |
|
29 } |
|
30 |
|
31 |
|
32 |
|
33 /** |
|
34 Destructor. |
|
35 */ |
|
36 EXPORT_C CConsoleBase::~CConsoleBase() |
|
37 { |
|
38 } |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 /** |
|
44 Gets a character from the console. |
|
45 |
|
46 @return the key code from the console. |
|
47 */ |
|
48 EXPORT_C TKeyCode CConsoleBase::Getch() |
|
49 { |
|
50 |
|
51 TRequestStatus s; |
|
52 Read(s); |
|
53 User::WaitForRequest(s); |
|
54 __ASSERT_ALWAYS(s==KErrNone,Panic(EConsGetchFailed)); |
|
55 return(KeyCode()); |
|
56 } |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 /** |
|
62 Prints characters to the console window. |
|
63 |
|
64 @param aFmt The non-modifiable descriptor containing the |
|
65 format string. The TRefByValue class provides a |
|
66 constructor which takes a TDesC type. |
|
67 |
|
68 @param ... A variable number of arguments to be converted to text |
|
69 as dictated by the format string. |
|
70 */ |
|
71 EXPORT_C void CConsoleBase::Printf(TRefByValue<const TDesC> aFmt,...) |
|
72 { |
|
73 |
|
74 TestOverflowTruncate overflow; |
|
75 // coverity[var_decl] |
|
76 VA_LIST list; |
|
77 VA_START(list,aFmt); |
|
78 TBuf<0x100> aBuf; |
|
79 // coverity[uninit_use_in_call] |
|
80 TRAP_IGNORE(aBuf.AppendFormatList(aFmt,list,&overflow)); // ignore leave in TTimeOverflowLeave::Overflow() |
|
81 Write(aBuf); |
|
82 } |
|
83 |
|
84 |
|
85 |
|
86 /** |
|
87 Sets the cursor's x-position. |
|
88 |
|
89 @param aX The x-position. |
|
90 */ |
|
91 EXPORT_C void CConsoleBase::SetPos(TInt aX) |
|
92 { |
|
93 |
|
94 SetCursorPosAbs(TPoint(aX,WhereY())); |
|
95 } |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 /** |
|
101 Sets the cursor's x-position and y-position. |
|
102 |
|
103 @param aX The x-position. |
|
104 @param aY The y-position. |
|
105 */ |
|
106 EXPORT_C void CConsoleBase::SetPos(TInt aX,TInt aY) |
|
107 { |
|
108 |
|
109 SetCursorPosAbs(TPoint(aX,aY)); |
|
110 } |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 /** |
|
116 Gets the cursor's x-position. |
|
117 |
|
118 @return The cursor's x-position. |
|
119 */ |
|
120 EXPORT_C TInt CConsoleBase::WhereX() const |
|
121 { |
|
122 |
|
123 return(CursorPos().iX); |
|
124 } |
|
125 |
|
126 |
|
127 |
|
128 /** |
|
129 Gets the cursor's y-position. |
|
130 |
|
131 @return The cursor's y-position. |
|
132 */ |
|
133 EXPORT_C TInt CConsoleBase::WhereY() const |
|
134 { |
|
135 |
|
136 return(CursorPos().iY); |
|
137 } |
|
138 |
|
139 |
|
140 /** |
|
141 Extension function |
|
142 |
|
143 |
|
144 */ |
|
145 EXPORT_C TInt CConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1) |
|
146 { |
|
147 return CBase::Extension_(aExtensionId, a0, a1); |
|
148 } |
|
149 |
|
150 |
|
151 void CColorConsoleBase::SetTextAttribute(TTextAttribute /*anAttribute*/) |
|
152 // |
|
153 // |
|
154 // |
|
155 { |
|
156 } |
|
157 |
|
158 |
|
159 /** |
|
160 Extension function |
|
161 |
|
162 |
|
163 */ |
|
164 EXPORT_C TInt CColorConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1) |
|
165 { |
|
166 return CConsoleBase::Extension_(aExtensionId, a0, a1); |
|
167 } |
|
168 |
|
169 |
|
170 NONSHARABLE_CLASS(CProxyConsole) : public CColorConsoleBase |
|
171 { |
|
172 public: |
|
173 ~CProxyConsole(); |
|
174 TInt Construct(const TDesC& aImplDll); |
|
175 public: |
|
176 // implement for CConsoleBase |
|
177 TInt Create(const TDesC &aTitle,TSize aSize); |
|
178 void Read(TRequestStatus &aStatus); |
|
179 void ReadCancel(); |
|
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); |
|
186 void ClearScreen(); |
|
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); |
|
194 private: |
|
195 RLibrary iLib; |
|
196 CColorConsoleBase* iConsole; |
|
197 }; |
|
198 |
|
199 TInt CProxyConsole::Construct(const TDesC& aImplDll) |
|
200 { |
|
201 const TUidType type(KNullUid, KSharedLibraryUid, KConsoleDllUid); |
|
202 TInt r=iLib.Load(aImplDll,type); |
|
203 if (r==KErrNone) |
|
204 { |
|
205 iConsole=(CColorConsoleBase*)(iLib.Lookup(1)()); |
|
206 if (!iConsole) |
|
207 r=KErrNoMemory; |
|
208 } |
|
209 return r; |
|
210 } |
|
211 |
|
212 CProxyConsole::~CProxyConsole() |
|
213 { |
|
214 delete iConsole; |
|
215 iLib.Close(); |
|
216 } |
|
217 |
|
218 TInt CProxyConsole::Create(const TDesC &aTitle,TSize aSize) |
|
219 { |
|
220 return iConsole->Create(aTitle,aSize); |
|
221 } |
|
222 |
|
223 void CProxyConsole::Read(TRequestStatus &aStatus) |
|
224 { |
|
225 iConsole->Read(aStatus); |
|
226 } |
|
227 |
|
228 void CProxyConsole::ReadCancel() |
|
229 { |
|
230 iConsole->ReadCancel(); |
|
231 } |
|
232 |
|
233 void CProxyConsole::Write(const TDesC &aDes) |
|
234 { |
|
235 iConsole->Write(aDes); |
|
236 } |
|
237 |
|
238 TPoint CProxyConsole::CursorPos() const |
|
239 { |
|
240 return iConsole->CursorPos(); |
|
241 } |
|
242 |
|
243 void CProxyConsole::SetCursorPosAbs(const TPoint &aPoint) |
|
244 { |
|
245 iConsole->SetCursorPosAbs(aPoint); |
|
246 } |
|
247 |
|
248 void CProxyConsole::SetCursorPosRel(const TPoint &aPoint) |
|
249 { |
|
250 iConsole->SetCursorPosRel(aPoint); |
|
251 } |
|
252 |
|
253 void CProxyConsole::SetCursorHeight(TInt aPercentage) |
|
254 { |
|
255 iConsole->SetCursorHeight(aPercentage); |
|
256 } |
|
257 |
|
258 void CProxyConsole::SetTitle(const TDesC &aTitle) |
|
259 { |
|
260 iConsole->SetTitle(aTitle); |
|
261 } |
|
262 |
|
263 void CProxyConsole::ClearScreen() |
|
264 { |
|
265 iConsole->ClearScreen(); |
|
266 } |
|
267 |
|
268 void CProxyConsole::ClearToEndOfLine() |
|
269 { |
|
270 iConsole->ClearToEndOfLine(); |
|
271 } |
|
272 |
|
273 TSize CProxyConsole::ScreenSize() const |
|
274 { |
|
275 return iConsole->ScreenSize(); |
|
276 } |
|
277 |
|
278 TKeyCode CProxyConsole::KeyCode() const |
|
279 { |
|
280 return iConsole->KeyCode(); |
|
281 } |
|
282 |
|
283 TUint CProxyConsole::KeyModifiers() const |
|
284 { |
|
285 return iConsole->KeyModifiers(); |
|
286 } |
|
287 |
|
288 void CProxyConsole::SetTextAttribute(TTextAttribute anAttribute) |
|
289 { |
|
290 iConsole->SetTextAttribute(anAttribute); |
|
291 } |
|
292 |
|
293 TInt CProxyConsole::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1) |
|
294 { |
|
295 return iConsole->Extension_(aExtensionId, a0, a1); |
|
296 } |
|
297 |
|
298 |
|
299 _LIT(KConsImpl,"econs"); |
|
300 #ifdef __WINS__ |
|
301 _LIT(KConsGuiImpl,"econseik"); |
|
302 _LIT(KConsNoGuiImpl,"econsnogui"); |
|
303 _LIT(KConsWservImpl, "econswserv"); |
|
304 #endif |
|
305 |
|
306 |
|
307 |
|
308 /** |
|
309 Creates a new console object. |
|
310 |
|
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. |
|
314 |
|
315 @return A pointer to the new console object. |
|
316 |
|
317 @see CConsoleBase::Create() |
|
318 */ |
|
319 EXPORT_C CConsoleBase *Console::NewL(const TDesC &aTitle,TSize aSize) |
|
320 { |
|
321 CProxyConsole *pC=new(ELeave) CProxyConsole; |
|
322 TInt r=pC->Construct(KConsImpl); |
|
323 if (r==KErrNone) |
|
324 r=pC->Create(aTitle,aSize); |
|
325 #ifdef __WINS__ |
|
326 if (r!=KErrNone) |
|
327 { |
|
328 delete pC; |
|
329 pC=new(ELeave) CProxyConsole; |
|
330 if (EmulatorNoGui()) |
|
331 { |
|
332 // try and create a dummy console via ECONSNOGUI |
|
333 r=pC->Construct(KConsNoGuiImpl); |
|
334 } |
|
335 else if (EmulatorMiniGui()) |
|
336 { |
|
337 // try and create Wserv console via ECONSWSERV |
|
338 r=pC->Construct(KConsWservImpl); |
|
339 } |
|
340 else |
|
341 { |
|
342 // try and create a GUI console via ECONSEIK instead |
|
343 r=pC->Construct(KConsGuiImpl); |
|
344 } |
|
345 if (r==KErrNone) |
|
346 r=pC->Create(aTitle,aSize); |
|
347 } |
|
348 #endif |
|
349 if (r!=KErrNone) |
|
350 { |
|
351 delete pC; |
|
352 User::Leave(r); |
|
353 } |
|
354 return(pC); |
|
355 } |