// FRMTLAY.H
//
// Copyright (c) 1997-1999 Symbian Ltd. All rights reserved.
//

#if !defined(__FRMTLAY_H__)
#define __FRMTLAY_H__

#if !defined(__E32STD_H__)
#include <e32std.h>
#endif
#if !defined(__E32BASE_H__)
#include <e32base.h>
#endif
#if !defined(__GDI_H__)
#include <gdi.h>
#endif
#if !defined(__TXTFRMAT_H__)
#include <txtfrmat.h>
#endif
#if !defined(__TXTETEXT_H__)
#include <txtetext.h>
#endif
#if !defined(__FRMLAYDT_H__)
#include "frmlaydt.h"
#endif

// Definition of layout and cursor positioning classes

class TViewYPosQualifier
	{
friend class CTextLayout;
friend class CTextView;
public:
	enum TPartOfLine
		{
		EFViewTopOfLine=1,			//Put the top pixel of the line at the specified point
		EFViewBaseLine=0,				//Put the baseline of the line at the specified point
		EFViewBottomOfLine=2		//Put the bottom pixel of the line at the specified point
		};
	enum TFullyVisible
		{
		EFViewForceLineFullyVisible=ETrue,		//Make sure that the line if fully visible
		EFViewDontForceLineFullyVisible=EFalse		//Possible leave the line (partially) not visible
		};
public:
	inline TViewYPosQualifier() :iHotSpot(EFViewBaseLine),iFillScreen(EFalse)
													,iFullyVisible(EFViewDontForceLineFullyVisible) {}
	IMPORT_C void SetHotSpot(TPartOfLine aHotSpot);
	IMPORT_C void SetFillScreen(TBool aFillScreen=ETrue);
	IMPORT_C void SetMakeLineFullyVisible(
									TFullyVisible aMakeLineFullyVisible=EFViewForceLineFullyVisible);
private:
	TPartOfLine iHotSpot;
	TBool iFillScreen;
	TFullyVisible iFullyVisible;
	};

class TViewRectChanges
	{
public:
	inline TViewRectChanges() :iScrollAtTop(0),iScrollAtBottom(0) {}
	void AdjustAll(TInt aDelta);
public:
	TInt iFormattedFrom;
	TInt iFormattedTo;
	TInt iScrollAtTop;
	TInt iScrollAtBottom;
	};

class TCursorSelection
	{
public:
	inline TCursorSelection();
	inline TCursorSelection(TInt aCursorPos,TInt aAnchorPos);
	inline void SetSelection(TInt aCursorPos,TInt aAnchorPos);
	inline TInt LowerPos() const;
	inline TInt HigherPos() const;
	inline TInt Length() const;
public:
	TInt iCursorPos;
	TInt iAnchorPos;
	};

class TReadTextBox;
class TReadLineSegment;
class CTextLayout;
class CWindowGc;

