1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
26 // Classes declared in this file
32 class TTextFieldEntry;
40 const TInt KFieldArrayGranularity=1;
43 class CTextFieldSet : public CBase
45 The engine that keeps the field table up to date
50 enum {ENoPasteLimit=-1};
52 IMPORT_C static CTextFieldSet* NewL(TInt aDocumentLength=0);
53 IMPORT_C static CTextFieldSet* NewL(const MTextFieldFactory* aFactory,const CStreamStore& aStore,TStreamId aStreamId);
54 IMPORT_C ~CTextFieldSet();
57 IMPORT_C void SetFieldFactory(MTextFieldFactory* aFactory);
58 IMPORT_C MTextFieldFactory* FieldFactory()const;
60 IMPORT_C void Reset(); // removes all fields from the array and reinitialises field array
63 IMPORT_C TStreamId StoreL(CStreamStore& aStore)const;
64 IMPORT_C void RestoreL(const CStreamStore& aFieldStore,TStreamId aStreamId);
66 // Component persistence
67 IMPORT_C void StoreFieldsL(CStreamStore& aStore,CStoreMap& aMap)const;
68 IMPORT_C void RestoreFieldsL(const CStreamStore& aFieldStore);
70 // Headstream persistence
71 IMPORT_C void InternalizeL(RReadStream& aStream);
72 IMPORT_C void ExternalizeL(RWriteStream& aStream)const;
74 IMPORT_C TStreamId CopyToStoreL(CStreamStore& aStore,TInt aPos,TInt aLength)const;
75 IMPORT_C void CopyComponentsL(CStreamStore& aStore,CStoreMap& aMap,TInt aPos,TInt aLength)const;
76 IMPORT_C void CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength)const;
77 IMPORT_C void PasteFromStoreL(const CStreamStore& aFieldStore,TStreamId aStreamId,TInt aPos,TInt aMaxLen=ENoPasteLimit);
78 IMPORT_C void PasteComponentsL(const CStreamStore& aFieldStore,TInt aPos);
79 IMPORT_C void PasteFromStreamL(RReadStream& aStream,TInt aPos,TInt aMaxLen=ENoPasteLimit);
80 // Insert/Remove field
81 IMPORT_C CTextField* NewFieldL(TUid aFieldType);
82 IMPORT_C TInt InsertFieldL(TInt aPos,CTextField* aField,TUid aFieldType); // inserts a field (including text) into doc (returns error num if it fails)
83 IMPORT_C TInt RemoveField(TInt aPos); // remove the field aPos is in
84 IMPORT_C TInt NewFieldValueL(HBufC*& aBuf, TInt aPos); // returns new value of the field in aBuf (or returns false if aPos not in field)
86 IMPORT_C void NotifyInsertion(TInt aPos, TInt aNumberAdded);
87 IMPORT_C void NotifyDeletion(TInt aPos, TInt aNumberRemoved);
88 IMPORT_C void NotifyFieldUpdate(TInt aPos, TInt aNewFieldValueLength);
90 IMPORT_C TInt FieldCount() const; // returns total number of fields in document
91 IMPORT_C TInt CharCount() const; // returns num characters in the document (according to fields)
92 IMPORT_C TBool FindFields(TInt aPos) const; // Returns ETrue if aPos is in a field
93 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
94 IMPORT_C const CTextField* TextField(TInt aPos)const;
96 IMPORT_C void RollbackPaste(); // call to carry out rollback if a paste goes wrong
99 void ConstructL(TInt aDocumentLength);
100 void ConstructL(const CStreamStore& aFieldStore,TStreamId aStreamId);
103 void StoreFieldsL(CStreamStore& aStore,CStoreMap& aMap,CArrayFixSeg<TTextFieldEntry>* aArray)const;
104 void DoRestoreL(const CStreamStore& aFieldStore,TStreamId aStreamId);
105 void DoRestoreFieldsL(CArrayFixSeg<TTextFieldEntry>* aArray,const CStreamStore& aFieldStore,TInt aStartIndex=0);
106 void InternalizeL(CArrayFixSeg<TTextFieldEntry>* aArray,RReadStream& aStream);
107 void ExternalizeL(RWriteStream& aStream,CArrayFixSeg<TTextFieldEntry>* aArray)const;
108 void DoPasteL(CArrayFixSeg<TTextFieldEntry>* aSourceArray,TInt aPos);
110 void AddInitialFieldEntryL(CArrayFixSeg<TTextFieldEntry>* aArray,TInt aDocumentLength); // used to initialise the array
111 void InsertEntryL(TInt aIndex,TTextFieldEntry& aEntry); // inserts into iFieldArray
112 void InsertEntryL(TInt aIndex,TTextFieldEntry& aEntry,CArrayFixSeg<TTextFieldEntry>* aArray);
113 void AppendEntryL(TTextFieldEntry& aEntry); // appends into iFieldArray
114 void AppendEntryL(TTextFieldEntry& aEntry,CArrayFixSeg<TTextFieldEntry>* aArray);
115 void CopyToArrayL(CArrayFixSeg<TTextFieldEntry>* aArray,TInt aPos,TInt aLength)const;
116 TBool InField(const TInt aPos, TInt& anIndex, TInt& anOffset) const; // anOffset set to distance into field or gap
117 void DeleteFieldEntry(TInt anIndex);
118 void DeleteFieldEntry(CArrayFixSeg<TTextFieldEntry>* aArray,TInt anIndex);
119 TTextFieldEntry SplitEntry(TInt aIndex,TInt aOffset,TInt aRange)const;
120 TInt EntryLen(const TTextFieldEntry& aEntry)const;
121 TInt EntryLen(TInt aIndex)const;
123 void RecordRollbackInfoL(TInt aPastePos);
125 MTextFieldFactory* iFieldFactory;
126 CArrayFixSeg<TTextFieldEntry>* iFieldArray; // Array of fields in the document
127 TRollbackInfo* iRollbackInfo;
131 class TFieldMapExternalizer : public MExternalizer<TStreamRef>
133 Allows NULL streams id's to be written out
134 when no reference is found in a store map.
139 friend class CPlainText;
140 friend class CTextFieldSet;
142 IMPORT_C TFieldMapExternalizer(const CStoreMap& aMap);
143 IMPORT_C void ExternalizeL(const TStreamRef& anObject,RWriteStream& aStream) const;
145 const CStoreMap* iMap;