// TXTFRMAT.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__TXTFRMAT_H__)
#define __TXTFRMAT_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

//
// Classes declared in this file:
class TTabStop;
class TParaBorder;
class TBullet;
//
class TParaBorderArray;
class CParaFormat;
class TParaFormatMask;
//
class TFontPresentation;
class TCharFormat;
class TCharFormatMask;

enum TTextFormatAttribute {
	//
	// PARAGRAPH FORMAT ATTRIBUTES
	EAttParaLanguage,
	EAttFillColor,
	EAttLeftMargin,EAttRightMargin,EAttIndent,EAttAlignment,EAttVerticalAlignment,
	EAttLineSpacing,EAttLineSpacingControl,EAttSpaceBefore,EAttSpaceAfter,
	EAttKeepTogether,EAttKeepWithNext,EAttStartNewPage,EAttWidowOrphan,EAttWrap,
	EAttBorderMargin,
	EAttTopBorder,EAttBottomBorder,EAttLeftBorder,EAttRightBorder,
	EAttBullet,
	EAttDefaultTabWidth,EAttTabStop,
	//
	// CHARACTER FORMAT ATTRIBUTES
	EAttCharLanguage,
	EAttColor,
	EAttFontHighlightColor,EAttFontHighlightStyle,
	EAttFontHeight,EAttFontPosture,EAttFontStrokeWeight,
	EAttFontPrintPos,EAttFontUnderline,EAttFontStrikethrough,
	EAttFontTypeface,
	EAttFontPictureAlignment,
	EAttFontHiddenText,
	EAttLast};  // Published format attribute symbols, for use when interrogating 'set' mask.

enum {EVariableLengthValue=0};

const TInt KMaxStyleName=0x20;
const TInt KMaxParaAttributes=EAttTabStop;
const TInt KMaxCharAttributes=EAttFontTypeface-KMaxParaAttributes;
const TInt KTabNotFound=-1;


//
// Tabs are uniquely identified by their twips position.

class TTabStop
	{
public:
	enum TTabType{ENullTab,ELeftTab,ECenteredTab,ERightTab};
public:
	IMPORT_C TTabStop();
	IMPORT_C TTabStop(const TTabStop& aTabStop);
	IMPORT_C TTabStop& operator=(const TTabStop& aTabStop);
	IMPORT_C TBool operator==(const TTabStop& aTabStop)const;
	inline TBool operator!=(const TTabStop& aTabStop)const;
public:
	TUint32 iTwipsPosition;
	TTabType iType;
	};


//
// Defines one side, (top/bottom/left/right), of a paragraph border.

class TParaBorder
	{
public:
	enum TLineStyle {ENullLineStyle,ESolid,EDouble,EDotted,EDashed,EDotDash,EDotDotDash};
	//
	IMPORT_C TParaBorder();
	IMPORT_C TBool operator==(const TParaBorder& aParaBorder)const;
	inline TBool operator!=(const TParaBorder& aParaBorder)const;
public:
	TLineStyle iLineStyle;
	TInt iThickness;
	TRgb iColor;
	TBool iAutoColor;
	};


//
// Defines a bullet point for a paragraph, as an attribute, rather than content.

class TBullet
	{
public:
	IMPORT_C TBullet();
	IMPORT_C TBool operator==(const TBullet& aBullet)const;
	inline operator!=(const TBullet& aBullet)const;
public:
	TChar iCharacterCode;  // Defines the symbol displayed.
	TUint32 iHeightInTwips;
	TTypeface iTypeface;
	TBool iHangingIndent;
	TRgb iColor;
	};


//
// Packages all paragraph format attributes.