class TDrawTextLayoutContext
	{
private:
	enum TDrawMode
		{
		EFDrawText=0x001,
		EFDrawGraphics=0x002,
		EFUseClippingRect=0x004,
		EFUseWindowGc=0x008,
		EFUseGcClear=0x020,
		EFUseBackgroundColor=0x040,
		EFUseOverrideTextColor=0x080,
		EFParagraphFillTextOnly=0x100,
		EFAllFlags=0xfff
		};
public:
	IMPORT_C TDrawTextLayoutContext();

// Setting functions
	IMPORT_C void SetGc(CGraphicsContext* aGc,CGraphicsContext* aPictureGc=NULL);
	IMPORT_C void SetBitmapGc(CBitmapContext* aGc,CBitmapContext* aPictureGc=NULL);
	IMPORT_C void SetWindowGc(CWindowGc* aGc,CWindowGc* aPictureGc=NULL);
	IMPORT_C void SetDrawToEveryPixel(TBool aDrawToEveryPixel);
	IMPORT_C void SetTextColorOverride(const TRgb *aOverrideColor);
	IMPORT_C void SetDrawTextOnly();
	IMPORT_C void SetDrawGraphicsOnly();
	IMPORT_C void SetDrawTextAndGraphics();
	IMPORT_C void SetClipping(TBool aClipping);
	IMPORT_C void SetParagraphFillTextOnly(TBool aFillTextOnly);

//Enquiry functions
	IMPORT_C const TRgb* TextOverrideColor() const;
	IMPORT_C CGraphicsContext* PrimaryGc() const;
	IMPORT_C CGraphicsContext* PictureGc() const;
	IMPORT_C TBool UseClippingRect() const;
	IMPORT_C TBool UseGcClear() const;
	IMPORT_C TBool DrawText() const;
	IMPORT_C TBool DrawGraphics() const;
	IMPORT_C TBool UseBackgroundColor() const;
	IMPORT_C TBool ParagraphFillTextOnly() const;

//Physical dimensions
	IMPORT_C TRect TextArea() const;
	IMPORT_C TInt DisplayHeight() const;
	IMPORT_C TPoint TopLeftTextArea() const;
	IMPORT_C TRect TotalMargin() const;
	IMPORT_C TRect LabelMargin() const;
	IMPORT_C TBool IsLabelMargin() const;
	IMPORT_C TRect GutterMargin() const;
	IMPORT_C TBool IsGutterMargin() const;
	IMPORT_C TPoint TopLeftText() const;
	IMPORT_C void WindowToText(TPoint& aWinPos) const;
	IMPORT_C void WindowToText(TRect& aRect) const;
	IMPORT_C void TextToWindow(TPoint& aTextAreaPos) const;
	IMPORT_C void TextToWindow(TRect& aRect) const;
public:
	TRect iViewRect;
	TInt iLabelMarginWidth;
	TInt iGutterMarginWidth;
	TInt iTextStartX;
	TRgb iBackgroundColor;
private:
	CGraphicsContext* iGc;
	CGraphicsContext* iPictureGc;
	TRgb iOverrideTextColor;
	TUint iDrawMode;
	};

class CLineLayout;
class CParaLayout;
class TTextLayoutInkState;

