|
1 /* |
|
2 * Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eikconso.h> |
|
20 #include <gdi.h> |
|
21 #include <coecntrl.h> |
|
22 #include <coemain.h> |
|
23 |
|
24 EXPORT_C TSize CEikConsoleScreen::ScreenSize() const |
|
25 { |
|
26 return iConsoleSize; |
|
27 } |
|
28 |
|
29 EXPORT_C TInt CEikConsoleScreen::Create(const TDesC& aTitle,TSize aSize) |
|
30 { |
|
31 TRAPD(err,ConstructL(aTitle,aSize,EUseBackedUpWindow)); |
|
32 if (!err) |
|
33 DrawCursor(); |
|
34 return(err); |
|
35 } |
|
36 |
|
37 EXPORT_C void CEikConsoleScreen::Read(TRequestStatus& /*aStatus*/) |
|
38 { // not implemented - this part of base abstraction deliberately broken |
|
39 } |
|
40 |
|
41 EXPORT_C void CEikConsoleScreen::ReadCancel() |
|
42 { // not implemented - this part of base abstraction deliberately broken |
|
43 } |
|
44 |
|
45 EXPORT_C TKeyCode CEikConsoleScreen::KeyCode() const |
|
46 { // not implemented - this part of base abstraction deliberately broken |
|
47 return(EKeyNull); |
|
48 } |
|
49 |
|
50 EXPORT_C TUint CEikConsoleScreen::KeyModifiers() const |
|
51 { // not implemented - this part of base abstraction deliberately broken |
|
52 return(0); |
|
53 } |
|
54 |
|
55 EXPORT_C void CEikConsoleScreen::FlushChars() |
|
56 { |
|
57 if (!iWriteNow && iWriteBuffer.Length()) |
|
58 { |
|
59 iWriteNow=1; |
|
60 Write(iWriteBuffer); |
|
61 iWriteBuffer.SetLength(0); |
|
62 iWriteNow=0; |
|
63 } |
|
64 } |
|
65 |
|
66 //////////////////////////////////////////////////////////////////////////////////////// |
|
67 // |
|
68 // UTILITY FUNCTIONS |
|
69 // |
|
70 //////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
72 void cutmax(TInt &x,TInt max) {if (x>max) x=max;} |
|
73 void cutmin(TInt &x,TInt min) {if (x<min) x=min;} |
|
74 |
|
75 TUint SmallerPoint(TPoint a,TPoint b) |
|
76 { |
|
77 return ( a.iY < b.iY || (a.iY==b.iY && a.iX<=b.iX ) ); |
|
78 } |
|
79 |
|
80 TRect Clip(const TRect &aRect,const TRect &anOtherRect) |
|
81 // return aRect clipped to anOtherRect (i.e. true intersection) |
|
82 { |
|
83 TRect theRect = aRect; |
|
84 theRect.Intersection(anOtherRect); |
|
85 cutmax(theRect.iTl.iX,theRect.iBr.iX); |
|
86 cutmax(theRect.iTl.iY,theRect.iBr.iY); |
|
87 return theRect; |
|
88 } |
|
89 |
|
90 void CopyNormalisedRange(TRect &dstRange,const TRect &srcRange) |
|
91 // Make dstRange a normalized RANGE version of srcRange |
|
92 { |
|
93 dstRange=srcRange; |
|
94 if (SmallerPoint(dstRange.iBr,dstRange.iTl)) |
|
95 { dstRange.iTl=srcRange.iBr; dstRange.iBr=srcRange.iTl; } |
|
96 } |
|
97 |
|
98 //////////////////////////////////////////////////////////////////////////////////////// |
|
99 // |
|
100 // HISTORY ACCESS (LOW LEVEL) |
|
101 // |
|
102 //////////////////////////////////////////////////////////////////////////////////////// |
|
103 |
|
104 TPtr8 CEikConsoleScreen::MemAttPtr(TPoint aScrPos,TUint aLength) // aScrPos = SCREEN coordinates |
|
105 // returns TPtr8 within attribute history at given position for aLength 'characters' |
|
106 { |
|
107 return TPtr8(&iAttBuf[aScrPos.iX+((aScrPos.iY+iMaxAttExtra)*iConsoleSize.iWidth)],aLength,aLength); |
|
108 } |
|
109 |
|
110 TPtr CEikConsoleScreen::MemChrPtr(TPoint aScrPos,TUint aLength) // aScrPos = SCREEN coordinates |
|
111 // returns TPtr within character history at given position for aLength 'characters' |
|
112 { |
|
113 return TPtr(&iChrBuf[aScrPos.iX+((aScrPos.iY+iMaxChrExtra)*iConsoleSize.iWidth)],aLength,aLength); |
|
114 } |
|
115 |
|
116 //////////////////////////////////////////////////////////////////////////////////////// |
|
117 // |
|
118 // SCROLLBAR STUFF |
|
119 // |
|
120 //////////////////////////////////////////////////////////////////////////////////////// |
|
121 |
|
122 EXPORT_C TBool CEikConsoleScreen::UpdateScrollBars() |
|
123 // should be called whenever datasize and/or topleft changes |
|
124 // Return ETrue if, as a result, the visible window has changed |
|
125 { |
|
126 if (iConsoleControl) |
|
127 { |
|
128 TBool updatedScrollbars = EFalse; |
|
129 TRAP_IGNORE(updatedScrollbars = iConsoleControl->UpdateScrollbarsL(iConsoleSize+TSize(0,iNoChrExtra),iConsoleSize,iTopLeft-TPoint(0,iMaxChrExtra-iNoChrExtra))); |
|
130 if (updatedScrollbars) |
|
131 return RecalculateSize(); // datasize change may have resulted in a different visible window (due to scrollbars) |
|
132 } |
|
133 return EFalse; |
|
134 } |
|
135 |
|
136 //////////////////////////////////////////////////////////////////////////////////////// |
|
137 // |
|
138 // HISTORY STORAGE (HIGH LEVEL) |
|
139 // |
|
140 //////////////////////////////////////////////////////////////////////////////////////// |
|
141 |
|
142 // aPos = SCREEN coordinates |
|
143 void CEikConsoleScreen::MemScrPut(const TDesC &aString,TPoint aPos,TUint8 anAtt) |
|
144 { |
|
145 MemChrPtr(aPos,aString.Length()).Copy(aString); |
|
146 MemAttPtr(aPos,aString.Length()).Fill(anAtt); |
|
147 } |
|
148 |
|
149 |
|
150 // aRect = SCREEN coordinates |
|
151 void CEikConsoleScreen::MemScrClr(const TRect &aRect,TUint8 anAtt) |
|
152 { |
|
153 TUint8 clrAtt = anAtt; |
|
154 if ((clrAtt & ATT_COLORMASK) == 0) |
|
155 clrAtt &= (ATT_BOLD|ATT_INVERSE); // when clearing, only BOLD and INVERSE properties are relevant |
|
156 for (TInt y=aRect.iTl.iY;y<aRect.iBr.iY;y++) |
|
157 { |
|
158 TInt width = aRect.iBr.iX - aRect.iTl.iX; |
|
159 MemChrPtr(TPoint(aRect.iTl.iX,y),width).Fill(TChar(' ')); |
|
160 MemAttPtr(TPoint(aRect.iTl.iX,y),width).Fill(clrAtt); |
|
161 } |
|
162 } |
|
163 |
|
164 // anOldPt/aNewPt = SCREEN coordinates |
|
165 void CEikConsoleScreen::MemScrMove(TPoint anOldPt,TPoint aNewPt,TUint aLen) |
|
166 { |
|
167 MemChrPtr(aNewPt,aLen).Copy(MemChrPtr(anOldPt,aLen)); |
|
168 MemAttPtr(aNewPt,aLen).Copy(MemAttPtr(anOldPt,aLen)); |
|
169 } |
|
170 |
|
171 // aRect = SCREEN coordinates |
|
172 void CEikConsoleScreen::MemScrScroll(const TRect &aRect,TPoint aVector) |
|
173 { |
|
174 // determine the destination rectangle |
|
175 TRect normRect = aRect; |
|
176 normRect.Normalize(); |
|
177 TRect newRect = normRect; |
|
178 newRect.Move(aVector); |
|
179 newRect.Intersection(normRect); |
|
180 newRect.Intersection(TRect(iConsoleSize)); |
|
181 // now move from old rectangle to new rectangle... |
|
182 TInt width = newRect.iBr.iX - newRect.iTl.iX; |
|
183 if (width>0) |
|
184 { |
|
185 TInt height= newRect.iBr.iY - newRect.iTl.iY; |
|
186 if ( aVector.iY <= 0 ) |
|
187 { |
|
188 for ( TInt y=0;y<height;y++ ) |
|
189 MemScrMove(newRect.iTl-aVector+TPoint(0,y),newRect.iTl+TPoint(0,y),TUint(width)); |
|
190 } |
|
191 else |
|
192 { |
|
193 for ( TInt y=height-1;y>=0;y-- ) |
|
194 MemScrMove(newRect.iTl-aVector+TPoint(0,y),newRect.iTl+TPoint(0,y),TUint(width)); |
|
195 } |
|
196 } |
|
197 // now, all characters that are in normRect but not in newRect must become spaces, but WE KEEP THE ATTRIBUTES! |
|
198 for(TInt y=normRect.iTl.iY;y<normRect.iBr.iY;y++) |
|
199 for(TInt x=normRect.iTl.iX;x<normRect.iBr.iX;x++) |
|
200 if (!newRect.Contains(TPoint(x,y))) |
|
201 MemChrPtr(TPoint(x,y),1).Fill(TChar(' ')); |
|
202 } |
|
203 |
|
204 void CEikConsoleScreen::MemScrScrollUp(TUint aLines) |
|
205 { |
|
206 TInt toMove = iConsoleSize.iWidth * (iConsoleSize.iHeight + iMaxChrExtra - aLines); |
|
207 if (toMove>0) |
|
208 MemChrPtr(TPoint(0,-iMaxChrExtra),toMove).Copy(MemChrPtr(TPoint(0,aLines-iMaxChrExtra),toMove)); |
|
209 toMove = iConsoleSize.iWidth * (iConsoleSize.iHeight + iMaxAttExtra - aLines); |
|
210 if (toMove>0) |
|
211 MemAttPtr(TPoint(0,-iMaxAttExtra),toMove).Copy(MemAttPtr(TPoint(0,aLines-iMaxAttExtra),toMove)); |
|
212 // update nr of lines stored |
|
213 iNoChrExtra+=aLines; |
|
214 cutmax(iNoChrExtra,iMaxChrExtra); |
|
215 } |
|
216 |
|
217 EXPORT_C void CEikConsoleScreen::SetHistorySizeL(TUint aMaxChrExtra,TUint aMaxAttExtra) |
|
218 { |
|
219 FlushChars(); |
|
220 TText* chrBuf = (TText *) User::AllocL(iConsoleSize.iWidth * (aMaxChrExtra + iConsoleSize.iHeight) * sizeof(TText)); |
|
221 CleanupStack::PushL(chrBuf); |
|
222 TUint8* attBuf = (TUint8 *) User::AllocL(iConsoleSize.iWidth * (aMaxAttExtra + iConsoleSize.iHeight) * sizeof(TUint8)); |
|
223 CleanupStack::Pop(); // chrBuf |
|
224 iMaxChrExtra=aMaxChrExtra; |
|
225 iMaxAttExtra=aMaxAttExtra; |
|
226 User::Free(iChrBuf); |
|
227 iChrBuf=chrBuf; |
|
228 User::Free(iAttBuf); |
|
229 iAttBuf=attBuf; |
|
230 // clear on-screen buffers and set top left to top of screen |
|
231 iNoChrExtra=0; |
|
232 MemScrClr(TRect(iConsoleSize),0); |
|
233 iTopLeft.SetXY(0,iMaxChrExtra); |
|
234 // datasize + topleft have changed: |
|
235 UpdateScrollBars(); |
|
236 } |
|
237 |
|
238 //////////////////////////////////////////////////////////////////////////////////////// |
|
239 // |
|
240 // SETTINGS |
|
241 // |
|
242 //////////////////////////////////////////////////////////////////////////////////////// |
|
243 |
|
244 EXPORT_C void CEikConsoleScreen::SetKeepCursorInSight(TUint aFlag) |
|
245 { |
|
246 FlushChars(); |
|
247 iKeepCursorInSight=aFlag; |
|
248 } |
|
249 |
|
250 EXPORT_C void CEikConsoleScreen::SetPureCRLF(TUint aFlag) |
|
251 { |
|
252 FlushChars(); |
|
253 iPureCRLF=aFlag; |
|
254 } |
|
255 |
|
256 EXPORT_C void CEikConsoleScreen::SetAllPrintable(TUint aFlag) |
|
257 { |
|
258 FlushChars(); |
|
259 iAllPrintable=aFlag; |
|
260 } |
|
261 |
|
262 EXPORT_C void CEikConsoleScreen::SetScrollLock(TUint aFlag) |
|
263 { |
|
264 FlushChars(); |
|
265 iScrollLock=aFlag; |
|
266 } |
|
267 |
|
268 //////////////////////////////////////////////////////////////////////////////////////// |
|
269 // |
|
270 // CURSOR DISPLAY |
|
271 // |
|
272 //////////////////////////////////////////////////////////////////////////////////////// |
|
273 |
|
274 EXPORT_C TInt CEikConsoleScreen::HideCursor() |
|
275 { |
|
276 FlushChars(); |
|
277 if (iCursorBlinking) |
|
278 { |
|
279 if (iConsoleControl->IsFocused()) |
|
280 iConsoleControl->HideCursor(); |
|
281 iCursorBlinking=FALSE; |
|
282 return 1; |
|
283 } |
|
284 return 0; |
|
285 } |
|
286 |
|
287 EXPORT_C void CEikConsoleScreen::DrawCursorInSight() |
|
288 { |
|
289 DrawInSight(iCursor); |
|
290 DrawCursor(); |
|
291 } |
|
292 |
|
293 EXPORT_C void CEikConsoleScreen::DrawCursor() |
|
294 { |
|
295 if (iConsFlags&ENoInitialCursor) |
|
296 { |
|
297 iConsFlags&=(~ENoInitialCursor); |
|
298 return; |
|
299 } |
|
300 FlushChars(); |
|
301 if(iConsoleControl->IsFocused()) |
|
302 { |
|
303 TPoint theCursor = ScrToVis(iCursor); |
|
304 iConsoleControl->DrawCursor(theCursor); |
|
305 iCursorBlinking=TRUE; |
|
306 } |
|
307 } |
|
308 |
|
309 void CEikConsoleScreen::DrawCursorWhereNeeded() |
|
310 { |
|
311 // FlushChars() by one of the DrawCursor's |
|
312 if (iKeepCursorInSight) |
|
313 DrawCursorInSight(); |
|
314 else |
|
315 DrawCursor(); |
|
316 } |
|
317 |
|
318 //////////////////////////////////////////////////////////////////////////////////////// |
|
319 // |
|
320 // MoveTopLeft() and Redraw() |
|
321 // |
|
322 //////////////////////////////////////////////////////////////////////////////////////// |
|
323 |
|
324 EXPORT_C void CEikConsoleScreen::SetScrollBarVisibilityL(CEikScrollBarFrame::TScrollBarVisibility aHBarVisibility, CEikScrollBarFrame::TScrollBarVisibility aVBarVisibility) |
|
325 { |
|
326 if (iConsoleControl->SetScrollBarVisibilityL(aHBarVisibility,aVBarVisibility)) |
|
327 { |
|
328 if (UpdateScrollBars()) |
|
329 iConsoleControl->UpdateArea(); |
|
330 } |
|
331 } |
|
332 |
|
333 EXPORT_C void CEikConsoleScreen::MoveTopLeft(TPoint aVector) |
|
334 { |
|
335 TInt cursorHidden=HideCursor(); //FlushChars(); by hidecursor |
|
336 |
|
337 TPoint newTL = iTopLeft + aVector; |
|
338 cutmax(newTL.iX, iConsoleSize.iWidth - iVisSize.iWidth); |
|
339 cutmin(newTL.iX, 0); |
|
340 cutmax(newTL.iY, iMaxChrExtra + iConsoleSize.iHeight - iVisSize.iHeight); |
|
341 cutmin(newTL.iY, iMaxChrExtra - iNoChrExtra); |
|
342 |
|
343 TPoint vector = iTopLeft-newTL; |
|
344 iConsoleControl->ScrollChars(iVisWin,vector); |
|
345 iTopLeft=newTL; |
|
346 // topleft has changed: |
|
347 UpdateScrollBars(); |
|
348 |
|
349 // Following lines added for smooth redrawing: (@@@ are these really needed? @@@) |
|
350 if (vector.iX==0) |
|
351 { |
|
352 if (vector.iY>0) |
|
353 Redraw(TRect(0,0,iVisSize.iWidth,vector.iY)); |
|
354 else if (vector.iY<0) |
|
355 Redraw(TRect(0,iVisSize.iHeight+vector.iY,iVisSize.iWidth,iVisSize.iHeight)); |
|
356 } |
|
357 else if (vector.iY==0) |
|
358 { |
|
359 if (vector.iX>0) |
|
360 Redraw(TRect(0,0,vector.iX,iVisSize.iHeight)); |
|
361 else // if (vector.iX<0) |
|
362 Redraw(TRect(iVisSize.iWidth+vector.iX,0,iVisSize.iWidth,iVisSize.iHeight)); |
|
363 } |
|
364 |
|
365 if (cursorHidden) |
|
366 DrawCursor(); |
|
367 } |
|
368 |
|
369 // Redraw of a set of same-attribute characters (knows about double LEFT/RIGHT) |
|
370 void CEikConsoleScreen::RedrawChars(TInt anX,TInt anY,TInt aLength,TUint anAtt) |
|
371 { |
|
372 TUint att=anAtt; |
|
373 if ( (anX&1) && !(anAtt & ATT_COLORMASK) && (anAtt & ATT_DOUBLEMASK) ) |
|
374 att |= ATT_RIGHTMASK; // set RIGHT flag for any doublewidth non-color character in an odd column |
|
375 iConsoleControl->DrawChars(MemChrPtr(TPoint(anX,anY-iMaxChrExtra),aLength),TPoint(anX,anY)-iTopLeft,att); |
|
376 TRect sel; CopyNormalisedRange(sel,iSelection); sel.Move(0,iMaxChrExtra); |
|
377 InvertOverlap(sel.iTl,sel.iBr,TPoint(anX,anY),TPoint(anX+aLength,anY)); //}}} |
|
378 } |
|
379 |
|
380 // aRect = VISIBLE coordinates!!! |
|
381 EXPORT_C void CEikConsoleScreen::Redraw(const TRect &aRect) |
|
382 { |
|
383 TInt oldnow=iWriteNow; iWriteNow=1; |
|
384 |
|
385 TRect todoRect = Clip(aRect,iVisWin); |
|
386 if (RecalculateSize()) |
|
387 { |
|
388 iTopLeft = GetAnInSightPosition(iCursor); |
|
389 // topleft has changed |
|
390 if (UpdateScrollBars()) |
|
391 { |
|
392 iTopLeft = GetAnInSightPosition(iCursor); |
|
393 UpdateScrollBars(); |
|
394 } |
|
395 // might as well redraw the whole screen now... |
|
396 todoRect = iVisWin; |
|
397 } |
|
398 |
|
399 // convert visible to clipped absolute coordinates |
|
400 todoRect.Move(iTopLeft); |
|
401 cutmax(todoRect.iBr.iX,iConsoleSize.iWidth); |
|
402 cutmax(todoRect.iBr.iY,iMaxChrExtra + iConsoleSize.iHeight); |
|
403 |
|
404 // hide cursor while redarwing... |
|
405 TInt cursorHidden = HideCursor(); |
|
406 |
|
407 for( TInt y=todoRect.iTl.iY; y<todoRect.iBr.iY; y++) |
|
408 { |
|
409 TInt yAtt = y+iMaxAttExtra-iMaxChrExtra; // line within attribute buffer |
|
410 TInt x,start; |
|
411 TInt len=0; |
|
412 TUint att=ATT_MAXVALUE+1; // impossible value |
|
413 TUint attXY=ATT_NORMAL; // default attribute (in case there is no attribute history) |
|
414 for( x=start=todoRect.iTl.iX; x<todoRect.iBr.iX; x++) |
|
415 { |
|
416 if (yAtt>=0) |
|
417 attXY=iAttBuf[x+yAtt*iConsoleSize.iWidth]; |
|
418 if ( att != attXY ) |
|
419 { |
|
420 if (len) |
|
421 RedrawChars(start,y,len,att); |
|
422 start=x; att=attXY; len=0; |
|
423 } |
|
424 len++; |
|
425 } |
|
426 if (len) |
|
427 RedrawChars(start,y,len,att); |
|
428 } |
|
429 |
|
430 if (cursorHidden) |
|
431 DrawCursor(); |
|
432 iWriteNow=oldnow; |
|
433 } |
|
434 |
|
435 //////////////////////////////////////////////////////////////////////////////////////// |
|
436 // |
|
437 // Constructors/Destructors/Initializers |
|
438 // |
|
439 //////////////////////////////////////////////////////////////////////////////////////// |
|
440 |
|
441 EXPORT_C void CEikConsoleScreen::SetTitle(const TDesC& aTitle) |
|
442 { |
|
443 TRAP_IGNORE(SetTitleL(aTitle)); |
|
444 // !! what to do if err ?? |
|
445 } |
|
446 |
|
447 EXPORT_C void CEikConsoleScreen::SetTitleL(const TDesC& aTitle) |
|
448 { |
|
449 HBufC* oldTitle=iConsoleTitle; |
|
450 iConsoleTitle=aTitle.AllocL(); |
|
451 delete(oldTitle); |
|
452 } |
|
453 |
|
454 EXPORT_C void CEikConsoleScreen::ConstructL(const TDesC &aTitle,TInt aFlags)// use full screen |
|
455 { |
|
456 // if no CEikConsoleControl set yet, claim one |
|
457 iConsFlags=aFlags; |
|
458 if (!iConsoleControl) |
|
459 { |
|
460 CEikConsoleControl* consWin = new(ELeave) CEikConsoleControl; |
|
461 CleanupStack::PushL(consWin); |
|
462 consWin->ConstructL(aFlags); |
|
463 SetConsWin(consWin); |
|
464 CleanupStack::Pop(); // consWin |
|
465 } |
|
466 SetTitleL(aTitle); |
|
467 iConsoleSize=TSize(iConsoleControl->Size().iWidth/iConsoleControl->CharSize().iWidth, |
|
468 iConsoleControl->Size().iHeight/iConsoleControl->CharSize().iHeight); |
|
469 iKeepCursorInSight=TRUE; |
|
470 iWriteBuffer.SetLength(0); |
|
471 SetHistorySizeL(0,0); |
|
472 } |
|
473 |
|
474 EXPORT_C void CEikConsoleScreen::ConstructL(const TDesC &aTitle,TPoint aTopLeft,const TSize &aSize, |
|
475 TInt aFlags,TEikConsWinUnits aUnit) |
|
476 { |
|
477 // if no CEikConsoleControl set yet, claim one |
|
478 iConsFlags=aFlags; |
|
479 if (!iConsoleControl) |
|
480 { |
|
481 CEikConsoleControl* consWin = new(ELeave) CEikConsoleControl; |
|
482 CleanupStack::PushL(consWin); |
|
483 consWin->ConstructL(aTopLeft,aSize,aFlags,aUnit); |
|
484 SetConsWin(consWin); |
|
485 CleanupStack::Pop(); // consWin |
|
486 } |
|
487 SetTitleL(aTitle); |
|
488 if (aUnit==EEikConsWinInChars) |
|
489 iConsoleSize=aSize; |
|
490 else |
|
491 iConsoleSize=TSize(aSize.iWidth/iConsoleControl->CharSize().iWidth, |
|
492 aSize.iHeight/iConsoleControl->CharSize().iHeight); |
|
493 iKeepCursorInSight=TRUE; |
|
494 iWriteBuffer.SetLength(0); |
|
495 SetHistorySizeL(0,0); |
|
496 } |
|
497 |
|
498 EXPORT_C void CEikConsoleScreen::ConstructL(const TDesC &aTitle,const TSize &aSize,TInt aFlags,TEikConsWinUnits aUnit) |
|
499 // place the screen at TPoint(0,0) |
|
500 { |
|
501 ConstructL(aTitle,TPoint(0,0),aSize,aFlags,aUnit); |
|
502 } |
|
503 |
|
504 EXPORT_C CEikConsoleScreen::CEikConsoleScreen() |
|
505 { |
|
506 } |
|
507 |
|
508 EXPORT_C CEikConsoleScreen::~CEikConsoleScreen() |
|
509 { |
|
510 delete(iConsoleControl); |
|
511 User::Free(iChrBuf); |
|
512 User::Free(iAttBuf); |
|
513 User::Free(iConsoleTitle); |
|
514 } |
|
515 |
|
516 TBool CEikConsoleScreen::RecalculateSize() |
|
517 // returns ETrue if visible window has changed |
|
518 { |
|
519 TRect oldwin=iVisWin; |
|
520 iVisSize = iConsoleControl->VisibleSize(); |
|
521 cutmax(iVisSize.iWidth ,iConsoleSize.iWidth); |
|
522 cutmax(iVisSize.iHeight ,iConsoleSize.iHeight); |
|
523 iVisWin = TRect(iVisSize); |
|
524 return oldwin!=iVisWin; |
|
525 } |
|
526 |
|
527 EXPORT_C const TFontSpec& CEikConsoleScreen::Font() const |
|
528 { |
|
529 return iConsoleControl->Font(); |
|
530 } |
|
531 |
|
532 EXPORT_C void CEikConsoleScreen::SetFontL(const TFontSpec &aFontSpec) |
|
533 { |
|
534 FlushChars(); |
|
535 iConsoleControl->SetFontL(aFontSpec,NULL); |
|
536 } |
|
537 |
|
538 EXPORT_C void CEikConsoleScreen::SetConsWin(CEikConsoleControl *aConsWin) |
|
539 { |
|
540 FlushChars(); |
|
541 TBool calledBefore=EFalse; |
|
542 TInt cursorHidden=EFalse; |
|
543 if (iConsoleControl) |
|
544 { |
|
545 calledBefore=ETrue; |
|
546 cursorHidden=HideCursor(); |
|
547 delete(iConsoleControl); |
|
548 } |
|
549 iConsoleControl=aConsWin; |
|
550 iConsoleControl->SetRedrawer(this); |
|
551 if (RecalculateSize()) |
|
552 iTopLeft = GetAnInSightPosition(iCursor); |
|
553 if (calledBefore) // no need to update scrollbars the very first time |
|
554 UpdateScrollBars(); |
|
555 if (cursorHidden) |
|
556 DrawCursorWhereNeeded(); |
|
557 } |
|
558 |
|
559 //////////////////////////////////////////////////////////////////////////////////////// |
|
560 // |
|
561 // Cursor Stuff |
|
562 // |
|
563 //////////////////////////////////////////////////////////////////////////////////////// |
|
564 |
|
565 // clip cursor to SCREEN, allows X coordinate of LAST line to be 1 past the right marging! |
|
566 void CEikConsoleScreen::ClipCursor() |
|
567 { |
|
568 cutmin(iCursor.iX,0); |
|
569 cutmin(iCursor.iY, -iNoChrExtra); |
|
570 if (iCursor.iY<iConsoleSize.iHeight-1) |
|
571 cutmax(iCursor.iX,iConsoleSize.iWidth-1); |
|
572 else |
|
573 cutmax(iCursor.iX,iConsoleSize.iWidth); |
|
574 cutmax(iCursor.iY,iConsoleSize.iHeight-1); |
|
575 } |
|
576 |
|
577 // return SCREEN coordinates |
|
578 EXPORT_C TPoint CEikConsoleScreen::CursorPos() const |
|
579 { |
|
580 ((CEikConsoleScreen*)this)->FlushChars(); |
|
581 return iCursor; |
|
582 } |
|
583 |
|
584 // aPoint = SCREEN coordinates |
|
585 EXPORT_C void CEikConsoleScreen::SetCursorPosAbs(const TPoint &aPoint) |
|
586 { |
|
587 FlushChars(); |
|
588 iCursor = aPoint; |
|
589 ClipCursor(); |
|
590 if (iCursorBlinking) |
|
591 DrawCursorWhereNeeded(); |
|
592 else if (iKeepCursorInSight) |
|
593 DrawInSight(iCursor); |
|
594 } |
|
595 |
|
596 EXPORT_C void CEikConsoleScreen::SetCursorPosRel(const TPoint &aPoint) |
|
597 { |
|
598 FlushChars(); |
|
599 iCursor+=aPoint; |
|
600 ClipCursor(); |
|
601 if (iCursorBlinking) |
|
602 DrawCursorWhereNeeded(); |
|
603 else if (iKeepCursorInSight) |
|
604 DrawInSight(iCursor); |
|
605 } |
|
606 |
|
607 EXPORT_C void CEikConsoleScreen::SetCursorHeight(TInt aPercentage) |
|
608 // set cursor height to aPercentage, and redraw cursor (if it is blinking) |
|
609 { |
|
610 iConsoleControl->SetCursorHeight(aPercentage); |
|
611 if (iCursorBlinking) |
|
612 DrawCursorWhereNeeded(); |
|
613 else if (iKeepCursorInSight) |
|
614 DrawInSight(iCursor); |
|
615 } |
|
616 |
|
617 TPoint CEikConsoleScreen::GetAnInSightPosition(TPoint aPosition) const |
|
618 { |
|
619 TPoint newTL = iTopLeft; |
|
620 // past right margin: move so that cursor is at 3/4th of visible line screen |
|
621 if ( aPosition.iX >= newTL.iX + iVisSize.iWidth ) |
|
622 newTL.iX = aPosition.iX - (3*iVisSize.iWidth)/4; |
|
623 // past left margin: move so that cursor is at 1/4th of visible line screen |
|
624 if ( aPosition.iX < newTL.iX ) |
|
625 newTL.iX = aPosition.iX - iVisSize.iWidth/4; |
|
626 // keep within visible limits |
|
627 cutmax(newTL.iX,iConsoleSize.iWidth - iVisSize.iWidth); |
|
628 cutmin(newTL.iX,0); |
|
629 cutmax(newTL.iY,iMaxChrExtra + iConsoleSize.iHeight - iVisSize.iHeight); |
|
630 cutmax(newTL.iY,aPosition.iY + iMaxChrExtra); |
|
631 cutmin(newTL.iY,iMaxChrExtra + aPosition.iY - (iVisSize.iHeight-1)); |
|
632 cutmin(newTL.iY,0); |
|
633 return newTL; |
|
634 } |
|
635 |
|
636 EXPORT_C void CEikConsoleScreen::DrawInSight(TPoint aPosition) |
|
637 { |
|
638 FlushChars(); |
|
639 TPoint vector = GetAnInSightPosition(aPosition); |
|
640 if ( vector != iTopLeft ) |
|
641 MoveTopLeft(vector-iTopLeft); // FlushChars() by MoveTopLeft |
|
642 } |
|
643 |
|
644 EXPORT_C void CEikConsoleScreen::Up(TUint aCount) |
|
645 { |
|
646 FlushChars(); |
|
647 iCursor.iY-=aCount; |
|
648 ClipCursor(); |
|
649 DrawCursorWhereNeeded(); |
|
650 } |
|
651 |
|
652 EXPORT_C void CEikConsoleScreen::Down(TUint aCount) |
|
653 { |
|
654 FlushChars(); |
|
655 iCursor.iY+=aCount; |
|
656 ClipCursor(); |
|
657 DrawCursorWhereNeeded(); |
|
658 } |
|
659 |
|
660 EXPORT_C void CEikConsoleScreen::Left(TUint aCount) |
|
661 { |
|
662 FlushChars(); |
|
663 iCursor.iY-=(aCount / iConsoleSize.iWidth ); |
|
664 iCursor.iX-=(aCount % iConsoleSize.iWidth ); |
|
665 while (iCursor.iX<0) |
|
666 { iCursor.iY--; iCursor.iX+=iConsoleSize.iWidth; } |
|
667 if (iCursor.iY<(-iNoChrExtra)) |
|
668 iCursor.SetXY(0,-iNoChrExtra); |
|
669 ClipCursor(); |
|
670 DrawCursorWhereNeeded(); |
|
671 } |
|
672 |
|
673 EXPORT_C void CEikConsoleScreen::Right(TUint aCount) |
|
674 { |
|
675 FlushChars(); |
|
676 iCursor.iX += aCount; |
|
677 iCursor.iY += (iCursor.iX / iConsoleSize.iWidth); |
|
678 iCursor.iX %= iConsoleSize.iWidth; |
|
679 if (iCursor.iY>=iConsoleSize.iHeight) |
|
680 iCursor.iX=iConsoleSize.iWidth; |
|
681 ClipCursor(); |
|
682 DrawCursorWhereNeeded(); |
|
683 } |
|
684 |
|
685 //////////////////////////////////////////////////////////////////////////////////////// |
|
686 // |
|
687 // GRAPHICS |
|
688 // |
|
689 //////////////////////////////////////////////////////////////////////////////////////// |
|
690 |
|
691 |
|
692 EXPORT_C HBufC *CEikConsoleScreen::RetrieveL(const TRect &aSelection) |
|
693 { |
|
694 FlushChars(); |
|
695 TRect sel=aSelection; |
|
696 TInt len = (sel.iBr.iX-sel.iTl.iX)+iConsoleSize.iWidth*(sel.iBr.iY-sel.iTl.iY); |
|
697 if (len==0) |
|
698 return NULL; |
|
699 if (len<0) |
|
700 return MemChrPtr(sel.iBr,-len).AllocL(); |
|
701 return MemChrPtr(sel.iTl, len).AllocL(); |
|
702 } |
|
703 |
|
704 // aRect = SCREEN coordinates |
|
705 EXPORT_C void CEikConsoleScreen::ClearChars(const TRect &aRect,TUint anAtt) |
|
706 { |
|
707 FlushChars(); |
|
708 MemScrClr(aRect,TUint8(anAtt)); |
|
709 iConsoleControl->ClearChars(Clip(ScrToVis(aRect),TRect(iConsoleSize)),anAtt); |
|
710 } |
|
711 |
|
712 EXPORT_C void CEikConsoleScreen::ScrollChars(const TRect &anArea,const TPoint &aVector) |
|
713 { |
|
714 FlushChars(); |
|
715 MemScrScroll(anArea,aVector); |
|
716 iConsoleControl->ScrollChars(Clip(ScrToVis(anArea),TRect(iConsoleSize)),aVector); |
|
717 } |
|
718 |
|
719 EXPORT_C void CEikConsoleScreen::ClearScreen() |
|
720 { |
|
721 TInt cursorHidden = HideCursor(); //FlushChars(); by hidecursor |
|
722 iCursor.SetXY(0,0); |
|
723 SelectCursor(); |
|
724 iTopLeft.SetXY(0,iMaxChrExtra); |
|
725 ClearChars(TRect(iConsoleSize),iAtt); |
|
726 // datasize + topleft changed |
|
727 UpdateScrollBars(); // wont ever actually leave |
|
728 if (cursorHidden) |
|
729 DrawCursorWhereNeeded(); |
|
730 else if (iKeepCursorInSight) |
|
731 DrawInSight(iCursor); |
|
732 } |
|
733 |
|
734 EXPORT_C void CEikConsoleScreen::SetAtt(TUint anAtt) |
|
735 { |
|
736 // never store the LEFT/RIGHT flag |
|
737 TUint newAtt = anAtt; |
|
738 if (!(anAtt & ATT_COLORMASK)) |
|
739 newAtt &= ATT_IGNORE_RIGHTLEFT; |
|
740 if (newAtt!=iAtt) |
|
741 { |
|
742 FlushChars(); |
|
743 iAtt = newAtt; |
|
744 } |
|
745 } |
|
746 |
|
747 EXPORT_C void CEikConsoleScreen::SetAtt(TUint aForegroundGrey16,TUint aBackgroundGrey16) |
|
748 { |
|
749 SetAtt( ATT_COLORMASK | (aForegroundGrey16 & 0x0F) | ((((aBackgroundGrey16/2) & 0x0F)<<4)) ); |
|
750 } |
|
751 |
|
752 EXPORT_C void CEikConsoleScreen::ClearToEndOfLine() |
|
753 { |
|
754 FlushChars(); //needed before using iCursor! |
|
755 ClearChars(TRect(iCursor.iX,iCursor.iY,iConsoleSize.iWidth,iCursor.iY+1),iAtt); |
|
756 } |
|
757 |
|
758 |
|
759 EXPORT_C void CEikConsoleScreen::Cr() |
|
760 { |
|
761 // !! removed by DavidW, to match E32 console behaviour -- ClearToEndOfLine(); //FlushChars(); by clreol |
|
762 iCursor.iX=0; |
|
763 } |
|
764 |
|
765 |
|
766 EXPORT_C void CEikConsoleScreen::Lf() |
|
767 { |
|
768 TInt cursorHidden=HideCursor(); //FlushChars(); by hidecursor |
|
769 iCursor.iY++; |
|
770 if (iCursor.iY >= iConsoleSize.iHeight) |
|
771 { |
|
772 iCursor.iY--; |
|
773 if (!iScrollLock) |
|
774 { |
|
775 //move selection along too! |
|
776 iSelection.iTl.iY--; cutmin(iSelection.iTl.iY,-iNoChrExtra); |
|
777 iSelection.iBr.iY--; cutmin(iSelection.iBr.iY,-iNoChrExtra); |
|
778 // scroll in memory and clear new bottom line |
|
779 MemScrScrollUp(); |
|
780 UpdateScrollBars(); |
|
781 MemScrClr(TRect(0,iConsoleSize.iHeight-1,iConsoleSize.iWidth,iConsoleSize.iHeight),TUint8(iAtt)); |
|
782 iConsoleControl->ScrollChars(iVisWin, TPoint(0,-1)); |
|
783 Redraw(TRect(0,iVisSize.iHeight-1,iVisSize.iWidth,iVisSize.iHeight)); |
|
784 } |
|
785 // restore cursor |
|
786 } |
|
787 if (cursorHidden) |
|
788 DrawCursorWhereNeeded(); |
|
789 else if (iKeepCursorInSight) |
|
790 DrawInSight(iCursor); |
|
791 } |
|
792 |
|
793 EXPORT_C void CEikConsoleScreen::Write(const TDesC &aText) |
|
794 { |
|
795 |
|
796 if (aText.Length()==0) |
|
797 return; |
|
798 |
|
799 // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
|
800 // consecutive write handling: save characters until |
|
801 // - any OTHER command is called that MUST come AFTER this write |
|
802 // - we got more than we can buffer |
|
803 // - we encounter a CR/LF as last character (?) |
|
804 retry: |
|
805 if (iWriteNow==0) |
|
806 { |
|
807 if (iWriteBuffer.Length() + aText.Length() < 256) |
|
808 { |
|
809 iWriteBuffer.Append(aText); |
|
810 /* !! Prevents eg EShell from flushing when using Up arrow (prev command coz no trailing CR/LF |
|
811 // check for CR/LF as last character @@@ should we? |
|
812 TInt c = iWriteBuffer[ iWriteBuffer.Length()-1 ]; |
|
813 if ( c==EKeyLineFeed || c==EKeyEnter ) |
|
814 */ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|
815 FlushChars(); |
|
816 return; |
|
817 } |
|
818 else |
|
819 { |
|
820 FlushChars(); |
|
821 if ( aText.Length() < 256 ) |
|
822 goto retry; |
|
823 // ELSE: write iWriteNow! |
|
824 } |
|
825 } |
|
826 |
|
827 // no cursor while we draw, and forget selection |
|
828 TInt cursorHidden=HideCursor(); |
|
829 InvertRange(iSelection); |
|
830 |
|
831 for ( TInt i=0; i<aText.Length(); ) |
|
832 { |
|
833 // current line full? |
|
834 if (iCursor.iX>=iConsoleSize.iWidth) |
|
835 { |
|
836 iCursor.iX=0; // instead of Cr() |
|
837 Lf(); |
|
838 continue; |
|
839 } |
|
840 // there are characters to be printed... |
|
841 TChar c = aText[i]; |
|
842 if ( c<32 && iAllPrintable==FALSE ) |
|
843 { |
|
844 switch (c) |
|
845 { |
|
846 // next char is a FF? |
|
847 case EKeyBell: |
|
848 // BELL @@@ |
|
849 break; |
|
850 case EKeyBackspace: |
|
851 Left(); // BS |
|
852 break; |
|
853 case EKeyTab: //TAB |
|
854 FlushChars(); |
|
855 for(;;) |
|
856 { |
|
857 // move character forward (stop at right margin) |
|
858 if (iCursor.iX<iConsoleSize.iWidth) |
|
859 iCursor.iX++; |
|
860 else |
|
861 break; |
|
862 // break at the first tab that is encountered |
|
863 if ( iCursor.iX%8==0) |
|
864 break; |
|
865 } |
|
866 break; |
|
867 case EKeyLineFeed: |
|
868 if (!iPureCRLF) |
|
869 Cr(); |
|
870 Lf(); // LF |
|
871 break; |
|
872 case EKeyFormFeed: |
|
873 ClearScreen(); // FF |
|
874 break; |
|
875 case EKeyEnter: |
|
876 if (iPureCRLF) |
|
877 Cr(); // CR |
|
878 break; |
|
879 } |
|
880 i++; |
|
881 } |
|
882 else |
|
883 { |
|
884 // Determine how many characters can be output at once |
|
885 TUint8 att = TUint8(iAtt); |
|
886 TInt avail = ( iConsoleSize.iWidth - iCursor.iX ); |
|
887 TInt outnow=0; |
|
888 if (iAllPrintable) outnow=1; |
|
889 while ( outnow<avail && i+outnow < aText.Length() && aText[i+outnow]>=32 ) |
|
890 outnow++; |
|
891 MemScrPut(aText.Mid(i,outnow),iCursor,att); |
|
892 |
|
893 // now let's see how many characters need actually be drawn... |
|
894 TPoint pos=ScrToVis(iCursor); |
|
895 if (pos.iY>=0 && pos.iY<iVisSize.iHeight) |
|
896 { |
|
897 TUint start=i; |
|
898 TInt len=outnow; |
|
899 if (pos.iX<0) |
|
900 { |
|
901 start-=pos.iX; len+=pos.iX; pos.iX=0; |
|
902 } |
|
903 cutmax(len,iVisSize.iWidth-pos.iX); |
|
904 if (len>0) |
|
905 { |
|
906 TUint drawAtt = att; |
|
907 if ( !(drawAtt & ATT_COLORMASK) && (drawAtt & ATT_DOUBLEMASK) && ((pos.iX+iTopLeft.iX) &1) ) |
|
908 drawAtt |= ATT_RIGHTMASK; // set RIGHT flag for any doublewidth non-color character in an odd column |
|
909 iConsoleControl->DrawChars(aText.Mid(start,len),pos,drawAtt); |
|
910 } |
|
911 } |
|
912 |
|
913 iCursor.iX += outnow; |
|
914 i+=outnow; |
|
915 } |
|
916 } |
|
917 |
|
918 InvertRange(iSelection); |
|
919 if (iCursor.iX==iConsoleSize.iWidth) |
|
920 if (iCursor.iY<iConsoleSize.iHeight-1) |
|
921 { iCursor.iX=0; iCursor.iY++; } |
|
922 if (cursorHidden) |
|
923 DrawCursorWhereNeeded(); |
|
924 else if (iKeepCursorInSight) |
|
925 DrawInSight(iCursor); |
|
926 } |
|
927 |
|
928 |
|
929 //////////////////////////////////////////////////////////////////////////////////////// |
|
930 // |
|
931 // SELECTION ROUTINES (LOW LEVEL) |
|
932 // |
|
933 //////////////////////////////////////////////////////////////////////////////////////// |
|
934 TPoint CEikConsoleScreen::ScrToVis(TPoint aPoint) // ^screen -> ^visible (unclipped) |
|
935 { |
|
936 return aPoint + TPoint(0,iMaxChrExtra) - iTopLeft; |
|
937 } |
|
938 |
|
939 TRect CEikConsoleScreen::ScrToVis(const TRect &aRect) // ^screen -> ^visible (clip iVisWin) |
|
940 { |
|
941 return Clip(TRect(ScrToVis(aRect.iTl),ScrToVis(aRect.iBr)),iVisWin); |
|
942 } |
|
943 |
|
944 void CEikConsoleScreen::InvertRange(const TRect &aRange) // ^screen |
|
945 { |
|
946 TRect aRect; CopyNormalisedRange(aRect,aRange); |
|
947 for ( TInt y=aRect.iTl.iY; y<=aRect.iBr.iY; y++ ) |
|
948 { |
|
949 TInt from = (y==aRect.iTl.iY) ? aRect.iTl.iX : 0; |
|
950 TInt upto = (y==aRect.iBr.iY) ? aRect.iBr.iX : iConsoleSize.iWidth; |
|
951 if (from<upto) |
|
952 iConsoleControl->InvertChars(ScrToVis(TRect(from,y,upto,y+1))); |
|
953 } |
|
954 } |
|
955 |
|
956 void CEikConsoleScreen::InvertOverlap(TPoint aStart,TPoint aEnd,TPoint bStart,TPoint bEnd) // ^absolute |
|
957 { |
|
958 if (SmallerPoint(aEnd,aStart)) |
|
959 return; |
|
960 if (SmallerPoint(bEnd,bStart)) |
|
961 return; |
|
962 TPoint start = SmallerPoint(aStart,bStart) ? bStart : aStart; |
|
963 TPoint end = SmallerPoint(aEnd ,bEnd ) ? aEnd : bEnd; |
|
964 if (SmallerPoint(end,start)) |
|
965 return; |
|
966 TRect rect(start,end); |
|
967 rect.Move(0,-iMaxChrExtra); |
|
968 InvertRange(rect); // ^absolute -> ^screen |
|
969 } |
|
970 |
|
971 |
|
972 EXPORT_C void CEikConsoleScreen::SetSelection(const TRect &aSelection) // ^screen |
|
973 { |
|
974 FlushChars(); |
|
975 TRect oldRange,newRange; |
|
976 CopyNormalisedRange(oldRange,iSelection); // normalise previous selection |
|
977 CopyNormalisedRange(newRange,aSelection); // normalise new selection |
|
978 iSelection=aSelection; |
|
979 |
|
980 oldRange.iTl.iY+=iMaxChrExtra; |
|
981 oldRange.iBr.iY+=iMaxChrExtra; |
|
982 newRange.iTl.iY+=iMaxChrExtra; |
|
983 newRange.iBr.iY+=iMaxChrExtra; |
|
984 |
|
985 InvertOverlap(TPoint(0,0), newRange.iTl,oldRange.iTl,oldRange.iBr ); // devert beforenew |
|
986 InvertOverlap(newRange.iTl,newRange.iBr,TPoint(0,0),oldRange.iTl); // invert beforeold |
|
987 InvertOverlap(newRange.iTl,newRange.iBr,oldRange.iBr,TPoint(0,iMaxChrExtra)+iConsoleSize ); // invert afterold |
|
988 InvertOverlap(newRange.iBr,TPoint(0,iMaxChrExtra)+iConsoleSize,oldRange.iTl,oldRange.iBr); // devert afternew |
|
989 } |
|
990 |
|
991 EXPORT_C void CEikConsoleScreen::SelectCursor() |
|
992 { |
|
993 FlushChars(); |
|
994 SetSelection(TRect(iCursor,iCursor)); |
|
995 } |
|
996 |
|
997 EXPORT_C TRect CEikConsoleScreen::Selection() // ^screen |
|
998 { |
|
999 FlushChars(); |
|
1000 return iSelection; |
|
1001 } |
|
1002 |
|
1003 |