class CParaFormat : public CBase
	{
public:
	enum {EMaxParaBorder=4};
	enum TParaBorderSide {EParaBorderTop,EParaBorderBottom,EParaBorderLeft,EParaBorderRight};
	enum TLineSpacingControl {
		ELineSpacingAtLeastInTwips,
		ELineSpacingExactlyInTwips,
		ELineSpacingAtLeastInPixels,
		ELineSpacingExactlyInPixels
		};
	enum TAlignment {
		ELeftAlign,	ETopAlign=ELeftAlign,
		ECenterAlign,
		ERightAlign,EBottomAlign=ERightAlign,
		EJustifiedAlign,
		EUnspecifiedAlign,
		ECustomAlign
		};  // Horizontal/Vertical paragraph alignment
	enum TParaFormatGetMode {EAllAttributes,EFixedAttributes};
	//
	IMPORT_C static CParaFormat* NewL();
	IMPORT_C static CParaFormat* NewLC();
	IMPORT_C static CParaFormat* NewL(const CParaFormat& aFormat);
	IMPORT_C CParaFormat();
	IMPORT_C ~CParaFormat();
	//
	IMPORT_C void ResetNonDestructive();  // preserves any allocated tabs,bullets or borders.
	IMPORT_C void Reset();  // full reset, deletes and nulls any allocated tabs,bullets or borders.
	//
	IMPORT_C void CopyL(const CParaFormat& aFormat,const TParaFormatMask& aMask);
	IMPORT_C void CopyL(const CParaFormat& aFormat);
	//
	IMPORT_C void Strip();  // Cleans up this paragraph format.
	//
	// Equality
	IMPORT_C TBool IsEqual(const CParaFormat& aFormat,const TParaFormatMask& aMask)const;
	IMPORT_C TBool IsEqual(const CParaFormat& aFormat)const;
	//
	// TabStop functions
	IMPORT_C void StoreTabL(const TTabStop& aTabStop);
	IMPORT_C void RemoveTab(TInt aTabTwipsPosition);
	inline void RemoveAllTabs();
	IMPORT_C const TTabStop TabStop(TInt aTabIndex)const;
	inline TInt TabCount()const;
	IMPORT_C TInt LocateTab(TInt aTabTwipsPosition)const;
	//
	// ParaBorder functions
	IMPORT_C void SetParaBorderL(TParaBorderSide aSide,const TParaBorder& aBorder);  // Overwrites any existing border for that side
	IMPORT_C void RemoveAllBorders();
	IMPORT_C const TParaBorder ParaBorder(TParaBorderSide aSide)const;
	inline TBool BordersPresent()const {return iParaBorderArray!=NULL;}
	IMPORT_C TBool AllBordersEqual(const CParaFormat& aFormat)const;
	IMPORT_C TBool IsBorderEqual(TParaBorderSide aSide,const CParaFormat& aFormat)const;
private:
	CParaFormat(const CParaFormat& aFormat);
	void ConstructL();
	void ConstructL(const CParaFormat& aFormat);
	void CopyTabsL(const CParaFormat& aFormat);
	//
	// No implementation provided
	enum {ETabStoreGranularity=2};
	CParaFormat& operator=(const CParaFormat& aParaFormat);
	TBool operator==(const CParaFormat& aFormat)const;
	TBool operator!=(const CParaFormat& aFormat)const;
private:
	CArrayFixFlat<TTabStop>* iTabList;  // Ordered list of TabStops.
	TParaBorderArray* iParaBorderArray;  // Defaults NULL.
public:
	TRgb iFillColor;  // Paragraph background color - default white
	TInt32 iLanguage;  // Integer coded language? - which to support?
	TInt32 iLeftMarginInTwips;
	TInt32 iRightMarginInTwips;
	//  Paragraph margins are relative to the page margins
	TInt32 iIndentInTwips;  // First line indent, relative to iLeftMargin
	TAlignment iHorizontalAlignment;
	TAlignment iVerticalAlignment;
	TInt32 iLineSpacingInTwips;  // Space between lines in a paragraph (twips)
	TLineSpacingControl iLineSpacingControl;  // AtLeast/Exactly iLineSpacing.
	TInt32 iSpaceBeforeInTwips;
	TInt32 iSpaceAfterInTwips;
	TBool iKeepTogether;  // Prevents page break in a paragraph when ETrue.
	TBool iKeepWithNext;  // Prevents page break between this & next para when ETrue.
	TBool iStartNewPage;  // Inserts page break before this paragraph when ETrue.
	TBool iWidowOrphan;  // Prevents widowing/orphaning of para. lines when ETrue.
	TBool iWrap;  // Inhibits paragraph line wrapping when EFalse.
	TInt32 iBorderMarginInTwips;  // Distance between paragraph border & enclosed text (NonNegative twips).
	TBullet* iBullet;  // Could be Null.
	TUint32 iDefaultTabWidthInTwips;
	};