class CTextLayout : public CBase
	{
friend class CTestTextLayout;
public:
	enum TParaChange
		{
		EFParaChangeNormal=0,				//No change to the number of paragraphs
		EFParaChangeStartNew=0x0001,			//One Paragraph split into two
		EFParaChangeRemoveNext=0x0002,		//Paragraph delimeter deleted from after the cursor
		EFParaChangeMergePrevious=0x0004		//Paragraph delimeter deleted from before the cursor
		};
	enum TDiscard
		{
		EFViewDiscardAllFormat=ETrue,		//Throw all the format away
		EFViewDontDiscardFormat=EFalse		//Dont throw away format until it is know that it is not needed
		};
	enum TAllowDisallow
		{
		EFAllowScrollingBlankSpace=ETrue,
		EFDisallowScrollingBlankSpace=EFalse
		};
	enum 		//Flags for ReadLine
		{
		EFReadLineHasLabel=0x0001,		//The line in question has a label
		EFReadFirstLineInPara=0x0002,	//The line in question is the first line of a paragraph
		EFReadLastLineInPara=0x0004	//The line in question is the last line of a paragraph
		};
	enum		//Flags for NotifyCharEdit
		{
		EFCharacterInsert,			//Insert a normal character
		EFParagraphDelimiter,		//Insert a paragraph delimiter
		EFLeftDelete,				//Delete character to left of cursor
		EFRightDelete				//Delete character to right of cursor (Some code assumes this is the last one and consecutatively ordered)
		};
	enum
		{
		EFScrollRedrawWholeScreen=CLayoutData::EFLargeNumber,	//A value greater than any possible display height
		EFMaximumLineWidth=CLayoutData::EFBodyWidthForNoWrapping,
		};
	enum		//TBool values used by various functions
		{
		EFAllParagraphsNotWrapped=ETrue,
		EFParagraphsWrappedByDefault=EFalse		//Pargraphs are wrapped depending on a flag in the para format
		};
	enum TAmountFormatted
		{
		EFFormatAllText=EFalse,
		EFFormatBand=ETrue,
		};
	enum TCurrentFormat
		{
		EFNoCurrentFormat=-1,
		EFNotInCurrentFormat=0
		};
private:
	typedef TDblQue<CParaLayout> TQue;
	typedef TDblQueIter<CParaLayout> TIter;
	class TBulletLayout
		{
	public:
		TBulletLayout::TBulletLayout() {}
	public:
		TBullet *iBullet;
		TInt iIndent;
		};
	enum TInsertPos
		{
		EFInsertAtStart=0,		//Insert created paragraph at the start
		EFInsertAfter,			//Insert created paragraph after the specified one
		EFInsertAtEnd,			//Insert created paragraph at the end
		};
	enum
		{
		EFAllFormat=CLayoutData::EFLargeNumber
		};
	enum					//Used in ViewL
		{
		EFViewNotMatchedYet=-1					//Must be negative
		};
	enum
		{
		EFPageBreakLineWidth=1		  // In Pixels
		};
public:
	//Creation, destruction
	IMPORT_C static CTextLayout *NewL(MLayDoc *aDoc,TInt aWrapWidth);
	IMPORT_C ~CTextLayout();
	IMPORT_C void DiscardFormat();

	//Set'er and Get'er functions of global parameters
	IMPORT_C void SetLayDoc(MLayDoc *aDoc);
	IMPORT_C void SetWrapWidth(TInt aWrapWidth);
	IMPORT_C void SetBandHeight(TInt aHeight);	  // Set in pixels for screen layout and wysiwyg
	IMPORT_C TInt BandHeight() const;
	IMPORT_C void SetImageDeviceMap(MGraphicsDeviceMap *aGd);
	IMPORT_C void SetLabelsDeviceMap(MGraphicsDeviceMap *aDeviceMap);
	IMPORT_C void SetAmountToFormat(TAmountFormatted aAmountOfFormat=EFFormatBand);
	IMPORT_C TBool IsFormattingBand() const;
	IMPORT_C void SetFormatMode(CLayoutData::TFormatMode aFormatMode,TInt aWrapWidth
																,MGraphicsDeviceMap* aFormatDevice);
	IMPORT_C void ForceNoWrapping(TBool aNoWrapping=EFAllParagraphsNotWrapped);
	IMPORT_C TBool IsWrapping() const;
	IMPORT_C void SetLabelsMarginWidth(TInt aWidth);
	IMPORT_C void SetNonPrintingCharsVisibility(TNonPrintingCharVisibility aVisibility);
	IMPORT_C TNonPrintingCharVisibility NonPrintingCharsVisibility() const;
	IMPORT_C TBool IsBackgroundFormatting() const;
	IMPORT_C void NotifyTerminateBackgroundFormatting();
	IMPORT_C void SetExcludePartialLines(TBool aExcludePartialLines=ETrue);
	IMPORT_C TBool ExcludingPartialLines() const;

	//Enquiry of Format statistics
	IMPORT_C TInt DocumentLength() const;
	IMPORT_C TInt ToParagraphStart(TInt& aDocPos) const;		//Changes aDocPos to paragraph start and returns the amount by which it change
	IMPORT_C TInt PixelsAboveBand() const;
	IMPORT_C TInt YBottomLastFormattedLine() const;			//Actually of pixels immediatly below this line
	IMPORT_C TInt FormattedHeightInPixels() const;
	IMPORT_C TInt PosRangeInBand(TInt& aDocPos) const;			//Returns the number of visible characters
	IMPORT_C TBool PosInBand(TInt aDocPos,TPoint& aXyPos) const;		//Returns whether the pos is in the band and the point where it is
	IMPORT_C TBool PosIsFormatted(TInt aDocPos) const;
	IMPORT_C TInt FirstCharOnLine(TInt aLineNo) const;	//That is "LineToDocPos"   Returns EFNoCurrentFormat when no format
	IMPORT_C TInt FormattedLength() const;
	IMPORT_C TInt NumFormattedLines() const;
	IMPORT_C TInt FirstLineInBand() const;	 // Returns EFNoCurrentFormat when no format
	IMPORT_C TInt GetLineRect(TInt aYPos,TRect& aLine) const;		//Returns the line width in pixels
	IMPORT_C TInt ParagraphHeight(TInt aDocPos) const;
	IMPORT_C TRect ParagraphRectL(TInt aDocPos) const;
	IMPORT_C TBool CalculateHorizontalExtremesL(TInt& aLeftX,TInt& aRightX,TBool aOnlyVisibleLines,TBool aIgnoreWrapCharacters=EFalse) const; // Returns false if no format
	IMPORT_C void GetCharacterHeightAndAscentL(TInt aDocPos,TInt& aHeight,TInt& aAscent) const;
	IMPORT_C void GetFontHeightAndAscentL(const TFontSpec& aFontSpec,TInt& aHeight,TInt& aAscent) const;
	IMPORT_C TInt XyPosToDocPosL(TPoint &aPos,TUint aFlags=CLayoutData::EFIndividualChars) const;		//aPoint changed to right most point on baseline
	IMPORT_C TBool DocPosToXyPosL(TInt aDocPos,TPoint& aPos
											,TUint aFlags=CLayoutData::EFIndividualChars) const;
	IMPORT_C TRect GetLineRectL(TInt aDocPos1,TInt aDocPos2) const;
	IMPORT_C TBool PictureRectangleL(TInt aDocPos,TRect& aPictureRect,TBool* const aCanScaleOrCrop=NULL) const;
	IMPORT_C TBool PictureRectangleL(const TPoint& aXyPos,TRect& aPictureRect,TBool* const aCanScaleOrCrop=NULL) const;
	IMPORT_C TInt FirstDocPosFullyInBand() const;

	//Formatting Functions		(Not for use while there is a CTextView)
	IMPORT_C TInt SetViewL(TInt aDocPos,TInt& aYPos,TViewYPosQualifier aYPosQualifier
												,TDiscard aDiscardFormat=EFViewDontDiscardFormat);
	IMPORT_C void FormatBandL();
	IMPORT_C void FormatCharRangeL(TInt aStartDocPos,TInt aEndDocPos);
	void FormatCharRangeL(TInt aStartDocPos,TInt aEndDocPos,TInt aPixelOffset);		//Used by a bug fix for printing
	IMPORT_C TBool FormatNextLineL(TInt& aBotPixel);
	IMPORT_C TBool FormatLineL(CParaFormat* aParaFormat,TInt& aDocPos,TInt& aHeight,TBool& aPageBreak);

	//Scrolling functions		(Not for use while there is a CTextView)
	IMPORT_C TInt ScrollParagraphsL(TInt& aNumParas,TAllowDisallow aScrollBlankSpace);
	IMPORT_C TInt ScrollLinesL(TInt& aNumLines
									,TAllowDisallow aScrollBlankSpace=EFDisallowScrollingBlankSpace);
	IMPORT_C TInt ChangeBandTopL(TInt& aPixels
									,TAllowDisallow aScrollBlankSpace=EFDisallowScrollingBlankSpace);
	IMPORT_C void PageUpL(TInt& aYCursorPos,TInt& aPixelsScrolled);
	IMPORT_C void PageDownL(TInt& aYCursorPos,TInt& aPixelsScrolled);

	//Notification of changes to document content of formatting		(Not for use while there is a CTextView)
	IMPORT_C TBool HandleCharEditL(TUint aType,TInt& aCursorPos,TInt& aGood
						,TInt& aFormattedUpTo,TInt& aFormattedFrom,TInt& aScroll,TBool aFormatChanged);
	IMPORT_C void HandleBlockChangeL(TCursorSelection aSelection,TInt aOldCharsChanged
												,TViewRectChanges& aViewChanges,TBool aFormatChanged);
	IMPORT_C void HandleAdditionalCharactersAtEndL(TInt& aFirstPixel,TInt& aLastPixel);
	IMPORT_C void ReformatVerticalSpaceL();// quick reformat when only space above and space below have changed
	IMPORT_C void AdjustVerticalAlignment(CParaFormat::TAlignment aVerticalAlignment);// quick reformat to add space above for ECenterAlign,EBottomAlign

	//Drawing functions
	IMPORT_C static void DrawBorders(const MGraphicsDeviceMap* aGd,CGraphicsContext& aGc,const TRect& aRect
					,const TParaBorderArray& aBorder,const TRgb* aBackground=NULL,TRegion *aClipRegion=NULL,const TRect* aDrawRect=NULL);
	IMPORT_C void DrawL(const TRect& aDrawRect,const TDrawTextLayoutContext* aDrawTextLayoutContext,const TCursorSelection* aHighlight=NULL);
	IMPORT_C void InvertRangeL(const TCursorSelection& aHighlight,const TRect& aDrawRect,const TDrawTextLayoutContext* aDrawTextLayoutContext);
private:
	IMPORT_C CTextLayout();
 	IMPORT_C void ConstructL(MLayDoc *aDoc,TInt aWrapWidth);
	
//Reading Back Format
	TInt ReadLine(TInt aY,TUint& aFlags,TInt& aLineLen);
	TInt FinishedReadingLabel(TInt aY);
	TBool ReadLineSegment(TReadLineSegment& aLineSegment);
	TBool ReadTBoxL(TReadTextBox& aTbox,TDes& aBuf,CFont *&aFont,CPicture*& aPict
		,TFontPresentation& aFontPresentation,TBool& aNoUnderlineBox);
	void CalculateParaDrawRects(const CParaFormat* aParaFormat,TParaBorderArray& aParaBorder,const TPoint& aTl);
	void ReadBullet(CParaFormat* aParaFormat,TBulletLayout& aBulletLayout);
	TBool GetParaFormatL(TInt aDocPos,CParaFormat*& aParaFormat) const;
	TBool UpdateStoredParaFormatL(TInt aDocPos,CParaFormat*& aParaFormat);
	void DestroyStoredParaFormat();

	void DelParagraphs();
	void DelFollowingParas(CParaLayout *aParagraph);
	void DelFollowingParas(TIter& iter);
	void DelParagraph(CParaLayout *aParagraph);
	virtual CParaLayout *NewParagraphL();			 //virtual for debugging
	TInt NumLines(TInt aPixels=EFAllFormat) const;
	TInt HalfBandHeight() const;
	TInt ParagraphHeight(TInt aDocPos,const CParaLayout*& aParagraph,TInt& aTopPixel) const;
	TInt FormatParaBeforeL(TInt& aDocPos,CParaLayout *aParagraph);
	TBool FormatParaAboveL();
	TBool FormatParaAboveToL(TInt aY);
	void DeleteFormatAbove();
	TInt FormatMoreAtEndL(TInt aAmount);
	void FormatMoreAtEndL(TInt& aNextPixel,TInt& aNextChar);
	void DeleteFormatAtEnd(TInt aAmount);
	TInt AdjustFormatAtEndL();
	TInt AdjustFormatOfLastParaL(TInt& aDocPos);
	TInt CopyParagraphsTo(TQue& aParaSet,TBool aDeletePartial);
	void ModifyYPos(TInt& aYPos,TInt& aFirstPixel,CParaLayout* aParagraph,TInt aParaPos
																,TViewYPosQualifier aYPosQualifier);
	TInt DoViewL(TQue& aParaSet,TInt aDocPos,TInt& aYPos,TViewYPosQualifier aYPosQualifier);
	void AdjustLineHeightsPrintPreview();
	TBool CheckFinishedFormattingL(const TBool aMoreToDo);
	TInt GetTopOfParagraph(CParaLayout * aPara);
	TBool SearchByPixel(TInt& aY,TIter& aIter,const CParaLayout *&aParagraph,TInt& aDocPos) const;
	TBool SearchByDocPos(TInt& aDocPos,TIter& aIter,const CParaLayout *&aParagraph,TInt& aHeight) const;
	TInt LastCharInBand() const;
	CParaLayout *NewParaInsertedL(TInsertPos aInsertPos=EFInsertAtEnd,CParaLayout *aPreviousPara=NULL);
	void ReadTextL(TDes& aBuf,TInt aDocPos,TInt aBoxLength,CFont *&aFont,CPicture*& aPict
												,TFontPresentation& aFontPresentation,TBool& aNoUnderlineBox);
	TInt ScrollParagraphsUpL(TInt& iNumParas);
	TInt ScrollParagraphsUpFromTop(TInt& iNumParas);
	TInt ScrollParagraphsDownL(TInt& iNumParas);
	TInt ScrollLinesUpL(TInt& iNumLines);
	TInt ScrollLinesUpFromTop(TInt& aNumLines);
	TInt ScrollLinesDownL(TInt& iNumLines);
	TInt ScrollTopPartialLine();
	
	// Drawing functions
	void GetNearestFontL(const TFontSpec& aFontSpec,CFont*& aFont);
	TInt DisplayLineL(TPoint aTl,TInt aLeftX,TInt aRightX,const TRgb *aParagraphColor,
					  const TRgb* aSurroundColor,TBulletLayout* aBulletLayout);
	TInt DisplayLineL(TInt aHeight,CParaFormat*& aParaFormat);
	void DisplayBulletL(const TReadTextBox& aBulletBox,const TBulletLayout* aBulletLayout,const TRgb* aBackColor);
	TInt YLastVisiblePixel() const;
	void ClipToViewRect();
	void ClipToDrawRect();
	void ClipToTextArea();
	void ClipToLabelMargin();
	void ReinstateClippingRect();
	void SetTextJustification(const TReadLineSegment& aLineSegment);
	void DrawRoundedRect(const TRect* aRoundedHighlight,const TRgb* aCornerColor
												,const TRgb* aRectColor,const TRgb* aSurroundColor);
	void DrawText(TPtrC aBuf,const TRect &aRect,TInt aBaseLine,CFont *aFont,TFontPresentation& aFontPresentation,
				  const TRgb *aBackColor,TBool aInvisibleBackground,TInt aLeftCharMargin,TTextLayoutInkState& aInkState);
	void DrawTextBeyondWrap(TPtrC aBuf,const TRect &aRect,TInt aBaseLine,TInt aLineTopY
						,TInt aLineBottomY,CFont *aFont,TFontPresentation& aFontPresentation
						,const TRgb *aBackColor,TBool aInvisibleBackground,const TRgb* aSurroundColor);
	void DrawBullet(TPtrC aBuf,const TRect& aRect,TInt aBaseLine,CFont* aFont,const TRgb& aColor
																			,const TRgb* aBackColor);
	TInt DrawPictureL(CPicture* aPicture,const TRect& aRect,TInt aBaseLine
							,TFontPresentation::TAlignment aPictAlignment,const TRgb* aBackColor);
	void DrawParaBorders(const TParaBorderArray& aParaBorder,const TRgb* aBackColor);
	void ClearRect(const TRect& aRect,TBool aClearInnerDrawRectOnly=ETrue,const TRgb *aBackColor=NULL);
	void ClearParagraphSurround(const TRgb* aBackColor,TInt* aTopOfLine=NULL,TInt* aBottomOfLine=NULL
																			,TInt* aTextRightX=NULL);
	void InvertRangeL(TInt aDocPos1,TInt aDocPos2);
	void Invert(const TRect& aRect);
	void DrawPageBreak(TInt aLastPixel);			
	void ReduceSegment(TReadLineSegment &lineSegment,TInt length);
private:
	CLayoutData *iLayoutData;
	__MUTABLE TQue iParagraphSet;				//Need to destroy this
	CParaLayout *iCurrentPara;
	CParaLayout *iReadPara;
	TInt iReadDocPos;
	TInt iReadY;
	TInt iDocPos;		//Used in background formatting
	TInt iTopDocPos;
	TInt iTopY;
	const TDrawTextLayoutContext* iDrawTextLayoutContext;
	CGraphicsContext* iGc;
	TRect iDrawRect;
	TRect iInnerParaDrawRect;
	TRect iOuterParaDrawRect;
	TRect iTotalParaClearRect;
	TRect iClipRect;
	const TCursorSelection* iHighlight;
#if defined(_DEBUG)
public:
	TBool __DbgIsFormattingUpToDate();
#endif
#if defined(TIMING_CODE)
public:
	TTestTimingCode* iTestTimingCode;
#endif
private:
	CTextLayout(const CTextLayout& aRHS);
	CTextLayout& operator=(const CTextLayout& aRHS);
#if defined(TIMING_CODE)
public:
	inline void SetTimingFlags(TUint aFlags) {iLayoutData->SetTimingFlags(aFlags);iTimingFlags=aFlags;}
	TUint iTimingFlags;
	inline void SetHandle(CWindowGc *aGc,RWsSession *aWs) 
			{iLayoutData->SetHandle(aGc,iWs);iTimingGc=aGc;iWs=aWs;}
	inline void SetCallBack(TCallBack aCallBack) {iLayoutData->SetCallBack(aCallBack);}
	CWindowGc *iTimingGc;
	RWsSession *iWs;
#endif
	};

