2 * Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #if !defined(__EIKCONSO_H__)
20 #define __EIKCONSO_H__
22 #if !defined(__E32CONS_H__)
26 #if !defined(__EIKSBOBS_H__)
30 #if !defined(__EIKSBFRM_H__)
34 #include <AknControl.h>
36 #define ATT_DOUBLEWIDTH 0x60
37 #define ATT_DOUBLETOP 0x20
38 #define ATT_DOUBLEBOTTOM 0x40
39 ////////////////////////////////////////////
40 #define ATT_ITALIC 0x08
41 #define ATT_INVERSE 0x04
42 #define ATT_UNDERLINE 0x02
44 ////////////////////////////////////////////
45 #define ATT_COLORMASK 0x80 // &x!=0 : color
46 #define ATT_DOUBLEMASK 0x60 // &x : only the bits relevant for doublewidth/doubleheight
47 #define ATT_RIGHTMASK 0x10 // |x to set RIGHT indicator
48 #define ATT_IGNORE_RIGHTLEFT 0xEF // &x to clear the RIGHT/LEFT flag
49 #define ATT_IGNORE_INVERSE 0xFB // &x to clear the INVERSE flag
50 ////////////////////////////////////////////
51 #define ATT_MAXVALUE 0xFF // all flags set (maximum value of attribute byte)
52 #define ATT_NORMAL 0 // the default character attribute
61 /** CEikConsoleScreen()
63 @param aBuffer String that needs to be clipped. will be modified by this call
64 @param aFont Font used in the code
65 @param aMaxWidthInPixels Maximum length of text that will not be clipped.
66 @param aDir Where is the text clipped from. EDoNotClip, EClipFromEnd, EClipFromBeginning.
67 @param aClipWidth The length of the text after clipping. KDefaultClipWidth will make it use aMaxWidthInPixels.
68 @param aClipString The representation of three dots. (not really used anywhere - use the default value always or "")
70 returns true if the text was clipped and 3 dots were added.
72 class CEikConsoleControl;
73 class CEikConsoleScreen : public CConsoleBase
78 EUseBackedUpWindow =0x1,
83 * CEikConsoleScreen() constructor
85 IMPORT_C CEikConsoleScreen();
87 * CEikConsoleScreen() destructor
89 IMPORT_C ~CEikConsoleScreen();
91 /** Create() Creates a console and sets title and size
93 * @param aTitle Title of the console
94 * @param aSize Size of the console in pixels
98 IMPORT_C TInt Create(const TDesC& aTitle,TSize aSize);
102 IMPORT_C void Read(TRequestStatus& aStatus);
106 IMPORT_C void ReadCancel();
110 IMPORT_C TKeyCode KeyCode() const;
114 IMPORT_C TUint KeyModifiers() const;
115 /** ConstructL() Constructs a console and sets title
117 * @param aTitle Title of the console
118 * @param aFlags Flags, for example EUseBackedUpWindow or ENoInitialCursor
120 IMPORT_C void ConstructL(const TDesC &aTitle,TInt aFlags);// use full screen
121 /** ConstructL() Constructs a console and sets title and size
123 * @param aTitle Title of the console
124 * @param aSize Size of the console in pixels
125 * @param aFlags Flags, for example EUseBackedUpWindow or ENoInitialCursor
126 * @param aUnit Unit of the console
128 IMPORT_C void ConstructL(const TDesC &aTitle,const TSize &aSize,TInt aFlags,TEikConsWinUnits aUnit=EEikConsWinInChars); // place the screen at TPoint(0,0)
129 /** ConstructL() Constructs a console and sets title and position and size
131 * @param aTitle Title of the console
132 * @param aTopLeft TopLeft corner of the console window
133 * @param aSize Size of the console in pixels
134 * @param aFlags Flags, for example EUseBackedUpWindow or ENoInitialCursor
135 * @param aUnit Unit of the console
137 IMPORT_C void ConstructL(const TDesC &aTitle,TPoint aTopLeft,const TSize &aSize,TInt aFlags,TEikConsWinUnits aUnit=EEikConsWinInChars);
138 /** SetConsWin() Sets console window
140 * @param aConsWin Console control
142 IMPORT_C void SetConsWin(CEikConsoleControl *aConsWin); // use if you don't want WHOLE screen
143 /** ConsoleControl() fetching console control
145 * Returns console control
147 inline CEikConsoleControl* ConsoleControl() const {return iConsoleControl;};
149 /** SetTitle() Set title of the console
151 * @param aTitle Title of the console
153 IMPORT_C void SetTitle(const TDesC &aTitle);
154 /** SetTitle() Set title of the console
156 * @param aTitle Title of the console
158 IMPORT_C void SetTitleL(const TDesC &aTitle);
159 /** Title() Gets title of the console
161 * returns Title of the console
163 inline HBufC *Title() const {return iConsoleTitle;};
165 /** ScreenSize() Gets size of the screen
167 * returns Size of the screen in pixels
169 IMPORT_C TSize ScreenSize() const;
170 /** FlushChars() Updates the character buffers
172 IMPORT_C void FlushChars(); //new
173 /** CursorPos() Cursor position getter
174 * returns cursor position
176 IMPORT_C TPoint CursorPos() const;
177 /** SetCursorPosAbs Moving cursor to absolute position
179 * @param aPoint Position in absolute coordinates
181 IMPORT_C void SetCursorPosAbs(const TPoint &aPoint);
182 /** SetCursorPosRel Moving cursor to relative position
184 * @param aPoint Position in relative coordinates
186 IMPORT_C void SetCursorPosRel(const TPoint &aPoint);
187 /** SetCursorHeight changes cursor height
189 * @param aPercentage Cursor height relative to character height
191 IMPORT_C void SetCursorHeight(TInt aPercentage);
192 /** Write() Writes text to the console
194 * @param aDes Text to be written to the console
196 IMPORT_C void Write(const TDesC &aDes);
197 /** ClearScreen() Clears the console screen
200 IMPORT_C void ClearScreen();
201 /** ClearToEndOfLine() Clears from cursor position to end of the line
204 IMPORT_C void ClearToEndOfLine();
205 /** ClearChars() Clears characters within rectangle matching attributes
207 * @param aRect Rectangle in pixels
208 * @param aCharacterAttributes Matching character attributes
210 IMPORT_C void ClearChars(const TRect &aRect,TUint aCharacterAttributes);
211 /** HideCursor() Hides cursor
213 * @return nonzero if cursor was not visible
215 IMPORT_C TInt HideCursor(); // returns nonzero if cursor wasn't visible
216 /** DrawCursor() Draws cursor
218 IMPORT_C void DrawCursor();
219 /** DrawInSight Moves topleft corner
221 * @param aPosition New position for insight
223 IMPORT_C void DrawInSight(TPoint aPosition);
224 /** DrawCursorInSight() Draws cursor and insight
226 IMPORT_C void DrawCursorInSight();
229 * @param aCount Number of steps to move
231 IMPORT_C void Up(TUint aCount=1);
233 * @param aCount Number of steps to move
235 IMPORT_C void Down(TUint aCount=1);
236 /** Move cursor right
237 * @param aCount Number of steps to move
239 IMPORT_C void Right(TUint aCount=1);
241 * @param aCount Number of steps to move
243 IMPORT_C void Left(TUint aCount=1);
247 /** Insert a linefeed
250 /** Scroll characters
251 * @param anArea Area to scroll
252 * @param aVector How much to scroll
254 IMPORT_C void ScrollChars(const TRect &anArea,const TPoint &aVector);
256 /** Redraw a rectangle
257 * @param aRect Rectangle to redraw
259 IMPORT_C void Redraw(const TRect &aRect); // called by CEikConsoleControl
261 * @param aVector new position of topleft
263 IMPORT_C void MoveTopLeft(TPoint aVector); // called by CEikConsoleControl
265 /** Size of the history
266 * @return lines stored for history buffer
268 inline TUint HistorySize() const {return iNoChrExtra;}; // lines ACTUALLY stored
269 /** Set history buffer size
270 * @param aMaxChrExtra lines allocated for history
271 * @param aMaxAttExtra attributed lines allocated for history
273 IMPORT_C void SetHistorySizeL(TUint aMaxChrExtra,TUint aMaxAttExtra); // lines of back-scroll history resp. lines of ATTRIBUTED backscroll history (aMaxAttExtra<=aMaxChrExtra)
276 * @returns attributes
278 inline TUint Att() const {return iAtt;};
281 * @param aCharacterAttributes Attributes for characters
283 IMPORT_C void SetAtt(TUint aCharacterAttributes);
285 * @param aForegroundGray16 Grey16 attributes for foreground
286 * @param aBackgroundGray16 Grey16 attribuets for background
288 IMPORT_C void SetAtt(TUint aForegroundGray16,TUint aBackgroundGray16);
290 /** SetFontL() Sets the font for console
291 * @param aFontDesc font specification
293 IMPORT_C void SetFontL(const TFontSpec &aFontDesc);
294 /** Font() Gets the used font
295 * @returns font specification
297 IMPORT_C const TFontSpec& Font() const;
299 /** SetSelection() Sets the selection position
300 * @param aRange range of the selection
302 IMPORT_C void SetSelection(const TRect &aRange);
303 /** SelectCursor() Sets empty selection starting and ending at cursor position
305 IMPORT_C void SelectCursor(); // empty selection starting and ending at cursor position
306 /** Selection() Get selection position
307 * @return selection position
309 IMPORT_C TRect Selection();
310 /** RetrieveL() returns selected text
311 * @param aRange selection
312 * @return text in descriptor
314 IMPORT_C HBufC *RetrieveL(const TRect &aRange); // returns selection in newly allocated buffer
316 /** SetPureCRLF() sets pure flag
319 IMPORT_C void SetPureCRLF(TUint aFlag);
320 /** SetAllPrintable() sets all printable flag
323 IMPORT_C void SetAllPrintable(TUint aFlag);
324 /** SetScrollLock() sets scroll lock flag
327 IMPORT_C void SetScrollLock(TUint aFlag);
328 /** SetKeepCursorInSight() sets cursor in sight flag
331 IMPORT_C void SetKeepCursorInSight(TUint aFlag);
332 /** SetScrollBarVisibilityL() sets scrollbar visibility
333 * @param aHBarVisibility horizontal scrollbar visibility
334 * @param aVBarVisibility vertical scrollbar visibility
336 IMPORT_C void SetScrollBarVisibilityL(CEikScrollBarFrame::TScrollBarVisibility aHBarVisibility, CEikScrollBarFrame::TScrollBarVisibility aVBarVisibility);
337 /** UpdateScrollBars() updates scrollbars
340 IMPORT_C TBool UpdateScrollBars();
343 // high-level history manipulation
344 void MemScrPut(const TDesC &aString,TPoint aPos,TUint8 aCharacterAttributes);
345 void MemScrClr(const TRect &aRect,TUint8 aCharacterAttributes);
346 void MemScrScrollUp(TUint aLines=1);
347 void MemScrMove(TPoint anOldPt,TPoint aNewPt,TUint aLen);
348 void MemScrScroll(const TRect &aRect,TPoint aVector);
349 // low-level history access
350 TPtr MemChrPtr(TPoint aPos,TUint aLen);
351 TPtr8 MemAttPtr(TPoint aPos,TUint aLen);
352 // console screen-to-visible window conversion
353 TPoint ScrToVis(TPoint aPoint);
354 TRect ScrToVis(const TRect &aRect);
355 // recalculates iVisSize and iVisWin
356 TBool RecalculateSize();
357 // calculate a TopLeft that would put aPosition in-sight
358 TPoint GetAnInSightPosition(TPoint aPosition) const;
359 // draw cursor or draw cursor in sight, depending on iKeepCursorInSight
360 void DrawCursorWhereNeeded();
361 // smart cursor-clipping: clips cursor to within screen, but allows it to be past the last character
363 // redraw characters with doublewidth LEFT/RIGHT flag set depending on odd/even columns
364 void RedrawChars(TInt anX,TInt anY,TInt aLength,TUint aCharacterAttributes);
365 // routines needed for selection
366 void InvertOverlap(TPoint aStart,TPoint aEnd,TPoint bStart,TPoint bEnd);
367 void InvertRange(const TRect &aRect);
370 CEikConsoleControl *iConsoleControl;// console window (handles redraw events)
371 TSize iConsoleSize; // size of console in characters (e.g. 80x24)
372 HBufC *iConsoleTitle; // console title
373 TRect iSelection; // current selection
374 TPoint iCursor; // current cursor position
375 TUint iAtt; // current character attribute
377 TInt iWriteNow; // if FALSE, Write()-calls can be buffered
378 TBuf<256> iWriteBuffer; // the Write() buffer
380 TInt iMaxChrExtra; // max nr of extra lines of characters stored
381 TInt iNoChrExtra; // actual nr of extra lines of characters stored
382 TInt iMaxAttExtra; // max nr of extra lines of character attributes stored
383 TText *iChrBuf; // character history
384 TUint8 *iAttBuf; // attribute history
386 TPoint iTopLeft; // coordinates of top left corner of visual display
387 TRect iVisWin; // RECT visible window
388 TSize iVisSize; // SIZE visible window
391 TUint iPureCRLF; // FALSE by default. If TRUE, CR and LF are "pure"
392 TUint iAllPrintable; // FALSE by default. If TRUE, even chars 0-31 are printed
393 TUint iScrollLock; // FALSE by default. If TRUE, will not scroll at bottom line
394 TUint iKeepCursorInSight; // TRUE by default. If FALSE, cursor may be offscreen after a Write()
395 TUint iCursorBlinking; // TRUE if cursor should be visible (i.e. user WANTS it to be visible)
400 class CEikConsoleControl : public CAknControl, public MEikScrollBarObserver
403 // constructors, destructors, initialization
406 IMPORT_C CEikConsoleControl();
409 IMPORT_C ~CEikConsoleControl();
412 IMPORT_C void ConstructL(TInt aFlags);
415 IMPORT_C void ConstructL(TPoint aTopLeft,const TSize &aSize,TInt aFlags,TEikConsWinUnits aUnit);
417 * @param aConsole console screen
419 IMPORT_C void SetRedrawer(CEikConsoleScreen *aConsole);
422 /** SetFontL() sets the console font
423 * @param aFontSpec font specification
424 * @param aFont font instance
426 IMPORT_C void SetFontL(const TFontSpec &aFontSpec,const CFbsFont* aFont); // change to font aFontSpec
427 /** Font() gets font specification
429 inline const TFontSpec& Font() const {return iFontSpec;}; // returns current fontspec
431 /** CharSize() gets character size
433 inline const TSize& CharSize() const {return iCharSize;};
434 /** VisibibleSize() gets visible size
437 IMPORT_C TSize VisibleSize() const; // returns maximal visible nr of visible characters
440 /** SetCursorHeight() Sets cursor height
441 * @param aPercentage value 0..100%
443 IMPORT_C void SetCursorHeight(TUint aPercentage); // set cursor height (0-100%)
444 /** DrawCursor Draws cursor at position
445 * @param aPosition position
447 IMPORT_C void DrawCursor(TPoint aPosition); // draw cursor at character position
448 /** HideCursor hides cursor
450 IMPORT_C void HideCursor(); // hide cursor
452 // basic graphic functions
453 /** DrawChars() draws characters
454 * @param aString string to be drawn
455 * @param aPosition position of the string
456 * @param aCharacterAttributes attributes of the drawn string
458 IMPORT_C void DrawChars(const TDesC &aString,const TPoint &aPosition,TUint aCharacterAttributes); // draw aString at character position aPosition using
459 /** ClearChars() clears characters
460 * @param anArea area to be cleared
461 * @param aCharacterAttributes attributes of cleared characters
463 IMPORT_C void ClearChars(const TRect &anArea,TUint aCharacterAttributes); // clear the character area
464 /** InsertChars() inserts character area
465 * @param anArea area to be inserted
467 IMPORT_C void InvertChars(const TRect &anArea); // invert the character area
468 /** ScrollChars scrolls character area
469 * @param anArea area to be scrolled
470 * @param aVector direction to be scrolled
472 IMPORT_C void ScrollChars(const TRect &anArea,const TPoint &aVector); // scroll characters inside anArea by the given vector
475 /** sets scrollbar visibility
476 * @param aHBarVisibility horizontal scrollbar visibility
477 * @param aVBarVisibility vertical scrollbar visibility
479 IMPORT_C TInt SetScrollBarVisibilityL(CEikScrollBarFrame::TScrollBarVisibility aHBarVisibility, CEikScrollBarFrame::TScrollBarVisibility aVBarVisibility);
480 /** Updates scrollbar
481 * @param aDataSize size of the data
482 * @param aVisibleSize how much of the data is visible on the console
483 * @param aPos position of the visible area relative to whole data
484 * @return ETrue if as a result, the visible window has changed
486 IMPORT_C TBool UpdateScrollbarsL(const TSize &aDataSize,const TSize& aVisibleSize,TPoint aPos);
487 /** Handles scroll event
488 * @param aScrollBar scrollbar to be used for the event
489 * @param aEventType type of the event that happened
491 IMPORT_C void HandleScrollEventL(CEikScrollBar* aScrollBar,TEikScrollEvent aEventType);
494 IMPORT_C void UpdateArea();
496 public: // from CCoeControl
497 /** GetColorUseListL provides color use list for the control
499 IMPORT_C virtual void GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) const; // not available before Release 005u
500 /** HandleResourceChange handles several kinds of resource change events
502 IMPORT_C virtual void HandleResourceChange(TInt aType); // not available before Release 005u
503 /** HandlePointerEventL handles touch pointer events
505 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
507 protected: // virtual
509 /** Draws the control
511 IMPORT_C void Draw(const TRect& aRect) const;
514 IMPORT_C void SizeChanged();
515 /** Focus has changed
517 IMPORT_C void FocusChanged(TDrawNow aDrawNow);
518 /** Component controls count
520 IMPORT_C virtual TInt CountComponentControls() const;
521 /** Component controls
523 IMPORT_C virtual CCoeControl* ComponentControl(TInt aIndex) const;
524 /** Writes internal state
526 IMPORT_C void WriteInternalStateL(RWriteStream& aWriteStream) const;
528 private: // virtual - Reserved from CCoeControl
529 IMPORT_C virtual void Reserved_2();
535 IMPORT_C void* ExtensionInterface( TUid aInterface );
538 TPoint CharsToPixels(TPoint aPoint);
539 TRect CharsToPixels(const TRect &aRect);
540 TRect PixelsToChars(const TRect &aRect);
541 void ClearPixels(const TRect &anArea,TRgb aColor) const;
544 void InterpretAttribute(TUint AnAtt);
545 void InterpretColorBits(TUint aCharacterAttributes);
546 inline CEikConsoleControl &M() const {return((CEikConsoleControl&)(*this));}
547 void CreateScrollBarFrameLayout(TEikScrollBarFrameLayout& aLayout) const;
548 void InitFontSpecL();
551 CEikConsoleScreen *iConsole; // the console that owns this window
552 TRgb iBackGray16; // current background color
553 TRgb iPenGray16; // current pen color for characters
554 TUint iLastAtt; // last attribute, to see if we need to change the gc
555 TUint iLastFontFlags; // last attribute, to see if we need to load another font
557 TSize iCharSize; // size of a single character (in pixels)
558 TSize iViewInPixels; // size of area available for characters (in pixels)
559 TSize iViewInChars; // size of area available for characters (in characters)
561 TTextCursor iTextCursor; // cursor to use
562 TUint iCursorHeightPercentage; // required height of cursor (as a percentage)
564 TInt iRedrawing; // NONZERO IF BUSY REDRAWING
566 CEikScrollBarFrame* iSBFrame;
567 CEikScrollBarFrame::TScrollBarVisibility iHBarVisibility;
568 CEikScrollBarFrame::TScrollBarVisibility iVBarVisibility;
569 TPoint iLastThumbPos;
571 const CFont *iCurrentFont; // Current font
572 TFontSpec iFontSpec; // Current font spec
573 TFontUnderline iFontUnderline; // Current font spec underline
574 TUint iFontHeight; // Height of current font when not doubleheight/doublewidth
575 TUint iFontIsProportional; // nonzero if font is proportional