// FRMLAYDT.H
//
// Copyright (c) 1997-1999 Symbian Ltd. All rights reserved.
//

#if !defined(__FRMLAYDT_H__)
#define __FRMLAYDT_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(__TXTLAYDOC_H__)
#include <txtlaydc.h>
#endif
#if !defined(__FRMVIS_H__)
#include "frmvis.h"
#endif

class TLineSegment;
class TTextBox;
class TParaBorder;
class CFormLine;
class CLineLayout;
#if defined(TIMING_CODE)
	class CWindowGc;
	class RWsSession;
#endif

//
// This class is internal but needs to be visible because public
// enums defined here are part of the interface
//

class CLayoutData : public CBase
	{
public:
	enum
		{
		EFLargeNumber=KMaxTInt/3,	//Must be less than KMaxTInt/2 to avoid overflow problems
		EFMaximumTBoxLength=256,
		EFFontHeightIncreaseFactor=7,	//Increase the font height by <n>%
		EFBaseLinePosition=82		//Position down ViewRect for BaseLine
		};
	enum
		{
		EFHeightForFormattingAllText=EFLargeNumber,
		EFBodyWidthForNoWrapping=EFLargeNumber
		};
	enum		//Flags for XyPosToDocPos and DocPosToXyPos
		{
		EFIndividualChars=0,		//Count individual characters
		EFWholeLinesOnly,			//Count whole lines only		(XyToDocPos only)
		EFWholeTBoxesOnly=EFWholeLinesOnly			//Count only whole TBoxs so as not to access the document		(DocPosToXy only)
		};	
	enum TFormatMode
		{
		EFScreenMode, // ie the body width is stored in pixels and no mapping between format and image device
		EFPrintMode,  // ie the body width is stored in twips and no mapping.
		EFPrintPreviewMode, // ie the body width in twips and partial mapping
		EFWysiwygMode // ie body width in twips and full mapping
		};
public:
	CLayoutData();			//To stop warning
 	void ConstructL(MLayDoc *aDoc,TInt aWrapWidth);
	~CLayoutData();
	void SetImageDeviceMap(MGraphicsDeviceMap* aGd);
	inline void SetLabelsGDMap(MGraphicsDeviceMap* aDeviceMap);
	inline void SetFormatDeviceMap(MGraphicsDeviceMap* aGd);
	void SetBandHeight(TInt aHeight);
	TInt BandHeightInPixels() const;
	TInt BodyWidthInPixels() const;
	TInt VisibleHeightInPixels() const;
	void SetFormatAllText(TBool aAll);
	TBool IsFormattingAllText() const;
	inline void SetWrapWidth(TInt aWidth);
	void SetFormatMode(CLayoutData::TFormatMode aMode,TInt aWrapWidth
																,MGraphicsDeviceMap* aFormatDevice);
	inline void SetToWrapping(TBool aIsWrapping);
	void SetLayDoc(MLayDoc *aDoc);
	inline TInt DocumentLength() const;
	TInt EffectiveBodyWidth(const CParaFormat* aParaFormat=NULL) const;
	TBool IsParaWrapping(const CParaFormat* aParaFormat) const;
	TBool GetParaFormatL(TInt aDocPos,CParaFormat*& aParaFormat);
	TBool UpdateStoredParaFormatL(TInt aDocPos);
	void DestroyStoredParaFormat();
	void UpdateLabelsParaFormatL();
	void DestroyLabelsParaFormat();
	inline TBool IsBackgroundFormatting();
	TInt SpaceBeforeInPixels(const CParaFormat *aParaFormat);
	TInt SpaceAfterInPixels(const CParaFormat *aParaFormat);
	void GetNearestFontInTwipsL(CFont *&aFont,const TFontSpec &aFontSpec);
	void ReleaseLastFont();
	TInt VertFormatToImagePixels(TInt aInt) const;
	TInt HorzFormatToImagePixels(TInt aInt) const;
	TInt HorzTwips2Pixels(TInt aTwips) const;
	TInt VertTwips2Pixels(TInt aTwips) const;
	void UseImageDevice(TBool aImage=ETrue);
	inline void UseLabelDevice(TBool aLabel=ETrue);
	MGraphicsDeviceMap* CurrentImageDevice() const;
	MGraphicsDeviceMap* GetCurrentDevice() const;
	TText MapSpecialCharacter(TText aChar) const;
	static TInt SingleBorderWidthInTwips(const TParaBorder& aBorder);
	static TInt TotalBorderWidthInTwips(const TParaBorder& aBorder);
	static TInt SingleBorderWidthInPixels(const MGraphicsDeviceMap* aGd,const TParaBorder& aBorder,TBool aHoriz);
	TInt TotalBorderWidthInPixels(const TParaBorder& aBorder,TBool aHoriz);
	inline void SetExcludePartialLines(TBool aExcludePartialLines);
	inline TBool ExcludingPartialLines();
	TBool CanMapSpecialCharacters() const;
	TBool EnquirePageBreakVisible(TInt aPos,TInt aLength) const;
	TInt AscentInPixels(const CFont* aFont) const;
	TInt DescentInPixels(const CFont* aFont) const;
	inline TInt IncreaseFontHeight(TInt aHeight) {return (iFontHeightIncreaseFactor*aHeight)/100;}
public:
	MLayDoc *iDoc;
	CFormLine *iFormLine;			//And this
	CFont *iLastCreatedFont;
	CParaFormat *iParaFormat;			//This too
	CParaFormat *iLabelsParaFormat;			//This too
	CLineLayout *iReadLine;
	TLineSegment* iReadLineSegment;
	TTextBox *iReadTBox;
	TBool iIsWrapping;
	TBool iIsBackgroundFormatting;
	TInt iLabelsWidth;
	TInt iFontHeightIncreaseFactor;		//Increase the font height by (100/<n>)%
	TNonPrintingCharVisibility iShowFormatChars;
	TFormatMode iFormatMode;
	TTextBox* iFirstNonUnderlineBox;
private:
	MGraphicsDeviceMap* iImageDevice; // Always used for viewing text.
	MGraphicsDeviceMap* iLabelsDevice; // On the image device only
	MGraphicsDeviceMap* iFormatDevice; // Allways used for initial formatting of text.
	TBool iUseImageDevice;	 // Switch between the two devices.
	TBool iUseLabelsDevice;
	TInt iVisibleHeight; // In pixels for screen mode and Wysiwyg mode (printing - twips)
	TInt iBandHeight;
	TInt iWrapWidth;	 // In pixels for screen mode only, otherwise twips.
	TBool iExcludingPartialLines;
#if defined(TIMING_CODE)
public:
	IMPORT_C void SetTimingFlags(TUint aFlags);
	IMPORT_C void SetHandle(CWindowGc *aGc,RWsSession *aWs);
	inline void SetCallBack(TCallBack aCallBack) {iCallBack=aCallBack;}
	class TTestTimingCode* iTestTimingCode;
	TUint iTimingFlags;
	CWindowGc *iGc;
	RWsSession *iWs;
	TCallBack iCallBack;
#endif
	};

#include "frmlaydt.inl"

#endif