//
// Internal class - NOT part of interface
// 

class TCursorPosition
	{
public:
	enum TMovementType
		{
		EFNoMovement,
		EFLeft,
		EFRight,
		EFLineUp,
		EFLineDown,
		EFPageUp,
		EFPageDown,
		EFLineBeg,
		EFLineEnd
		};
	enum TDrawSelectionFlags
		{
		EFDrawNone=0x00,			//Must be zero (that is false)
		EFDrawHighlight=0x01,
		EFDrawOldPictureFrame=0x02,
		EFDrawNewPictureFrame=0x04
		};
	enum		//Values for doing LineBeg and LineEnd
		{
		EFFirstCharOnLine=(-CLayoutData::EFLargeNumber),
		EFLastCharOnLine=CLayoutData::EFLargeNumber
		};
private:
	enum
		{
		EFAbove=-1,
		EFInside=0,
		EFBelow=1
		};
public:
	inline TCursorPosition();
	inline void SetLayout(CTextLayout *aLayout);
	inline TBool IsSelection() const;
	inline TBool IsSelectionToDraw() const;
	TBool IsPictureFrame() const;
	TBool IsNewPictureFrame() const;
	inline TInt LatentX();
	inline void UpdateLatentX(TInt aX);
	inline void SetToPreviousHighlight();
	inline void SetToCurrentHighlight();
	TBool CancelHighlight();
	TInt SetSelectionL(const TCursorSelection& aSelection);
	void SetPendingSelection(const TCursorSelection& aSelection);
	TInt GetDeltaSelect(TInt& aPos);
	void GetSelection(TCursorSelection& aSelection) const;
	TInt SetDocPosL(TBool aDragSelectOn,TInt aDocPos);
	TInt SetXyPosL(TBool aDragSelectOn,TPoint aPos,TBool aAllowPictureFrame);
	TInt MoveL(TBool aDragSelectOn,TMovementType& aMovement,TBool aAllowPictureFrame);
	TInt FormattingChangedL();
	void UpdateLatentPositionL();
	void TextMoveVerticallyL();
	TBool GetLineRectL(TRect& aLine,TPoint& aBaseLine);
	void GetCurrentLineHeightAndAscentL(TBool aLeftOfCursor,TInt& aHeight,TInt& aAscent);
	void DocumentShiftedBy(TInt aChars);
public:
	TInt iDocPos;
	TInt iAnchor;
	TUint iDrawSelectionFlags;
private:
	enum TMode
		{
		EFReturnCurrentHighlight,
		EFReturnPreviousHighlight
		};
	enum
		{
		EFUseCurrentDocumentPosition=CLayoutData::EFLargeNumber
		};
private:
	inline TCursorPosition& operator=(TCursorPosition& /*aLHS*/) {return *this;}
	TInt ViewTopOfLineL(TInt aDocPos,TInt& aYPos);
	void CheckSelection(TBool aSelect);
	void CheckNullSelection();
	inline void UpdateLatentY(TInt aY);
	TInt CheckCursorOnScreenL(TInt& aY);
	TInt BringCursorOnScreenL(TInt aDocPos=EFUseCurrentDocumentPosition);
	TInt StayL();
	TInt RightL(TMovementType& aMovement,TBool aAllowPictureFrame);
	TInt LeftL(TMovementType& aMovement,TBool aAllowPictureFrame);
	TInt StartOfLineL();
	void DoStartOfLineL();
	TInt EndOfLineL();
	void DoEndOfLineL();
	TInt UpL(TMovementType& aMove);
	TInt DownL(TMovementType& aMove);
	TInt PageScrollL(TMovementType& aMove);
	/*TInt PageUpL();
	TInt PageDownL();*/
	TInt DoSetDocPosL(TInt aDocPos);
	TInt DoSetVisibleDocPosL(TInt aDocPos);
	void DoSetXyPosL(TPoint& aXy);
	void SelectPictureFrameByXyPosL(TInt aOldDocPos);
	void SetPictureFrame(TInt aDocPos,TInt aAnchor,const TRect& aPictureRect);
	inline TBool CalculateCursorPosL(TPoint& aCurPos);
private:
	CTextLayout *iLayout;
	TBool iSelected;
	TInt iOldAnchor;
	TInt iOldDocPos;
	TMode iMode;
	TInt iLatentX;
	TInt iLatentY;
	};

#include "frmtlay.inl"

#endif
