textrendering/texthandling/inc/FLDSET.H
changeset 0 1fb32624e06b
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __FLDSET_H__
       
    20 #define __FLDSET_H__
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 #include <fldinfo.h>
       
    25 #include <fldbase.h>
       
    26 #include <fldbltin.h>
       
    27 
       
    28 //
       
    29 // Classes declared in this file
       
    30 class CTextFieldSet;
       
    31 //
       
    32 // Classes referenced
       
    33 class RReadStream;
       
    34 class RWriteStream;
       
    35 class TTextFieldEntry;
       
    36 class CStreamStore;
       
    37 class CStoreMap;
       
    38 class TRollbackInfo;
       
    39 
       
    40 /**
       
    41 @internalComponent
       
    42 */
       
    43 const TInt KFieldArrayGranularity=1;
       
    44 
       
    45 
       
    46 class CTextFieldSet : public CBase
       
    47 /**
       
    48 The engine that keeps the field table up to date
       
    49 @internalComponent
       
    50 */
       
    51 	{
       
    52 public:
       
    53 	enum {ENoPasteLimit=-1};
       
    54 public:
       
    55 	IMPORT_C static CTextFieldSet* NewL(TInt aDocumentLength=0);
       
    56 	IMPORT_C static CTextFieldSet* NewL(const MTextFieldFactory* aFactory,const CStreamStore& aStore,TStreamId aStreamId);
       
    57 	IMPORT_C ~CTextFieldSet();
       
    58 	//
       
    59 	// Factory functions
       
    60 	IMPORT_C void SetFieldFactory(MTextFieldFactory* aFactory);
       
    61 	IMPORT_C MTextFieldFactory* FieldFactory()const;
       
    62 	//
       
    63 	IMPORT_C void Reset(); // removes all fields from the array and reinitialises field array
       
    64 	//
       
    65 	// Persistence
       
    66 	IMPORT_C TStreamId StoreL(CStreamStore& aStore)const;
       
    67 	IMPORT_C void RestoreL(const CStreamStore& aFieldStore,TStreamId aStreamId);
       
    68 	//
       
    69 	// Component persistence
       
    70 	IMPORT_C void StoreFieldsL(CStreamStore& aStore,CStoreMap& aMap)const;
       
    71 	IMPORT_C void RestoreFieldsL(const CStreamStore& aFieldStore);
       
    72 	//
       
    73 	// Headstream persistence
       
    74 	IMPORT_C void InternalizeL(RReadStream& aStream);
       
    75 	IMPORT_C void ExternalizeL(RWriteStream& aStream)const;
       
    76 	//	Cut/Paste
       
    77 	IMPORT_C TStreamId CopyToStoreL(CStreamStore& aStore,TInt aPos,TInt aLength)const;
       
    78 	IMPORT_C void CopyComponentsL(CStreamStore& aStore,CStoreMap& aMap,TInt aPos,TInt aLength)const;
       
    79 	IMPORT_C void CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength)const;
       
    80 	IMPORT_C void PasteFromStoreL(const CStreamStore& aFieldStore,TStreamId aStreamId,TInt aPos,TInt aMaxLen=ENoPasteLimit);
       
    81 	IMPORT_C void PasteComponentsL(const CStreamStore& aFieldStore,TInt aPos);
       
    82 	IMPORT_C void PasteFromStreamL(RReadStream& aStream,TInt aPos,TInt aMaxLen=ENoPasteLimit);
       
    83 	// Insert/Remove field
       
    84 	IMPORT_C CTextField* NewFieldL(TUid aFieldType);
       
    85 	IMPORT_C TInt InsertFieldL(TInt aPos,CTextField* aField,TUid aFieldType); // inserts a field (including text) into doc (returns error num if it fails)
       
    86 	IMPORT_C TInt RemoveField(TInt aPos); // remove the field aPos is in
       
    87 	IMPORT_C TInt NewFieldValueL(HBufC*& aBuf, TInt aPos); // returns new value of the field in aBuf (or returns false if aPos not in field)
       
    88 	// Update field set
       
    89 	IMPORT_C void NotifyInsertion(TInt aPos, TInt aNumberAdded);
       
    90 	IMPORT_C void NotifyDeletion(TInt aPos, TInt aNumberRemoved);
       
    91 	IMPORT_C void NotifyFieldUpdate(TInt aPos, TInt aNewFieldValueLength);
       
    92 	// Utilities
       
    93 	IMPORT_C TInt FieldCount() const; // returns total number of fields in document
       
    94 	IMPORT_C TInt CharCount() const; // returns num characters in the document (according to fields)
       
    95 	IMPORT_C TBool FindFields(TInt aPos) const; // Returns ETrue if aPos is in a field
       
    96 	IMPORT_C TBool FindFields(TFindFieldInfo& aInfo,TInt aPos,TInt aRange=0) const; // finds num fields at least partly in range. Returns true if aPos is in field, and returns info on the first field in aRange
       
    97 	IMPORT_C const CTextField* TextField(TInt aPos)const;
       
    98 	// Rollback
       
    99 	IMPORT_C void RollbackPaste(); // call to carry out rollback if a paste goes wrong
       
   100 protected:
       
   101 	CTextFieldSet();
       
   102 	void ConstructL(TInt aDocumentLength);
       
   103 	void ConstructL(const CStreamStore& aFieldStore,TStreamId aStreamId);
       
   104 private:
       
   105 	// persistence
       
   106 	void StoreFieldsL(CStreamStore& aStore,CStoreMap& aMap,CArrayFixSeg<TTextFieldEntry>* aArray)const;
       
   107 	void DoRestoreL(const CStreamStore& aFieldStore,TStreamId aStreamId);
       
   108 	void DoRestoreFieldsL(CArrayFixSeg<TTextFieldEntry>* aArray,const CStreamStore& aFieldStore,TInt aStartIndex=0);
       
   109 	void InternalizeL(CArrayFixSeg<TTextFieldEntry>* aArray,RReadStream& aStream);
       
   110 	void ExternalizeL(RWriteStream& aStream,CArrayFixSeg<TTextFieldEntry>* aArray)const;
       
   111 	void DoPasteL(CArrayFixSeg<TTextFieldEntry>* aSourceArray,TInt aPos);
       
   112 	// utility functions
       
   113 	void AddInitialFieldEntryL(CArrayFixSeg<TTextFieldEntry>* aArray,TInt aDocumentLength); // used to initialise the array
       
   114 	void InsertEntryL(TInt aIndex,TTextFieldEntry& aEntry); // inserts into iFieldArray
       
   115 	void InsertEntryL(TInt aIndex,TTextFieldEntry& aEntry,CArrayFixSeg<TTextFieldEntry>* aArray);
       
   116 	void AppendEntryL(TTextFieldEntry& aEntry); // appends into iFieldArray
       
   117 	void AppendEntryL(TTextFieldEntry& aEntry,CArrayFixSeg<TTextFieldEntry>* aArray);
       
   118 	void CopyToArrayL(CArrayFixSeg<TTextFieldEntry>* aArray,TInt aPos,TInt aLength)const;
       
   119 	TBool InField(const TInt aPos, TInt& anIndex, TInt& anOffset) const; // anOffset set to distance into field or gap
       
   120 	void DeleteFieldEntry(TInt anIndex);
       
   121 	void DeleteFieldEntry(CArrayFixSeg<TTextFieldEntry>* aArray,TInt anIndex);
       
   122 	TTextFieldEntry SplitEntry(TInt aIndex,TInt aOffset,TInt aRange)const;
       
   123 	TInt EntryLen(const TTextFieldEntry& aEntry)const;
       
   124 	TInt EntryLen(TInt aIndex)const;
       
   125 	// rollback
       
   126 	void RecordRollbackInfoL(TInt aPastePos);
       
   127 private:
       
   128 	MTextFieldFactory* iFieldFactory;
       
   129 	CArrayFixSeg<TTextFieldEntry>* iFieldArray; // Array of fields in the document
       
   130 	TRollbackInfo* iRollbackInfo;
       
   131 	__DECLARE_TEST;
       
   132 	};
       
   133 
       
   134 class TFieldMapExternalizer : public MExternalizer<TStreamRef>
       
   135 /**
       
   136 Allows NULL streams id's to be written out
       
   137 when no reference is found in a store map.
       
   138 @internalComponent
       
   139 */
       
   140 	{
       
   141 private:
       
   142 	friend class CPlainText;
       
   143 	friend class CTextFieldSet;
       
   144 private:
       
   145 	IMPORT_C TFieldMapExternalizer(const CStoreMap& aMap);
       
   146 	IMPORT_C void ExternalizeL(const TStreamRef& anObject,RWriteStream& aStream) const;
       
   147 private:
       
   148 	const CStoreMap* iMap;
       
   149 	};
       
   150 
       
   151 #endif