// TXTFMSTM.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

// PRIVATE HEADER FILE CONTAINING IMPLEMENTATION SPECIFIC CLASSES

#if !defined(__TXTFMSTM_H__)
#define __TXTFMSTM_H__

#if !defined(__E32STD_H__)
#include <e32std.h>
#endif

#if !defined(__TXTFRMAT_H__)
#include <txtfrmat.h>
#endif

//
// Classes defined in this file
class RFormatStream;
//
// Classes referenced
class RReadStream;
class RWriteStream;


//
// Provides streaming services to facilitate the storage of format attributes.

class RFormatStream
	{
private:
	friend class CFormatLayer;
	friend class CParaFormatLayer;
	friend class CCharFormatLayer;
	//
	// Special members
	RFormatStream::RFormatStream();
	void Reset();
public:
	//
	// Persistence
	void ExternalizeL(RWriteStream& aStream)const;
	void InternalizeL(RReadStream& aStream);
private:
	//
	// Utility
	const TUint8* Ptr(TInt& aSize)const;  // return a ptr to the start of the buffer, set asize to buf size
	//
	// Set/Sense
	void SetParaFormatL(const CParaFormat* aDesiredFormat,const TParaFormatMask& aDesiredMask,const CParaFormat* aCurrentFormat);
	void SetCharFormatL(const TCharFormat& aCharFormat,const TCharFormatMask& aMask);
	void SenseParaFormatL(CParaFormat* aParaFormat,TParaFormatMask& aMask,CParaFormat::TParaFormatGetMode aMode)const;
	void SenseCharFormat(TCharFormat& aCharFormat,TCharFormatMask& aMask)const;
private:
	void AllocL(TInt aSize);
	TInt Length(TUint8*& aPtr,TTextFormatAttribute aType)const;
	TInt DoCalcSizeParaFormat(const CParaFormat* aDesiredFormat,const TParaFormatMask& aDesiredMask,const CParaFormat* aCurrentFormat);
	void DoSetParaFormat(const CParaFormat* aDesiredFormat,const TParaFormatMask& aDesiredMask,const CParaFormat* aCurrentFormat);
	void RemoveRedundantCharFormat(TCharFormatMask& aMask,const TCharFormat& aFormat,const TCharFormat& aEffectiveFormat);
	TInt DoCalcSizeCharFormat(const TCharFormat& aCharFormat,const TCharFormatMask& aMask);
	void DoStoreCharFormat(const TCharFormat& aCharFormat,const TCharFormatMask& aMask);
	//
	// Store overloads
	TUint8* StoreBullet(TUint8* aPtr,const TBullet& aSource);
	TUint8* StoreBorder(TUint8* aPtr,TTextFormatAttribute aType,const TParaBorder& aSource);
	TUint8* StoreTab(TUint8* aPtr,const TTabStop& aSource);
	// Tabs
	TInt StoreTabsL(TUint8*& aPtr,const CParaFormat* aDesiredFormat,const CParaFormat* aCurrentFormat,TBool aStoreData);
	TInt MergeTabListsL(TUint8*& aPtr,const CParaFormat* aDesiredFormat,TInt aDesiredTabCount,
				const CParaFormat* aCurrentFormat,TInt aCurrentTabCount,TBool aStoreData);
	void StoreAllTabsL(TUint8*& aPtr,const CParaFormat* aSource,TInt aTabCount);
	//
	TUint8* Store(TUint8* aPtr,const TRgb& aRgb);			// write color values
	TUint8* Store(TUint8* aPtr,const TTypeface& aTypeface);  // write typeface name
	//
	// Restore methods
//	TTextFormatAttribute AttributeType(TUint8*& aPtr)const;
	TUint8* ReadValue(TUint8* aPtr,TRgb& aRgb)const;
	TUint8* ReadValue(TUint8* aPtr,TTypeface& aTypeface)const;
	TUint8* ReadValue(TUint8* aPtr,TParaBorder& aBorder)const;
	TUint8* ReadValue(TUint8* aPtr,TBullet& aBullet)const;
	TUint8* ReadTabL(TUint8* aPtr,CParaFormat* aTarget)const;
private:
	static const TInt8 iAttributeLength[EAttLast];  // Attribute-value length lookup table
	TUint8* iBase;
	TUint8* iEnd;  // points to the byte following the end of the REQUESTED buffer.
	__DECLARE_TEST;
	};

#endif