// Used as an argument in CParaFormatLayer message sends.
// Used in conjunction with CParaFormat, this class 'tags' those 
// CParaFormat format attributes that should participate in set/sense actions
// of CParaFormatLayer.

class TParaFormatMask
	{
public:
	inline TParaFormatMask();
	//
	// Modify single attribute
	inline void SetAttrib(TTextFormatAttribute aAttribute);
	inline void ClearAttrib(TTextFormatAttribute aAttribute);
	//
	// Modify all attributes
	IMPORT_C void SetAll();
	IMPORT_C void ClearAll();
	//
	// Enquiry functions
	inline TBool AttribIsSet(TTextFormatAttribute aAttribute)const;
	inline TBool IsNull()const;
	IMPORT_C TBool operator==(const TParaFormatMask& aMask)const;
	inline TBool operator!=(const TParaFormatMask& aMask)const;
private:
	TUint32 iGuard;
	//
	friend class RFormatStream;
	};


//
// Specifies all font independent character format attributes.

class TFontPresentation
	{
public:
	enum TFontHighlightStyle
		{
		EFontHighlightNone,
		EFontHighlightNormal,
		EFontHighlightRounded
		};
	enum TAlignment
		{
		EAlignTop,
		EAlignBottom,
		EAlignCentered,
		EAlignBaseLine
		};
	//
	IMPORT_C TFontPresentation();
	//
	// Enquiry function
	IMPORT_C TBool IsEqual(const TFontPresentation& aFontPresentation,const TCharFormatMask& aMask)const;
public:
	TRgb iTextColor;
	TRgb iHighlightColor;  // Background color
	TFontHighlightStyle iHighlightStyle;
	TFontStrikethrough iStrikethrough;
	TFontUnderline iUnderline;
	TBool iHiddenText;
	TAlignment iPictureAlignment;
	};


// Specifies all character format attributes.
// Passed out of the LayDoc interface.

class TCharFormat
	{
public:
	IMPORT_C TCharFormat();
	IMPORT_C TCharFormat(const TDesC &aTypefaceName,TInt aHeight);
	//
	// Enquiry functions
	IMPORT_C TBool IsEqual(const TCharFormat& aFormat,const TCharFormatMask& aMask)const;
	IMPORT_C TBool IsEqual(const TCharFormat& aFormat)const;
public:
	TInt32 iLanguage;
	TFontPresentation iFontPresentation;  // Font independent character attributes
	TFontSpec iFontSpec;  // Device independant font specification.
	};


// This class is for use as an argument in CCharFormatLayer message sends.
// Used in conjunction with TCharFormat, this class 'tags' those 
// TCharFormat format attributes that should participate in set/sense actions
// of CCharFormatLayer.

class TCharFormatMask
	{
public:
	inline TCharFormatMask();
	//
	// Modify single attribute
	inline void SetAttrib(TTextFormatAttribute aAttribute);
	inline void ClearAttrib(TTextFormatAttribute aAttribute);
	//
	// Modify all attributes
	IMPORT_C void SetAll();
	IMPORT_C void ClearAll();
	//
	// Enquiry functions
	inline TBool AttribIsSet(TTextFormatAttribute aAttribute)const;
	inline TBool IsNull()const;
	IMPORT_C TBool operator==(const TCharFormatMask& aMask)const;
	inline TBool operator!=(const TCharFormatMask& aMask)const;
private:
	TInt32 iGuard;
	//
	friend class RFormatStream;
	};


class TParaBorderArray
	{
public:
	TParaBorder iBorder[4];
	};


#include <txtfrmat.inl>


#endif

