32
|
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 |
#include <e32std.h>
|
|
20 |
#include <e32base.h>
|
|
21 |
|
|
22 |
#include <s32std.h>
|
|
23 |
#include <s32strm.h>
|
|
24 |
#include <s32stor.h>
|
|
25 |
#include <s32mem.h>
|
|
26 |
#include <s32file.h>
|
|
27 |
#include <s32ucmp.h>
|
|
28 |
|
|
29 |
#include <fepitfr.h>
|
|
30 |
|
|
31 |
#include "FLDDEF.H"
|
|
32 |
#include "FLDINFO.H"
|
|
33 |
#include "FLDSET.H"
|
|
34 |
|
|
35 |
#include "TXTETEXT.H"
|
|
36 |
#include "TXTRICH.H"
|
|
37 |
#include "TXTOPT.H"
|
|
38 |
#include "TXTFEP.H"
|
|
39 |
#include "TXTPLAIN.H"
|
|
40 |
#include "TXTSTD.H"
|
|
41 |
#include "TXTRTPFL.H"
|
|
42 |
#include "TXTCLIPBOARD.H"
|
|
43 |
|
|
44 |
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
|
|
45 |
#include "TXTETEXT_INTERNAL.H"
|
|
46 |
#endif
|
|
47 |
|
|
48 |
const TUint KFieldCountLimit = 255;
|
|
49 |
#define UNUSED_VAR(a) a = a
|
|
50 |
|
|
51 |
// Write some or all of the text in a buffer to a stream, writing the length first if aWriteLength is true.
|
|
52 |
static void ExternalizeTextL(RWriteStream& aStream,const CBufBase& aText,TInt aPos,TInt aLength,TBool aWriteLength)
|
|
53 |
{
|
|
54 |
if (aWriteLength)
|
|
55 |
aStream << TCardinality(aLength);
|
|
56 |
|
|
57 |
// Use the Standard Unicode Compression Scheme.
|
|
58 |
RBufReadStream input_stream(aText,aPos * sizeof(TText));
|
|
59 |
TMemoryStreamUnicodeSource source(input_stream);
|
|
60 |
TUnicodeCompressor c;
|
|
61 |
c.CompressL(aStream,source,KMaxTInt,aLength);
|
|
62 |
input_stream.Close();
|
|
63 |
}
|
|
64 |
|
|
65 |
// Read text from a stream and write it to a buffer.
|
|
66 |
static void InternalizeTextL(RReadStream& aStream,CBufBase& aText,TInt aLength)
|
|
67 |
{
|
|
68 |
// Use the Standard Unicode Compression Scheme.
|
|
69 |
RBufWriteStream output_stream(aText);
|
|
70 |
TMemoryStreamUnicodeSink sink(output_stream);
|
|
71 |
TUnicodeExpander e;
|
|
72 |
e.ExpandL(sink,aStream,aLength);
|
|
73 |
output_stream.CommitL();
|
|
74 |
output_stream.Close();
|
|
75 |
}
|
|
76 |
|
|
77 |
// Read text from a stream and write it to a buffer; read the length first.
|
|
78 |
static void InternalizeTextL(RReadStream& aStream,CBufBase& aText)
|
|
79 |
{
|
|
80 |
TCardinality length;
|
|
81 |
aStream >> length;
|
|
82 |
InternalizeTextL(aStream,aText,length);
|
|
83 |
}
|
|
84 |
/**
|
|
85 |
Returns the interface corresponding to the
|
|
86 |
specified UID if it exists, or 0 if not. Overridden
|
|
87 |
versions should base call rather than returning 0.
|
|
88 |
|
|
89 |
@param aInterfaceId The UID indicating the interface to return
|
|
90 |
@param aInterface The interface corresponding to aInterfaceId
|
|
91 |
if it is supported, or 0 if it is not
|
|
92 |
*/
|
|
93 |
EXPORT_C void CEditableText::ExtendedInterface(TAny*& /*aInterface*/, TUid /*aInterfaceId*/) {}
|
|
94 |
|
|
95 |
/**
|
|
96 |
Returns the interface corresponding to the
|
|
97 |
specified UID if it exists, or 0 if not. Overridden
|
|
98 |
versions should base call rather than returning 0.
|
|
99 |
|
|
100 |
@param aInterfaceId The UID indicating the interface to return
|
|
101 |
@param aInterface The interface corresponding to aInterfaceId
|
|
102 |
if it is supported, or 0 if it is not
|
|
103 |
*/
|
|
104 |
EXPORT_C void CPlainText::ExtendedInterface(TAny*& /*aInterface*/, TUid /*aInterfaceId*/) {}
|
|
105 |
|
|
106 |
/**
|
|
107 |
@internalAll
|
|
108 |
@released
|
|
109 |
*/
|
|
110 |
EXPORT_C void CPlainText::Reserved_2() {}
|
|
111 |
|
|
112 |
//////////////////////////////////
|
|
113 |
// CEditableText
|
|
114 |
//////////////////////////////////
|
|
115 |
|
|
116 |
EXPORT_C CEditableText::~CEditableText()
|
|
117 |
{
|
|
118 |
delete iOptionalData;
|
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
EXPORT_C TInt CEditableText::ScanWords(TInt& /*aPos*/,TUint& /*aScanMask*/) const
|
|
124 |
/** Scans the text from a specified document position to a location
|
|
125 |
determined by the flags specified in a bitmask. The function can scan
|
|
126 |
forwards or backwards to the beginning or end of a word.
|
|
127 |
|
|
128 |
@param aPos A valid document position from which to scan. On return,
|
|
129 |
contains the new document position.
|
|
130 |
@param aScanMask The scan mask to use. See the scanning enumeration defined
|
|
131 |
in class CPlainText.
|
|
132 |
@return The number of characters skipped to reach the new document position.
|
|
133 |
Notes: If the scan passes the end of text delimiter, on return, aPos is set
|
|
134 |
to EScanEndOfData and the function's return value indicates the
|
|
135 |
number of characters skipped in passing the end of text delimiter. */
|
|
136 |
{
|
|
137 |
return 0;
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
EXPORT_C TInt CEditableText::ScanParas(TInt& /*aPos*/,TUint& /*aScanMask*/) const
|
|
142 |
/** Scans the text from a specified document position to a location determined
|
|
143 |
by the flags specified in a bitmask. The function can scan forwards or backwards
|
|
144 |
to the beginning or end of a paragraph.
|
|
145 |
|
|
146 |
@param aPos A valid document position from which to scan. On return, contains
|
|
147 |
the new document position.
|
|
148 |
@param aScanMask The scan mask to use. See the scanning enumeration defined
|
|
149 |
in class CPlainText.
|
|
150 |
@return The number of characters skipped to reach the new document position.
|
|
151 |
Notes: If the scan passes the end of text delimiter, on return, aPos is set
|
|
152 |
to EScanEndOfData and the function's return value indicates the
|
|
153 |
number of characters skipped in passing the end of text delimiter. */
|
|
154 |
{
|
|
155 |
return 0;
|
|
156 |
}
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
EXPORT_C void CEditableText::SetHasChanged(TBool aHasChanged)
|
|
161 |
/** Sets whether a change has occurred to the editable text object. This is called
|
|
162 |
by functions which change the text object in some way.
|
|
163 |
|
|
164 |
@param aHasChanged ETrue if a change has occurred to the text object. EFalse
|
|
165 |
if no change has occurred. */
|
|
166 |
{
|
|
167 |
iHasChanged = aHasChanged;
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
// Save the editable text type identifier.
|
|
172 |
void CEditableText::ExternalizeL(RWriteStream& aStream)const
|
|
173 |
{
|
|
174 |
aStream << KEditableTextUid;
|
|
175 |
}
|
|
176 |
|
|
177 |
|
|
178 |
void CEditableText::InternalizeL(RReadStream& aStream)
|
|
179 |
// Read from the stream, expecting the editable text type identifier
|
|
180 |
//
|
|
181 |
{
|
|
182 |
TUid uid;
|
|
183 |
aStream>> uid;
|
|
184 |
if (uid!=KEditableTextUid)
|
|
185 |
User::Leave(KErrCorrupt);
|
|
186 |
}
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
EXPORT_C TStreamId CEditableText::StoreL(CStreamStore& aStore)const
|
|
192 |
/** Stores the text and its components. The components (e.g. fields and pictures)
|
|
193 |
are stored in separate streams within the stream store.
|
|
194 |
|
|
195 |
@param aStore Stream store to which the text and text components are written.
|
|
196 |
@return The ID of the stream store. */
|
|
197 |
{
|
|
198 |
CStoreMap* map=CStoreMap::NewLC(aStore);
|
|
199 |
StoreComponentsL(aStore,*map);
|
|
200 |
//
|
|
201 |
RStoreWriteStream stream(*map);
|
|
202 |
TStreamId id=stream.CreateLC(aStore);
|
|
203 |
stream<< *this;
|
|
204 |
stream.CommitL();
|
|
205 |
//
|
|
206 |
map->Reset();
|
|
207 |
CleanupStack::PopAndDestroy(2); // map,stream
|
|
208 |
return id;
|
|
209 |
}
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
EXPORT_C void CEditableText::RestoreL(const CStreamStore& aStore,TStreamId aStreamId)
|
|
214 |
/** Restores the text and its components from a stream store.
|
|
215 |
|
|
216 |
@param aStore Stream store containing the text and its components.
|
|
217 |
@param aStreamId The ID of the stream store in which the text was previously
|
|
218 |
stored. */
|
|
219 |
{
|
|
220 |
// Load text and field components only. (Pictures, if present, are deferred loaded).
|
|
221 |
__ETEXT_WATCH(RESTORE)
|
|
222 |
|
|
223 |
RStoreReadStream stream;
|
|
224 |
stream.OpenLC(aStore,aStreamId);
|
|
225 |
//
|
|
226 |
stream>> *this;
|
|
227 |
CleanupStack::PopAndDestroy(); // stream
|
|
228 |
RestoreComponentsL(aStore);
|
|
229 |
|
|
230 |
__ETEXT_WATCH_END(RESTORE)
|
|
231 |
}
|
|
232 |
|
|
233 |
TBool CEditableText::DeleteWithoutDestroyingFormatL(TInt aPos, TInt aLength)
|
|
234 |
/** Deletes a range of characters. For rich text the format of the deleted character
|
|
235 |
at position aPos is preserved, so that any text subsequently inserted at aPos will have
|
|
236 |
that format applied to it.
|
|
237 |
@param aPos The document position from which to begin deleting including aPos.
|
|
238 |
@param aLength The number of characters to delete. Must be positive or a panic
|
|
239 |
occurs. The sum of aPos and aLength must be less than the document length,
|
|
240 |
or a panic occurs.
|
|
241 |
@return Indicates whether two paragraphs have been merged together as a result
|
|
242 |
of the delete, indicating that the resulting paragraph must be reformatted.
|
|
243 |
*/
|
|
244 |
{
|
|
245 |
TAny* richTextInterface = NULL;
|
|
246 |
ExtendedInterface(richTextInterface, KUidRichText);
|
|
247 |
|
|
248 |
if(richTextInterface)
|
|
249 |
{
|
|
250 |
return REINTERPRET_CAST(CRichText*, richTextInterface)->DelSetInsertCharFormatL(aPos, aLength);
|
|
251 |
}
|
|
252 |
else
|
|
253 |
{
|
|
254 |
return DeleteL(aPos, aLength);
|
|
255 |
}
|
|
256 |
}
|
|
257 |
|
|
258 |
EXPORT_C void CEditableText::StartFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aInitialInlineText,TInt aPositionOfInlineTextInDocument,TInt aNumberOfCharactersToHide,MFepInlineTextFormatRetriever& aInlineTextFormatRetriever)
|
|
259 |
/** @internalAll */
|
|
260 |
{
|
|
261 |
__ASSERT_ALWAYS(aPositionOfInlineTextInDocument>=0 && aNumberOfCharactersToHide>=0 && aPositionOfInlineTextInDocument+aNumberOfCharactersToHide<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
262 |
__ASSERT_ALWAYS(InlineEditData()==NULL,Panic(EAlreadyFepInlineEditing));
|
|
263 |
aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
|
|
264 |
aNumberOfCharactersSuccessfullyDeleted=0;
|
|
265 |
aNumberOfCharactersSuccessfullyInserted=0;
|
|
266 |
CInlineEditData* const inlineEditData=new(ELeave) CInlineEditData;
|
|
267 |
CleanupStack::PushL(inlineEditData);
|
|
268 |
HBufC* hiddenText=NULL;
|
|
269 |
CleanupStack::PushL(hiddenText);
|
|
270 |
if (aNumberOfCharactersToHide>0)
|
|
271 |
{
|
|
272 |
CleanupStack::Pop(); // hiddenText
|
|
273 |
hiddenText=HBufC::NewLC(aNumberOfCharactersToHide);
|
|
274 |
TPtr hiddenTextAsWritableDescriptor=hiddenText->Des();
|
|
275 |
Extract(hiddenTextAsWritableDescriptor,aPositionOfInlineTextInDocument,aNumberOfCharactersToHide);
|
|
276 |
aParagraphContainingStartPositionOfInlineTextHasChangedFormat=DeleteWithoutDestroyingFormatL(aPositionOfInlineTextInDocument,aNumberOfCharactersToHide);
|
|
277 |
aNumberOfCharactersSuccessfullyDeleted=aNumberOfCharactersToHide;
|
|
278 |
aPositionOfInsertionPointInDocument=aPositionOfInlineTextInDocument;
|
|
279 |
}
|
|
280 |
inlineEditData->iPositionOfInlineTextInDocument=aPositionOfInlineTextInDocument;
|
|
281 |
inlineEditData->iLengthOfInlineText=aInitialInlineText.Length();
|
|
282 |
inlineEditData->iInlineText=aInitialInlineText.AllocL();
|
|
283 |
inlineEditData->iHiddenText=hiddenText;
|
|
284 |
CleanupStack::Pop(); // hiddentext now owned by inlineEditData.
|
|
285 |
inlineEditData->iInlineTextFormatRetriever=&aInlineTextFormatRetriever;
|
|
286 |
InsertL(aPositionOfInlineTextInDocument,aInitialInlineText);
|
|
287 |
SetAndTransferOwnershipOfInlineEditDataL(inlineEditData);
|
|
288 |
CleanupStack::Pop(); // inlineEditData
|
|
289 |
aNumberOfCharactersSuccessfullyInserted=inlineEditData->iLengthOfInlineText;
|
|
290 |
aPositionOfInsertionPointInDocument=aNewPositionOfInsertionPointInDocument;
|
|
291 |
}
|
|
292 |
|
|
293 |
|
|
294 |
EXPORT_C void CEditableText::UpdateFepInlineTextL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aNewInlineText)
|
|
295 |
/** @internalAll */
|
|
296 |
{
|
|
297 |
CInlineEditData* const inlineEditData=InlineEditData();
|
|
298 |
__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
|
|
299 |
aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
|
|
300 |
aNumberOfCharactersSuccessfullyDeleted=0;
|
|
301 |
aNumberOfCharactersSuccessfullyInserted=0;
|
|
302 |
HBufC*& inlineText=inlineEditData->iInlineText;
|
|
303 |
HBufC* oldInlineText=inlineText;
|
|
304 |
__ASSERT_DEBUG(oldInlineText==NULL || inlineEditData->iLengthOfInlineText==oldInlineText->Length(),Panic(EDebug));
|
|
305 |
const TInt lengthOfNewInlineText=aNewInlineText.Length();
|
|
306 |
if (oldInlineText!=NULL && *oldInlineText==aNewInlineText)
|
|
307 |
{
|
|
308 |
aNumberOfCharactersSuccessfullyDeleted=lengthOfNewInlineText;
|
|
309 |
aNumberOfCharactersSuccessfullyInserted=lengthOfNewInlineText;
|
|
310 |
}
|
|
311 |
else
|
|
312 |
{
|
|
313 |
if (oldInlineText==NULL)
|
|
314 |
{
|
|
315 |
oldInlineText=HBufC::NewL(lengthOfNewInlineText);
|
|
316 |
}
|
|
317 |
else if (lengthOfNewInlineText>oldInlineText->Length())
|
|
318 |
{
|
|
319 |
oldInlineText=oldInlineText->ReAllocL(lengthOfNewInlineText);
|
|
320 |
}
|
|
321 |
CleanupStack::PushL(oldInlineText);
|
|
322 |
inlineText=NULL; // sets inlineEditData->iLengthOfInlineText in case either the delete or the insert leaves
|
|
323 |
const TInt positionOfInlineTextInDocument=inlineEditData->iPositionOfInlineTextInDocument;
|
|
324 |
TInt& lengthOfInlineText=inlineEditData->iLengthOfInlineText;
|
|
325 |
if (lengthOfInlineText>0)
|
|
326 |
{
|
|
327 |
aParagraphContainingStartPositionOfInlineTextHasChangedFormat=DeleteWithoutDestroyingFormatL(positionOfInlineTextInDocument,lengthOfInlineText);
|
|
328 |
aNumberOfCharactersSuccessfullyDeleted=lengthOfInlineText;
|
|
329 |
lengthOfInlineText=0; // sets inlineEditData->iLengthOfInlineText in case the insert leaves
|
|
330 |
aPositionOfInsertionPointInDocument=inlineEditData->iPositionOfInlineTextInDocument;
|
|
331 |
}
|
|
332 |
InsertL(positionOfInlineTextInDocument,aNewInlineText);
|
|
333 |
lengthOfInlineText=aNewInlineText.Length(); // sets inlineEditData->iLengthOfInlineText
|
|
334 |
aNumberOfCharactersSuccessfullyInserted=lengthOfInlineText;
|
|
335 |
inlineText=oldInlineText;
|
|
336 |
CleanupStack::Pop(); // oldInlineText
|
|
337 |
*oldInlineText=aNewInlineText;
|
|
338 |
}
|
|
339 |
aPositionOfInsertionPointInDocument=aNewPositionOfInsertionPointInDocument;
|
|
340 |
}
|
|
341 |
|
|
342 |
|
|
343 |
EXPORT_C void CEditableText::CommitFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument)
|
|
344 |
/**
|
|
345 |
* @internalAll
|
|
346 |
*/
|
|
347 |
{
|
|
348 |
const CInlineEditData* const inlineEditData=InlineEditData();
|
|
349 |
__ASSERT_ALWAYS(inlineEditData!=NULL,Panic(ENotCurrentlyFepInlineEditing));
|
|
350 |
__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || inlineEditData->iLengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
|
|
351 |
aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
|
|
352 |
const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
|
|
353 |
aNumberOfCharactersSuccessfullyDeleted=lengthOfInlineText;
|
|
354 |
aNumberOfCharactersSuccessfullyInserted=lengthOfInlineText;
|
|
355 |
aPositionOfInsertionPointInDocument=aNewPositionOfInsertionPointInDocument;
|
|
356 |
DeleteInlineEditDataAndSetToNull();
|
|
357 |
}
|
|
358 |
|
|
359 |
|
|
360 |
EXPORT_C void CEditableText::CancelFepInlineEdit(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument)
|
|
361 |
/**
|
|
362 |
* @internalAll
|
|
363 |
*/
|
|
364 |
{
|
|
365 |
aParagraphContainingStartPositionOfInlineTextHasChangedFormat=EFalse;
|
|
366 |
aNumberOfCharactersSuccessfullyDeleted=0;
|
|
367 |
aNumberOfCharactersSuccessfullyInserted=0;
|
|
368 |
const CInlineEditData* inlineEditData=InlineEditData();
|
|
369 |
if (inlineEditData!=NULL)
|
|
370 |
{
|
|
371 |
const TInt positionOfInlineTextInDocument=inlineEditData->iPositionOfInlineTextInDocument;
|
|
372 |
const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
|
|
373 |
__ASSERT_DEBUG(inlineEditData->iInlineText==NULL || lengthOfInlineText==inlineEditData->iInlineText->Length(),Panic(EDebug));
|
|
374 |
TRAPD(notUsed,
|
|
375 |
if (lengthOfInlineText>0)
|
|
376 |
{
|
|
377 |
aParagraphContainingStartPositionOfInlineTextHasChangedFormat=DeleteWithoutDestroyingFormatL(positionOfInlineTextInDocument,lengthOfInlineText);
|
|
378 |
aNumberOfCharactersSuccessfullyDeleted=lengthOfInlineText;
|
|
379 |
aPositionOfInsertionPointInDocument=inlineEditData->iPositionOfInlineTextInDocument;
|
|
380 |
}
|
|
381 |
const HBufC* const hiddenText=inlineEditData->iHiddenText;
|
|
382 |
if (hiddenText!=NULL)
|
|
383 |
{
|
|
384 |
__ASSERT_DEBUG(hiddenText->Length()>0, Panic(EDebug));
|
|
385 |
InsertL(positionOfInlineTextInDocument,*hiddenText);
|
|
386 |
aNumberOfCharactersSuccessfullyInserted=hiddenText->Length();
|
|
387 |
aPositionOfInsertionPointInDocument=aNewPositionOfInsertionPointInDocument;
|
|
388 |
}
|
|
389 |
);
|
|
390 |
UNUSED_VAR(notUsed);
|
|
391 |
DeleteInlineEditDataAndSetToNull();
|
|
392 |
}
|
|
393 |
}
|
|
394 |
|
|
395 |
EXPORT_C void CEditableText::OverrideFormatOfInlineTextIfApplicable(TPtrC& aView,TCharFormat& aFormat,TInt aStartPos)const
|
|
396 |
{
|
|
397 |
const CInlineEditData* inlineEditData=InlineEditData();
|
|
398 |
if (inlineEditData!=NULL)
|
|
399 |
{
|
|
400 |
const TInt positionOfInlineTextInDocument=inlineEditData->iPositionOfInlineTextInDocument;
|
|
401 |
const TInt lengthOfInlineText=inlineEditData->iLengthOfInlineText;
|
|
402 |
const TInt originalLengthOfView=aView.Length();
|
|
403 |
TInt maximumLengthOfView=originalLengthOfView;
|
|
404 |
if (aStartPos<positionOfInlineTextInDocument)
|
|
405 |
{
|
|
406 |
maximumLengthOfView=positionOfInlineTextInDocument-aStartPos;
|
|
407 |
}
|
|
408 |
else if (aStartPos<positionOfInlineTextInDocument+lengthOfInlineText)
|
|
409 |
{
|
|
410 |
inlineEditData->iInlineTextFormatRetriever->GetFormatOfFepInlineText(aFormat,maximumLengthOfView,aStartPos-positionOfInlineTextInDocument);
|
|
411 |
}
|
|
412 |
if (originalLengthOfView>maximumLengthOfView)
|
|
413 |
{
|
|
414 |
aView.Set(aView.Left(maximumLengthOfView));
|
|
415 |
}
|
|
416 |
}
|
|
417 |
}
|
|
418 |
|
|
419 |
|
|
420 |
EXPORT_C TInt CEditableText::GetPositionOfInlineTextInDocument() const
|
|
421 |
{
|
|
422 |
const CInlineEditData* inlineEditData=InlineEditData();
|
|
423 |
if (inlineEditData==NULL)
|
|
424 |
return KErrNotFound;
|
|
425 |
return inlineEditData->iPositionOfInlineTextInDocument;
|
|
426 |
}
|
|
427 |
|
|
428 |
|
|
429 |
EXPORT_C TInt CEditableText::GetLengthOfInlineText() const
|
|
430 |
{
|
|
431 |
const CInlineEditData* inlineEditData=InlineEditData();
|
|
432 |
if (inlineEditData==NULL)
|
|
433 |
return KErrNotFound;
|
|
434 |
return inlineEditData->iLengthOfInlineText;
|
|
435 |
}
|
|
436 |
|
|
437 |
|
|
438 |
//////////////////////////////////
|
|
439 |
// TEtextComponentInfo
|
|
440 |
//////////////////////////////////
|
|
441 |
|
|
442 |
|
|
443 |
|
|
444 |
EXPORT_C TEtextComponentInfo::TEtextComponentInfo()
|
|
445 |
: iFieldCount(0),iPictureCount(0),iStyleCount(0)
|
|
446 |
/** C++ constructor overloaded function.
|
|
447 |
|
|
448 |
The object can be constructed either:by default this initializes the
|
|
449 |
field, picture and style counts to zerowith a field, picture and style
|
|
450 |
count
|
|
451 |
|
|
452 |
@param aFieldCount Specifies the number of fields in the text object.
|
|
453 |
@param aPictureCount Specifies the number of pictures in the text object
|
|
454 |
(rich text only).
|
|
455 |
@param aStyleCount Specifies the number of styles owned or referenced by
|
|
456 |
the text object (rich text only). */
|
|
457 |
{}
|
|
458 |
|
|
459 |
|
|
460 |
EXPORT_C TEtextComponentInfo::TEtextComponentInfo(TInt aFieldCount,TInt aPictureCount,TInt aStyleCount)
|
|
461 |
: iFieldCount(aFieldCount),iPictureCount(aPictureCount),iStyleCount(aStyleCount)
|
|
462 |
/** C++ constructor overloaded function. The object can be constructed either:
|
|
463 |
|
|
464 |
by default this initializes the field, picture and style counts to zero
|
|
465 |
|
|
466 |
with a field, picture and style count
|
|
467 |
|
|
468 |
@param aFieldCount Specifies the number of fields in the text object.
|
|
469 |
@param aPictureCount Specifies the number of pictures in the text object (rich
|
|
470 |
text only).
|
|
471 |
@param aStyleCount Specifies the number of styles owned or referenced by the
|
|
472 |
text object (rich text only). */
|
|
473 |
{}
|
|
474 |
|
|
475 |
|
|
476 |
//////////////////////////////////
|
|
477 |
// CPlainText
|
|
478 |
//////////////////////////////////
|
|
479 |
|
|
480 |
|
|
481 |
EXPORT_C void CPlainText::__DbgTestInvariant()const
|
|
482 |
// Provides class invariants. Explanations below:
|
|
483 |
//
|
|
484 |
{
|
|
485 |
#ifdef _DEBUG
|
|
486 |
// ASSERT: Storage handle is good.
|
|
487 |
__ASSERT_DEBUG(iByteStore!=NULL,User::Invariant());
|
|
488 |
// ASSERT: The text component must be non-negative in length
|
|
489 |
__ASSERT_DEBUG(DocumentLength()>=0,User::Invariant());
|
|
490 |
#endif
|
|
491 |
}
|
|
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
EXPORT_C CPlainText* CPlainText::NewL(TDocumentStorage aStorage,TInt aDefaultTextGranularity)
|
|
497 |
/** Allocates and constructs a plain text object overloaded function.
|
|
498 |
|
|
499 |
The text object's contents may be restored from a stream store. If the
|
|
500 |
text object supports fields, a field factory should be specified.
|
|
501 |
|
|
502 |
@param aStorage The type of in-memory buffer to use. Defaults to ESegmentedStorage.
|
|
503 |
@param aDefaultTextGranularity Specifies the granularity of the in-memory
|
|
504 |
buffer. Default is EDefaultTextGranularity bytes (=256).
|
|
505 |
@param aStore Stream store from which the object is restored.
|
|
506 |
@param aStreamId ID of the stream store.
|
|
507 |
@param aFieldFactory Pointer to a field factory. A field factory must be
|
|
508 |
provided if the text object supports the addition of fields.
|
|
509 |
@return Pointer to the new plain text object. */
|
|
510 |
{
|
|
511 |
CPlainText* self=new(ELeave) CPlainText();
|
|
512 |
CleanupStack::PushL(self);
|
|
513 |
self->ConstructL(aStorage,aDefaultTextGranularity);
|
|
514 |
CleanupStack::Pop();
|
|
515 |
return self;
|
|
516 |
}
|
|
517 |
|
|
518 |
|
|
519 |
EXPORT_C CPlainText* CPlainText::NewL(const CStreamStore& aStore,TStreamId aStreamId,MTextFieldFactory* aFieldFactory,TDocumentStorage aStorage)
|
|
520 |
/** Returns a handle to a new instance of this class, restored from the specified
|
|
521 |
read stream.*/
|
|
522 |
{
|
|
523 |
CPlainText* self=new(ELeave) CPlainText();
|
|
524 |
CleanupStack::PushL(self);
|
|
525 |
self->ConstructL(aStore,aStreamId,aFieldFactory,aStorage);
|
|
526 |
CleanupStack::Pop();
|
|
527 |
return self;
|
|
528 |
}
|
|
529 |
|
|
530 |
|
|
531 |
EXPORT_C CPlainText::CPlainText()
|
|
532 |
{
|
|
533 |
SetHasChanged(EFalse);
|
|
534 |
}
|
|
535 |
|
|
536 |
|
|
537 |
EXPORT_C void CPlainText::ConstructL(TDocumentStorage aStorage,TInt aDefaultTextGranularity)
|
|
538 |
/** Allocates storage of CBufFlat or CBufSeg, according
|
|
539 |
to the parameter aStorage.
|
|
540 |
Creates & initializes the field set.*/
|
|
541 |
{
|
|
542 |
DoConstructL(aStorage,aDefaultTextGranularity);
|
|
543 |
InsertEodL();
|
|
544 |
|
|
545 |
__TEST_INVARIANT;
|
|
546 |
}
|
|
547 |
|
|
548 |
|
|
549 |
EXPORT_C void CPlainText::ConstructL(const CStreamStore& aStore,TStreamId aStreamId,MTextFieldFactory* aFieldFactory,
|
|
550 |
TDocumentStorage aStorage)
|
|
551 |
/** Allocates storage of CBufFlat or CBufSeg, according
|
|
552 |
to the parameter aStorage, restoring contents from the specified read-stream aStream.*/
|
|
553 |
{
|
|
554 |
DoConstructL(aStorage,EDefaultTextGranularity,aFieldFactory);
|
|
555 |
RestoreL(aStore,aStreamId);
|
|
556 |
|
|
557 |
__TEST_INVARIANT;
|
|
558 |
}
|
|
559 |
|
|
560 |
|
|
561 |
EXPORT_C void CPlainText::DoConstructL(TDocumentStorage aStorage,TInt aDefaultTextGranularity,MTextFieldFactory* aFieldFactory)
|
|
562 |
/** Allocates storage of CBufFlat or CBufSeg, according to the parameter aStorage.
|
|
563 |
Creates & initializes the field set.*/
|
|
564 |
{
|
|
565 |
__ASSERT_DEBUG(iByteStore==NULL,Panic(EConstructCalledTwice));
|
|
566 |
|
|
567 |
iByteStore=(aStorage==ESegmentedStorage)
|
|
568 |
? (CBufBase*)CBufSeg::NewL(aDefaultTextGranularity*sizeof(TText))
|
|
569 |
: (CBufBase*)CBufFlat::NewL(aDefaultTextGranularity*sizeof(TText));
|
|
570 |
if (aFieldFactory)
|
|
571 |
SetFieldFactory(aFieldFactory);
|
|
572 |
}
|
|
573 |
|
|
574 |
|
|
575 |
|
|
576 |
EXPORT_C CPlainText::~CPlainText()
|
|
577 |
/** The destructor frees the object's text storage and field set, prior to its
|
|
578 |
destruction. */
|
|
579 |
{
|
|
580 |
KillFieldSet();
|
|
581 |
delete iByteStore;
|
|
582 |
}
|
|
583 |
|
|
584 |
|
|
585 |
void CPlainText::KillFieldSet()
|
|
586 |
/** Delete the field set if it is resident in memory.*/
|
|
587 |
{
|
|
588 |
if (FieldSetPresent())
|
|
589 |
delete iFieldSet.AsPtr();
|
|
590 |
iFieldSet=NULL;
|
|
591 |
}
|
|
592 |
|
|
593 |
|
|
594 |
//
|
|
595 |
// CPlainText - Persistence
|
|
596 |
|
|
597 |
|
|
598 |
EXPORT_C void CPlainText::StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap)const
|
|
599 |
/** Stores the plain text object's components to the stream store specified.
|
|
600 |
|
|
601 |
@param aStore Stream store to which the text object's components are written.
|
|
602 |
@param aMap A store map. This binds the address of each component to the stream
|
|
603 |
ID of aStore. This is needed to support the deferred loading of pictures in
|
|
604 |
rich text. */
|
|
605 |
{
|
|
606 |
// Store any field components, then store the field set out-of-line, if present.
|
|
607 |
if (FieldSetPresent())
|
|
608 |
{
|
|
609 |
TStreamId id=iFieldSet->StoreL(aStore);
|
|
610 |
aMap.BindL(iFieldSet,id);
|
|
611 |
}
|
|
612 |
}
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
EXPORT_C void CPlainText::RestoreComponentsL(const CStreamStore& aStore)
|
|
617 |
/** Restores the plain text object's field set from a stream store.
|
|
618 |
|
|
619 |
@param aStore The stream store from which the field set is restored. */
|
|
620 |
{
|
|
621 |
// Load the field set, and load any referenced pictures
|
|
622 |
TStreamId id=iFieldSet.AsId();
|
|
623 |
if (id!=KNullStreamId)
|
|
624 |
{
|
|
625 |
CreateFieldSetL(0);
|
|
626 |
iFieldSet->SetFieldFactory(iFieldFactory);
|
|
627 |
iFieldSet->RestoreL(aStore,id);
|
|
628 |
}
|
|
629 |
}
|
|
630 |
|
|
631 |
|
|
632 |
|
|
633 |
EXPORT_C void CPlainText::StoreFieldComponentsL(CStreamStore& aStore,CStoreMap& aMap)const
|
|
634 |
/** Stores the plain text object's field components to a stream store.
|
|
635 |
|
|
636 |
@param aStore Stream store to which the fields are written.
|
|
637 |
@param aMap A store map. This binds the address of each text component to the
|
|
638 |
stream ID of aStore. This is needed to support the deferred loading of pictures
|
|
639 |
in rich text. */
|
|
640 |
{
|
|
641 |
// 2' StoreComponents()
|
|
642 |
// Only has effect if a field set is present.
|
|
643 |
if (FieldSetPresent())
|
|
644 |
iFieldSet->StoreFieldsL(aStore,aMap);
|
|
645 |
}
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
EXPORT_C void CPlainText::RestoreFieldComponentsL(const CStreamStore& aStore)
|
|
650 |
/** Restores the plain text object's field set.
|
|
651 |
|
|
652 |
@param aStore The stream store from which the fields are restored. */
|
|
653 |
{
|
|
654 |
// 2' RestoreComponents()
|
|
655 |
// Only has effect if a field set is present - (has been Internalized())
|
|
656 |
if (FieldSetPresent())
|
|
657 |
iFieldSet->RestoreFieldsL(aStore);
|
|
658 |
}
|
|
659 |
|
|
660 |
|
|
661 |
|
|
662 |
EXPORT_C void CPlainText::ExternalizeL(RWriteStream& aStream)const
|
|
663 |
/** Externalises a plain text object to a write stream. The presence of this function
|
|
664 |
means that the standard templated operator<<() (defined in s32strm.h) is available
|
|
665 |
to externalise objects of this class.
|
|
666 |
|
|
667 |
@param aStream Stream to which the object should be externalised. */
|
|
668 |
{
|
|
669 |
// Store this object in the specified write-stream.
|
|
670 |
CEditableText::ExternalizeL(aStream);
|
|
671 |
DoExternalizeFieldDataL(aStream);
|
|
672 |
DoExternalizePlainTextL(aStream);
|
|
673 |
}
|
|
674 |
|
|
675 |
|
|
676 |
|
|
677 |
EXPORT_C void CPlainText::InternalizeL(RReadStream& aStream)
|
|
678 |
/** Internalises the text object's text content and field set from a read stream.
|
|
679 |
The presence of this function means that the standard templated operator>>()
|
|
680 |
(defined in s32strm.h) is available to internalise objects of this class.
|
|
681 |
InternalizeL() has construct rather than assignment semantics. You should
|
|
682 |
not use it for fully initialised objects.
|
|
683 |
|
|
684 |
@param aStream Stream from which the object should be internalised. */
|
|
685 |
{
|
|
686 |
// Restores plain text from the specified read-stream.
|
|
687 |
// Internalize has construction semantics, not assignment semantics.
|
|
688 |
CEditableText::InternalizeL(aStream);
|
|
689 |
DoInternalizeFieldDataL(aStream);
|
|
690 |
DoInternalizePlainTextL(aStream);
|
|
691 |
|
|
692 |
__TEST_INVARIANT;
|
|
693 |
}
|
|
694 |
|
|
695 |
|
|
696 |
|
|
697 |
EXPORT_C void CPlainText::ExternalizeFieldDataL(RWriteStream& aStream)const
|
|
698 |
/** Externalises the plain text object's field set.
|
|
699 |
|
|
700 |
@param aStream The stream to which the field set should be written. */
|
|
701 |
{
|
|
702 |
// Save just the field set
|
|
703 |
__TEST_INVARIANT;
|
|
704 |
|
|
705 |
TUint fieldCount=(TUint)FieldCount();
|
|
706 |
if(fieldCount<KFieldCountLimit)
|
|
707 |
aStream.WriteUint8L(fieldCount);
|
|
708 |
else
|
|
709 |
{
|
|
710 |
aStream.WriteUint8L(KFieldCountLimit);
|
|
711 |
aStream.WriteUint32L(fieldCount);
|
|
712 |
}
|
|
713 |
if (fieldCount>0)
|
|
714 |
aStream<< *iFieldSet;
|
|
715 |
}
|
|
716 |
|
|
717 |
|
|
718 |
|
|
719 |
EXPORT_C void CPlainText::InternalizeFieldDataL(RReadStream& aStream)
|
|
720 |
/** Internalizes the field set.
|
|
721 |
|
|
722 |
@param aStream The read stream from which the field set is read. */
|
|
723 |
{
|
|
724 |
// 2' InternalizeL()
|
|
725 |
// Restores field records from the specified read-stream.
|
|
726 |
// Internalize has construction semantics, not assignment semantics.
|
|
727 |
|
|
728 |
TUint fieldCount=aStream.ReadUint8L();
|
|
729 |
if (fieldCount==KFieldCountLimit)
|
|
730 |
fieldCount=aStream.ReadUint32L();
|
|
731 |
if (fieldCount>0)
|
|
732 |
{
|
|
733 |
if (!iFieldSet)
|
|
734 |
CreateFieldSetL(DocumentLength());
|
|
735 |
aStream>> *iFieldSet;
|
|
736 |
}
|
|
737 |
}
|
|
738 |
|
|
739 |
|
|
740 |
EXPORT_C void CPlainText::DoInternalizeFieldDataL(RReadStream& aStream)
|
|
741 |
/** Read from the stream until the field data is identified, and consume it.*/
|
|
742 |
{
|
|
743 |
TUid uid=UidFromStreamL(aStream);
|
|
744 |
while (uid!=KPlainTextFieldDataUid)
|
|
745 |
{
|
|
746 |
if (uid==KPlainTextCharacterDataUid)
|
|
747 |
User::Leave(KErrCorrupt); // There is no field Data !!!!!
|
|
748 |
CPlainText::ConsumeAdornmentL(aStream);
|
|
749 |
uid=UidFromStreamL(aStream);
|
|
750 |
}
|
|
751 |
if (FieldSetPresent())
|
|
752 |
iFieldFactory=iFieldSet->FieldFactory();
|
|
753 |
KillFieldSet();
|
|
754 |
aStream>> iFieldSet; // a swizzle
|
|
755 |
}
|
|
756 |
|
|
757 |
|
|
758 |
EXPORT_C void CPlainText::DoExternalizeFieldDataL(RWriteStream& aStream)const
|
|
759 |
/** Write to the stream, the T.V. representing the field set.*/
|
|
760 |
{
|
|
761 |
aStream<< KPlainTextFieldDataUid;
|
|
762 |
if (FieldSetPresent())
|
|
763 |
aStream<< iFieldSet;
|
|
764 |
else
|
|
765 |
aStream<< KNullStreamId;
|
|
766 |
}
|
|
767 |
|
|
768 |
|
|
769 |
EXPORT_C void CPlainText::DoExternalizePlainTextL(RWriteStream& aStream)const
|
|
770 |
/** Write to the stream, the T.V. representing the plain text.*/
|
|
771 |
{
|
|
772 |
aStream<< KPlainTextCharacterDataUid;
|
|
773 |
ExternalizePlainTextL(aStream);
|
|
774 |
}
|
|
775 |
|
|
776 |
|
|
777 |
|
|
778 |
EXPORT_C void CPlainText::ExternalizePlainTextL(RWriteStream& aStream)const
|
|
779 |
|
|
780 |
/** Externalises the plain text object's text content (preceded by a length count)
|
|
781 |
to a write stream.
|
|
782 |
|
|
783 |
@param aStream Stream to which the text content should be externalised. */
|
|
784 |
{
|
|
785 |
// Save just the bytestore
|
|
786 |
__TEST_INVARIANT;
|
|
787 |
::ExternalizeTextL(aStream,*iByteStore,0,iByteStore->Size() / sizeof(TText),TRUE);
|
|
788 |
}
|
|
789 |
|
|
790 |
EXPORT_C void CPlainText::DoInternalizePlainTextL(RReadStream& aStream)
|
|
791 |
/** Read from the stream until the character data is found, and consume it.*/
|
|
792 |
{
|
|
793 |
TUid uid=UidFromStreamL(aStream);
|
|
794 |
while (uid!=KPlainTextCharacterDataUid)
|
|
795 |
{
|
|
796 |
CPlainText::ConsumeAdornmentL(aStream);
|
|
797 |
uid=UidFromStreamL(aStream);
|
|
798 |
}
|
|
799 |
CPlainText::InternalizePlainTextL(aStream);
|
|
800 |
}
|
|
801 |
|
|
802 |
EXPORT_C void CPlainText::InternalizePlainTextL(RReadStream& aStream)
|
|
803 |
/** Internalises an empty text object's text content from a read stream
|
|
804 |
overloaded function.
|
|
805 |
|
|
806 |
This function has construct rather than assignment semantics. You
|
|
807 |
should not use it for fully initialised objects.NoteThe overload which
|
|
808 |
takes a length argument is not intended for general use and its use is
|
|
809 |
deprecated.
|
|
810 |
|
|
811 |
@param aStream Stream from which the object should be internalised.
|
|
812 |
@param aLength Indicates the number of characters which should be
|
|
813 |
read, after expansion from their compressed format. */
|
|
814 |
{
|
|
815 |
// Restores plain text content from the specified read-stream.
|
|
816 |
// Internalize has construction semantics, not assignment semantics.
|
|
817 |
::InternalizeTextL(aStream,*iByteStore);
|
|
818 |
SetHasChanged(EFalse);
|
|
819 |
|
|
820 |
__TEST_INVARIANT;
|
|
821 |
}
|
|
822 |
|
|
823 |
|
|
824 |
EXPORT_C void CPlainText::ExternalizePlainTextNoLengthCountL(RWriteStream& aStream)const
|
|
825 |
/** Externalises the plain text object's text content to a write stream.
|
|
826 |
|
|
827 |
This function differs from ExternalizePlainTextL() in that
|
|
828 |
it does not precede the text content with a length count.
|
|
829 |
This function is not intended for general use and is deprecated.
|
|
830 |
@see void CPlainText::ExternalizePlainTextL(RWriteStream& aStream)const
|
|
831 |
@deprecated */
|
|
832 |
{
|
|
833 |
::ExternalizeTextL(aStream,*iByteStore,0,iByteStore->Size() / sizeof(TText),FALSE);
|
|
834 |
}
|
|
835 |
|
|
836 |
|
|
837 |
EXPORT_C void CPlainText::InternalizePlainTextL(RReadStream& aStream,TInt aLength)
|
|
838 |
/** Internalises an empty text object's text content from a read stream's
|
|
839 |
overloaded function.
|
|
840 |
|
|
841 |
This function has construct rather than assignment semantics. You should not
|
|
842 |
use it for fully initialised objects.
|
|
843 |
|
|
844 |
Note
|
|
845 |
|
|
846 |
The overload which takes a length argument is not intended for general use
|
|
847 |
and its use is deprecated.
|
|
848 |
|
|
849 |
@param aStream Stream from which the object should be internalised.
|
|
850 |
@param aLength Indicates the number of characters which should be read, after
|
|
851 |
expansion from their compressed format.
|
|
852 |
@deprecated */
|
|
853 |
{
|
|
854 |
::InternalizeTextL(aStream,*iByteStore,aLength);
|
|
855 |
}
|
|
856 |
|
|
857 |
|
|
858 |
// Copy the specified section of plain text to the specified store.
|
|
859 |
|
|
860 |
|
|
861 |
EXPORT_C void CPlainText::CopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const
|
|
862 |
/** Copies plain text including fields, if present, to the clipboard.
|
|
863 |
|
|
864 |
A panic occurs in any of the following circumstances:
|
|
865 |
|
|
866 |
aPos is invalid
|
|
867 |
|
|
868 |
aLength is invalid (zero or less)
|
|
869 |
|
|
870 |
the sum of aPos and aLength is greater than or equal to the number of characters
|
|
871 |
in the document
|
|
872 |
|
|
873 |
@param aStore Stream store to which the text is written.
|
|
874 |
@param aDictionary The stream dictionary.
|
|
875 |
@param aPos The document position from which to begin copying.
|
|
876 |
@param aLength The number of characters to copy. */
|
|
877 |
{
|
|
878 |
if (aLength > 0)
|
|
879 |
DoCopyToStoreL(aStore,aDictionary,aPos,aLength);
|
|
880 |
}
|
|
881 |
|
|
882 |
|
|
883 |
TStreamId CPlainText::DoCopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const
|
|
884 |
{
|
|
885 |
__TEST_INVARIANT;
|
|
886 |
TInt documentLength = DocumentLength();
|
|
887 |
__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
|
|
888 |
__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
|
|
889 |
__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
|
|
890 |
|
|
891 |
if (aLength == 0)
|
|
892 |
return KNullStreamId;
|
|
893 |
|
|
894 |
CStoreMap* map=CStoreMap::NewLC(aStore);
|
|
895 |
CopyComponentsL(aStore,*map,aPos,aLength);
|
|
896 |
|
|
897 |
// create custom externalizer over the map
|
|
898 |
TFieldMapExternalizer fMap(*map);
|
|
899 |
RStoreWriteStream stream(fMap);
|
|
900 |
TStreamId id=stream.CreateLC(aStore);
|
|
901 |
CopyToStreamL(stream,aPos,aLength);
|
|
902 |
stream.CommitL();
|
|
903 |
|
|
904 |
aDictionary.AssignL(KClipboardUidTypePlainText,id);
|
|
905 |
map->Reset();
|
|
906 |
CleanupStack::PopAndDestroy(2);
|
|
907 |
|
|
908 |
__TEST_INVARIANT;
|
|
909 |
return id;
|
|
910 |
}
|
|
911 |
|
|
912 |
|
|
913 |
void CPlainText::CopyComponentsL(CStreamStore& aStore,CStoreMap& aMap,TInt aPos,TInt aLength)const
|
|
914 |
// Copy/Paste 2' StoreComponentsL() - only if a field set is present.
|
|
915 |
//
|
|
916 |
{
|
|
917 |
if (FieldSetPresent())
|
|
918 |
iFieldSet->CopyComponentsL(aStore,aMap,aPos,aLength);
|
|
919 |
}
|
|
920 |
|
|
921 |
|
|
922 |
// Write the plain text to the stream.
|
|
923 |
void CPlainText::CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength)const
|
|
924 |
{
|
|
925 |
__TEST_INVARIANT;
|
|
926 |
TInt documentLength = DocumentLength();
|
|
927 |
__ASSERT_ALWAYS(aPos >= 0 && aPos <= documentLength,Panic(ECharPosBeyondDocument));
|
|
928 |
__ASSERT_ALWAYS(aLength >= 0,Panic(ECopyToStreamNegativeLength));
|
|
929 |
__ASSERT_ALWAYS(aPos + aLength <= documentLength,Panic(ECharPosBeyondDocument));
|
|
930 |
|
|
931 |
aStream.WriteInt32L(aLength);
|
|
932 |
::ExternalizeTextL(aStream,*iByteStore,aPos,aLength,FALSE);
|
|
933 |
|
|
934 |
// Write the field set if any.
|
|
935 |
TBool fieldSetPresent = FieldSetPresent();
|
|
936 |
aStream.WriteUint8L(fieldSetPresent != EFalse);
|
|
937 |
if (fieldSetPresent)
|
|
938 |
iFieldSet->CopyToStreamL(aStream,aPos,aLength);
|
|
939 |
}
|
|
940 |
|
|
941 |
|
|
942 |
|
|
943 |
|
|
944 |
EXPORT_C TInt CPlainText::PasteFromStoreL(const CStreamStore& aStore,const CStreamDictionary& aDictionary,TInt aPos)
|
|
945 |
/** Pastes plain text and fields, if present, from the clipboard into the current
|
|
946 |
text object at the specified document position. The entire contents of the
|
|
947 |
store are pasted.
|
|
948 |
|
|
949 |
@param aStore The steam store from which to paste the text.
|
|
950 |
@param aDictionary The stream dictionary.
|
|
951 |
@param aPos Document position at which to paste. Must be valid or the function
|
|
952 |
raises a panic.
|
|
953 |
@return The number of characters pasted. */
|
|
954 |
{
|
|
955 |
// Paste the lesser of aMaxPasteLength and the entire clipboard contents.
|
|
956 |
// Return the number of characters pasted.
|
|
957 |
TStreamId id=aDictionary.At(KClipboardUidTypePlainText);
|
|
958 |
return DoPasteFromStoreL(aStore,id,aPos);
|
|
959 |
}
|
|
960 |
|
|
961 |
|
|
962 |
TInt CPlainText::DoPasteFromStoreL(const CStreamStore& aStore,TStreamId aStreamId,TInt aPos)
|
|
963 |
{
|
|
964 |
__ASSERT_ALWAYS(aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
965 |
|
|
966 |
TInt charsPasted=0;
|
|
967 |
if (aStreamId!=KNullStreamId)
|
|
968 |
{// There is a recognised type in the clipboard.
|
|
969 |
RStoreReadStream stream;
|
|
970 |
stream.OpenLC(aStore,aStreamId);
|
|
971 |
charsPasted=PasteFromStreamL(stream,aPos);
|
|
972 |
CleanupStack::PopAndDestroy();
|
|
973 |
//
|
|
974 |
PasteComponentsL(aStore,aPos);
|
|
975 |
SetHasChanged(ETrue);
|
|
976 |
}
|
|
977 |
|
|
978 |
__TEST_INVARIANT;
|
|
979 |
return charsPasted;
|
|
980 |
}
|
|
981 |
|
|
982 |
|
|
983 |
void CPlainText::PasteComponentsL(const CStreamStore& aStore,TInt aPos)
|
|
984 |
// Copy/Paste 2' RestoreComponentsL() - only if a field set is present.
|
|
985 |
//
|
|
986 |
{
|
|
987 |
if (FieldSetPresent())
|
|
988 |
iFieldSet->PasteComponentsL(aStore,aPos);
|
|
989 |
}
|
|
990 |
|
|
991 |
|
|
992 |
// Paste everything in the stream.
|
|
993 |
TInt CPlainText::PasteFromStreamL(RReadStream& aStream,TInt aPos)
|
|
994 |
{
|
|
995 |
TInt chars_read = 0;
|
|
996 |
TInt error = KErrNone;
|
|
997 |
|
|
998 |
TRAP(error, chars_read=CPlainText::DoPasteFromStreamL(aStream, aPos));
|
|
999 |
|
|
1000 |
UpdatePageTable(aPos,chars_read);
|
|
1001 |
|
|
1002 |
/*
|
|
1003 |
If there was an exception delete any inserted text and propagate the exception.
|
|
1004 |
Not deleting the text would cause the size of the text to be inconsistent with the size
|
|
1005 |
implied elsewhere, such as in the formatting information stored in CRichText objects.
|
|
1006 |
*/
|
|
1007 |
if (error != KErrNone)
|
|
1008 |
{
|
|
1009 |
DoPtDelete(aPos,chars_read);
|
|
1010 |
User::Leave(error);
|
|
1011 |
}
|
|
1012 |
|
|
1013 |
__TEST_INVARIANT;
|
|
1014 |
return chars_read;
|
|
1015 |
}
|
|
1016 |
|
|
1017 |
|
|
1018 |
TInt CPlainText::DoPasteFromStreamL(RReadStream& aStream, TInt aPos)
|
|
1019 |
{
|
|
1020 |
TInt chars_read = 0;
|
|
1021 |
|
|
1022 |
CBufSeg* buffer = CBufSeg::NewL(512);
|
|
1023 |
CleanupStack::PushL(buffer);
|
|
1024 |
TInt length = aStream.ReadInt32L();
|
|
1025 |
::InternalizeTextL(aStream,*buffer,length);
|
|
1026 |
|
|
1027 |
/*
|
|
1028 |
Insert the text bit by bit so that memory consumed by the CPlainText object is freed from the buffer;
|
|
1029 |
this is important if pasting huge amounts of text.
|
|
1030 |
*/
|
|
1031 |
while (buffer->Size() > 0)
|
|
1032 |
{
|
|
1033 |
TPtr8 p8 = buffer->Ptr(0);
|
|
1034 |
TInt bytes = p8.Length();
|
|
1035 |
TInt chars = bytes / sizeof(TText);
|
|
1036 |
TPtrC p((TText*)p8.Ptr(),chars); // platform dependency in the Unicode build; relies on little-endianness
|
|
1037 |
PtInsertL(aPos + chars_read,p);
|
|
1038 |
buffer->Delete(0,bytes);
|
|
1039 |
chars_read += chars;
|
|
1040 |
}
|
|
1041 |
|
|
1042 |
CleanupStack::PopAndDestroy(); // buffer
|
|
1043 |
buffer = NULL;
|
|
1044 |
|
|
1045 |
// If there's a field set, internalize it.
|
|
1046 |
if (aStream.ReadUint8L() != 0) // next byte is non-zero if there's a field set
|
|
1047 |
{
|
|
1048 |
if (!FieldSetPresent())
|
|
1049 |
CreateFieldSetL(DocumentLength());
|
|
1050 |
iFieldSet->PasteFromStreamL(aStream,aPos,chars_read);
|
|
1051 |
}
|
|
1052 |
|
|
1053 |
return chars_read;
|
|
1054 |
}
|
|
1055 |
|
|
1056 |
|
|
1057 |
void CPlainText::InsertEodL()
|
|
1058 |
/** Inserts the end-of-document character upon document construction.*/
|
|
1059 |
{
|
|
1060 |
// ASSERT: The plain text component is empty.
|
|
1061 |
__ASSERT_DEBUG(DocumentLength()==-1,Panic(ECorruptTextStore));
|
|
1062 |
TBuf<1> content;
|
|
1063 |
content.Append(EParagraphDelimiter);
|
|
1064 |
TPtrC eod(content);
|
|
1065 |
DoPtInsertL(0,eod);
|
|
1066 |
|
|
1067 |
__TEST_INVARIANT;
|
|
1068 |
}
|
|
1069 |
|
|
1070 |
|
|
1071 |
EXPORT_C void CPlainText::Reset()
|
|
1072 |
/** Deletes all text content, formatting and fields from the document, leaving
|
|
1073 |
the single paragraph delimiter which terminates the text object. */
|
|
1074 |
{
|
|
1075 |
// Resets document contents to a single end-of-document character, with no other content.
|
|
1076 |
// (No reset occurs if the component is already in the reset state. Avoids an assertion
|
|
1077 |
// failure in the delete method, where length to delete !> 0).
|
|
1078 |
__TEST_INVARIANT;
|
|
1079 |
|
|
1080 |
TInt content=DocumentLength();
|
|
1081 |
if (content>0)
|
|
1082 |
DoPtDelete(0,content);
|
|
1083 |
if (FieldSetPresent())
|
|
1084 |
KillFieldSet();
|
|
1085 |
SetHasChanged(ETrue);
|
|
1086 |
|
|
1087 |
__TEST_INVARIANT;
|
|
1088 |
}
|
|
1089 |
|
|
1090 |
|
|
1091 |
|
|
1092 |
|
|
1093 |
EXPORT_C TInt CPlainText::DocumentLength()const
|
|
1094 |
/** Gets the the number of characters in the text object.
|
|
1095 |
|
|
1096 |
Note: the count includes all non-printing characters but excludes the end
|
|
1097 |
of text paragraph delimiter, so that the smallest possible return value is
|
|
1098 |
zero.
|
|
1099 |
|
|
1100 |
@return The number of characters in the text object. */
|
|
1101 |
{return ((iByteStore->Size()/sizeof(TText))-1);}
|
|
1102 |
|
|
1103 |
|
|
1104 |
EXPORT_C void CPlainText::InsertL(TInt aInsertPos,const TChar& aChar)
|
|
1105 |
/** Inserts either a single character or a descriptor into the text object
|
|
1106 |
at a specified document position.
|
|
1107 |
|
|
1108 |
Updates the page table.
|
|
1109 |
|
|
1110 |
@param aPos The document position at which to insert the character/descriptor.
|
|
1111 |
Must be valid, or a panic occurs.
|
|
1112 |
@param aChar The character to insert.
|
|
1113 |
@param aBuf The descriptor to insert. */
|
|
1114 |
{
|
|
1115 |
__TEST_INVARIANT;
|
|
1116 |
__ASSERT_ALWAYS(aInsertPos>=0 && aInsertPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1117 |
|
|
1118 |
TInt contentLength = 1;
|
|
1119 |
if (aChar < 0x10000)
|
|
1120 |
{
|
|
1121 |
TBuf<1> content;
|
|
1122 |
content.Append(aChar);
|
|
1123 |
DoPtInsertL(aInsertPos,content);
|
|
1124 |
}
|
|
1125 |
else
|
|
1126 |
{
|
|
1127 |
TText16 high = TChar::GetHighSurrogate(aChar);
|
|
1128 |
TText16 low = TChar::GetLowSurrogate(aChar);
|
|
1129 |
RDebug::Print(_L("CPlainText::InsertL(%d), %X expand to %X %X."), aInsertPos, aChar, high, low);
|
|
1130 |
|
|
1131 |
TBuf<2> content;
|
|
1132 |
contentLength = 2;
|
|
1133 |
content.Append(high);
|
|
1134 |
content.Append(low);
|
|
1135 |
DoPtInsertL(aInsertPos,content);
|
|
1136 |
}
|
|
1137 |
if (FieldSetPresent())
|
|
1138 |
iFieldSet->NotifyInsertion(aInsertPos,contentLength);
|
|
1139 |
|
|
1140 |
SetHasChanged(ETrue);
|
|
1141 |
|
|
1142 |
__TEST_INVARIANT;
|
|
1143 |
}
|
|
1144 |
|
|
1145 |
|
|
1146 |
EXPORT_C void CPlainText::InsertL(TInt aPos,const TDesC& aBuf)
|
|
1147 |
/** Inserts the contents of aBuf into the document at position aPos.*/
|
|
1148 |
{
|
|
1149 |
PtInsertL(aPos,aBuf);
|
|
1150 |
SetHasChanged(ETrue);
|
|
1151 |
}
|
|
1152 |
|
|
1153 |
|
|
1154 |
EXPORT_C void CPlainText::PtInsertL(TInt aPos,const TDesC& aBuf)
|
|
1155 |
/** Inserts the contents a aBuf into the document at position aInsertPos.
|
|
1156 |
Maintain field set.*/
|
|
1157 |
{
|
|
1158 |
__TEST_INVARIANT;
|
|
1159 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1160 |
|
|
1161 |
DoPtInsertL(aPos,aBuf);
|
|
1162 |
if (FieldSetPresent())
|
|
1163 |
iFieldSet->NotifyInsertion(aPos,aBuf.Length());
|
|
1164 |
|
|
1165 |
__TEST_INVARIANT;
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
|
|
1169 |
EXPORT_C void CPlainText::DoPtInsertL(TInt aPos,const TDesC& aBuf)
|
|
1170 |
/** Inserts the contents a aBuf into the document at position aInsertPos.
|
|
1171 |
Maintain field set.*/
|
|
1172 |
{
|
|
1173 |
TPtrC8 buf((TUint8*)aBuf.Ptr(),aBuf.Size());
|
|
1174 |
iByteStore->InsertL(aPos*sizeof(TText),buf);
|
|
1175 |
UpdatePageTable(aPos,aBuf.Length());
|
|
1176 |
}
|
|
1177 |
|
|
1178 |
|
|
1179 |
void CPlainText::InsertL(TInt aPos,const CPlainText* aText)
|
|
1180 |
/** Insert the specified plain text object at the specified character position.
|
|
1181 |
(Called by CRichText::Insert()*/
|
|
1182 |
{
|
|
1183 |
TInt lengthRemaining=aText->DocumentLength();
|
|
1184 |
TInt readPos=0;
|
|
1185 |
FOREVER
|
|
1186 |
{
|
|
1187 |
TPtrC view=aText->Read(readPos);
|
|
1188 |
TInt consumed=view.Length();
|
|
1189 |
if (consumed>lengthRemaining)
|
|
1190 |
consumed=lengthRemaining;
|
|
1191 |
InsertL(aPos,view);
|
|
1192 |
lengthRemaining-=consumed;
|
|
1193 |
if (lengthRemaining==0)
|
|
1194 |
return;
|
|
1195 |
aPos+=consumed;
|
|
1196 |
readPos+=consumed;
|
|
1197 |
}
|
|
1198 |
}
|
|
1199 |
|
|
1200 |
|
|
1201 |
EXPORT_C TBool CPlainText::DeleteL(TInt aPos,TInt aLength)
|
|
1202 |
/** Deletes one or more characters beginning at, and including, the character at
|
|
1203 |
a specified document position. Updates the page table. Any fields wholly contained
|
|
1204 |
in the range of characters to delete are removed from the field set.
|
|
1205 |
|
|
1206 |
@param aPos The document position from which to begin deleting. Must be valid
|
|
1207 |
or a panic occurs.
|
|
1208 |
@param aLength The number of characters to delete. Must be positive or a panic
|
|
1209 |
occurs. The sum of aPos and aLength must be less than the document length,
|
|
1210 |
or a panic occurs.
|
|
1211 |
@return Indicates whether two paragraphs have been merged together as a result
|
|
1212 |
of the delete, indicating that the resulting paragraph must be reformatted.
|
|
1213 |
Has no meaning for plain text, so always EFalse. */
|
|
1214 |
{
|
|
1215 |
return Delete(aPos,aLength);
|
|
1216 |
}
|
|
1217 |
|
|
1218 |
|
|
1219 |
// A non-virtual non-leaving delete function for use inside ETEXT.
|
|
1220 |
TBool CPlainText::Delete(TInt aPos,TInt aLength)
|
|
1221 |
{
|
|
1222 |
__TEST_INVARIANT;
|
|
1223 |
|
|
1224 |
TBool ret = DoPtDelete(aPos,aLength);
|
|
1225 |
if (FieldSetPresent())
|
|
1226 |
iFieldSet->NotifyDeletion(aPos,aLength);
|
|
1227 |
SetHasChanged(ETrue);
|
|
1228 |
|
|
1229 |
__TEST_INVARIANT;
|
|
1230 |
return ret;
|
|
1231 |
}
|
|
1232 |
|
|
1233 |
|
|
1234 |
EXPORT_C TBool CPlainText::DoPtDelete(TInt aPos,TInt aLength)
|
|
1235 |
/** Deletes aLength number of characters from the document,
|
|
1236 |
commencing at, and including, position aPos.
|
|
1237 |
The return value indicates if 2 paragraphs have been merged together
|
|
1238 |
as a result of the delete, indicating that the resulting paragraph
|
|
1239 |
must be reformatted.
|
|
1240 |
In global text, this clearly has no reasonable meaning, so always returns
|
|
1241 |
EFalse, so no reformatting occurs.*/
|
|
1242 |
{
|
|
1243 |
TInt documentLength=DocumentLength()+1;
|
|
1244 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
|
|
1245 |
__ASSERT_ALWAYS(aLength>=0,Panic(EDeleteNegativeLength));
|
|
1246 |
__ASSERT_ALWAYS(aPos+aLength<=documentLength,Panic(ECharPosBeyondDocument));
|
|
1247 |
|
|
1248 |
iByteStore->Delete(aPos*sizeof(TText),aLength*sizeof(TText));
|
|
1249 |
UpdatePageTable(aPos,-aLength);
|
|
1250 |
|
|
1251 |
return EFalse;
|
|
1252 |
}
|
|
1253 |
|
|
1254 |
|
|
1255 |
|
|
1256 |
EXPORT_C TInt CPlainText::ImportTextFileL(TInt aPos,const TDes& aFileName,TTextOrganisation aTextOrganisation)
|
|
1257 |
/** Imports a plain text file into this text object.
|
|
1258 |
|
|
1259 |
Translates non-printing characters in the source text file into Symbian OS
|
|
1260 |
special characters, for instance tabs are converted into
|
|
1261 |
CEditableText::ETabCharacters, and form feeds into CEditableText::EPageBreaks.
|
|
1262 |
Line feeds in the source text file are translated according to the
|
|
1263 |
aTextOrganisation argument.
|
|
1264 |
|
|
1265 |
The function leaves if there is any problem in opening the file.
|
|
1266 |
|
|
1267 |
@param aPos Document position at which to insert the text. Must be a valid
|
|
1268 |
position, or a panic occurs.
|
|
1269 |
@param aFileName The name of the text file to import.
|
|
1270 |
@param aTextOrganisation If EOrganiseByLine, a single line feed or a line feed
|
|
1271 |
and carriage return is converted into a space character. A line feed which
|
|
1272 |
is followed by another line feed is converted into a paragraph delimiter.
|
|
1273 |
If EOrganiseByParagraph, all line feeds are converted into paragraph delimiters.
|
|
1274 |
|
|
1275 |
@return The number of characters imported. */
|
|
1276 |
{
|
|
1277 |
TInt chars_inserted = 0;
|
|
1278 |
RFs file_session;
|
|
1279 |
TInt error = file_session.Connect();
|
|
1280 |
if (error == KErrNone)
|
|
1281 |
{
|
|
1282 |
RFile file;
|
|
1283 |
error = file.Open(file_session,aFileName,EFileStream | EFileRead | EFileShareReadersOnly);
|
|
1284 |
if (error == KErrNone)
|
|
1285 |
{
|
|
1286 |
RFileReadStream input_stream(file);
|
|
1287 |
TRAP(error,ImportTextL(aPos,input_stream,aTextOrganisation,KMaxTInt,KMaxTInt,&chars_inserted));
|
|
1288 |
input_stream.Close();
|
|
1289 |
}
|
|
1290 |
file.Close();
|
|
1291 |
file_session.Close();
|
|
1292 |
}
|
|
1293 |
User::LeaveIfError(error);
|
|
1294 |
return chars_inserted;
|
|
1295 |
}
|
|
1296 |
|
|
1297 |
|
|
1298 |
|
|
1299 |
EXPORT_C void CPlainText::ExportAsTextL(const TDes& aFileName,TTextOrganisation aTextOrganisation,TInt aLineWrap)const
|
|
1300 |
/** Writes the contents of the plain text object to a text file.
|
|
1301 |
|
|
1302 |
The filename is given by aFileName. Any existing file with that name is
|
|
1303 |
replaced. A wrap width can be specified. This is only used when exporting
|
|
1304 |
by line (aTextOrganisation is EOrganiseByLine).
|
|
1305 |
|
|
1306 |
The function leaves if there is any problem in creating or replacing the file.
|
|
1307 |
|
|
1308 |
@param aFileName The name of the file to export the text to. If a file with
|
|
1309 |
this name already exists, it is replaced. Otherwise, a new file is created.
|
|
1310 |
@param aTextOrganisation Defines how to translate line delimiters. If
|
|
1311 |
EOrganiseByLine, lines wrap at the wrap width, as specified in aMaxLineLength.
|
|
1312 |
If EOrganiseByParagraph, lines do not wrap and paragraph delimiters are
|
|
1313 |
converted into CR/LF pairs.
|
|
1314 |
@param aMaxLineLength The maximum number of characters in each line, (only
|
|
1315 |
relevant if the text organisation is EOrganiseByLine). */
|
|
1316 |
{
|
|
1317 |
__ASSERT_DEBUG(aTextOrganisation == EOrganiseByParagraph || aLineWrap > 0,Panic(EExportLineWrapInvalid));
|
|
1318 |
RFs file_session;
|
|
1319 |
TInt error = file_session.Connect();
|
|
1320 |
if (error == KErrNone)
|
|
1321 |
{
|
|
1322 |
RFile file;
|
|
1323 |
error = file.Replace(file_session,aFileName,EFileStream | EFileWrite | EFileShareExclusive);
|
|
1324 |
if (error == KErrNone)
|
|
1325 |
{
|
|
1326 |
RFileWriteStream output_stream(file);
|
|
1327 |
TRAP(error,output_stream.WriteUint16L(EByteOrderMark));
|
|
1328 |
if (error == KErrNone)
|
|
1329 |
TRAP(error,ExportTextL(0,output_stream,aTextOrganisation,KMaxTInt,DocumentLength(),aLineWrap));
|
|
1330 |
output_stream.Close();
|
|
1331 |
}
|
|
1332 |
file.Close();
|
|
1333 |
file_session.Close();
|
|
1334 |
}
|
|
1335 |
User::LeaveIfError(error);
|
|
1336 |
}
|
|
1337 |
|
|
1338 |
|
|
1339 |
|
|
1340 |
EXPORT_C void CPlainText::ImportTextL(TInt aPos,RReadStream& aInput,TTextOrganisation aTextOrganisation,
|
|
1341 |
TInt aMaxOutputChars,TInt aMaxInputChars,
|
|
1342 |
TInt* aOutputChars,TInt* aInputChars)
|
|
1343 |
/** Imports plain text from a stream into this text object.
|
|
1344 |
|
|
1345 |
Translates line feeds in the source text according to the
|
|
1346 |
aTextOrganisation argument.
|
|
1347 |
|
|
1348 |
@param aPos Document position at which to insert the text. Must be a valid
|
|
1349 |
position, or a panic occurs.
|
|
1350 |
@param aInput Stream from which to read the text.
|
|
1351 |
@param aTextOrganisation If EOrganiseByLine, a single line feed
|
|
1352 |
or a line feed and carriage return is converted into a space character. A
|
|
1353 |
line feed which is followed by another line feed is converted into a paragraph
|
|
1354 |
delimiter. If EOrganiseByParagraph, all line feeds are converted
|
|
1355 |
into paragraph delimiters.
|
|
1356 |
@param aMaxOutputChars The maximum number of characters to write to the text
|
|
1357 |
object.
|
|
1358 |
@param aMaxInputChars The maximum number of characters to read from the stream.
|
|
1359 |
@param aOutputChars On return, the number of characters written to the text
|
|
1360 |
object.
|
|
1361 |
@param aInputChars On return, the number of characters read from the stream. */
|
|
1362 |
{
|
|
1363 |
TImportExportParam param;
|
|
1364 |
param.iOrganisation = aTextOrganisation;
|
|
1365 |
param.iMaxOutputChars = aMaxOutputChars;
|
|
1366 |
param.iMaxInputChars = aMaxInputChars;
|
|
1367 |
TImportExportResult result;
|
|
1368 |
ImportTextL(aPos,aInput,param,result);
|
|
1369 |
if (aOutputChars)
|
|
1370 |
*aOutputChars = result.iOutputChars;
|
|
1371 |
if (aInputChars)
|
|
1372 |
*aInputChars = result.iInputChars;
|
|
1373 |
}
|
|
1374 |
|
|
1375 |
|
|
1376 |
EXPORT_C void CPlainText::ExportTextL(TInt aPos,RWriteStream& aOutput,TTextOrganisation aTextOrganisation,
|
|
1377 |
TInt aMaxOutputChars,TInt aMaxInputChars,TInt aMaxLineLength,
|
|
1378 |
TInt* aOutputChars,TInt* aInputChars) const
|
|
1379 |
/** Writes plain text to a stream, optionally converting it from Unicode
|
|
1380 |
into a foreign encoding.
|
|
1381 |
|
|
1382 |
@since 6.1
|
|
1383 |
@param aPos A document position in the source plain text object from which
|
|
1384 |
to start reading the text to export.
|
|
1385 |
@param aOutput On return, the write stream to which the text is written.
|
|
1386 |
@param aParam Export parameters, including an optional foreign encoding to
|
|
1387 |
convert the Unicode text into, a file server connection, (this is needed for
|
|
1388 |
the character conversion - if not specified, one will be created), a line
|
|
1389 |
wrap width, and the maximum number of characters to export.
|
|
1390 |
@param aResult On return, contains the number of characters read and written. */
|
|
1391 |
{
|
|
1392 |
TImportExportParam param;
|
|
1393 |
param.iOrganisation = aTextOrganisation;
|
|
1394 |
param.iMaxOutputChars = aMaxOutputChars;
|
|
1395 |
param.iMaxInputChars = aMaxInputChars;
|
|
1396 |
param.iMaxLineLength = aMaxLineLength;
|
|
1397 |
TImportExportResult result;
|
|
1398 |
ExportTextL(aPos,aOutput,param,result);
|
|
1399 |
if (aOutputChars)
|
|
1400 |
*aOutputChars = result.iOutputChars;
|
|
1401 |
if (aInputChars)
|
|
1402 |
*aInputChars = result.iInputChars;
|
|
1403 |
}
|
|
1404 |
|
|
1405 |
EXPORT_C void CPlainText::ImportTextL(TInt aPos,RReadStream& aInput,
|
|
1406 |
const TImportExportParam& aParam,TImportExportResult& aResult)
|
|
1407 |
/** Imports plain text from a stream into this text object, optionally
|
|
1408 |
converting it from a foreign encoding into Unicode.
|
|
1409 |
|
|
1410 |
@param aPos Document position at which to insert the text. Must be a valid
|
|
1411 |
position, or a panic occurs.
|
|
1412 |
@param aInput Stream from which to read the text.
|
|
1413 |
@param aParam Import parameters, including the foreign encoding to convert
|
|
1414 |
from, whether to guess the foreign encoding and the maximum number of characters
|
|
1415 |
to import.
|
|
1416 |
@param aResult On return, contains the number of characters read and written
|
|
1417 |
and the foreign encoding used by the imported text.
|
|
1418 |
@see CPlainText::TImportExportParam
|
|
1419 |
@see CPlainText::TImportExportResult */
|
|
1420 |
{
|
|
1421 |
CBufSeg* buffer = CBufSeg::NewL(512);
|
|
1422 |
CleanupStack::PushL(buffer);
|
|
1423 |
RBufWriteStream output(*buffer,0);
|
|
1424 |
TImportExportParam param = aParam;
|
|
1425 |
param.iOutputInternal = TRUE; // force output to internal format
|
|
1426 |
TPlainTextReader::TranslateL(param,aResult,output,aInput);
|
|
1427 |
|
|
1428 |
TInt chars_inserted = 0;
|
|
1429 |
while (buffer->Size() > 0)
|
|
1430 |
{
|
|
1431 |
TPtr8 p8 = buffer->Ptr(0);
|
|
1432 |
TInt bytes = p8.Length();
|
|
1433 |
TInt chars = bytes / sizeof(TText);
|
|
1434 |
TPtrC p((TText*)p8.Ptr(),chars);
|
|
1435 |
/*
|
|
1436 |
Insert text using the virtual function InsertL to allow derived classes
|
|
1437 |
like CRichText to update their attributes.
|
|
1438 |
*/
|
|
1439 |
InsertL(aPos + chars_inserted,p);
|
|
1440 |
buffer->Delete(0,bytes);
|
|
1441 |
chars_inserted += chars;
|
|
1442 |
}
|
|
1443 |
|
|
1444 |
CleanupStack::PopAndDestroy(); // buffer;
|
|
1445 |
}
|
|
1446 |
|
|
1447 |
EXPORT_C void CPlainText::ExportTextL(TInt aPos,RWriteStream& aOutput,
|
|
1448 |
const TImportExportParam& aParam,TImportExportResult& aResult) const
|
|
1449 |
/** Writes plain text to a stream, optionally converting it from Unicode into a
|
|
1450 |
foreign encoding.
|
|
1451 |
|
|
1452 |
@param aPos A document position in the source plain text object from which
|
|
1453 |
to start reading the text to export.
|
|
1454 |
@param aOutput On return, the write stream to which the text is written.
|
|
1455 |
@param aParam Export parameters, including an optional foreign encoding to
|
|
1456 |
convert the Unicode text into, a file server connection, (this is needed for
|
|
1457 |
the character conversion if not specified, one will be created), a line
|
|
1458 |
wrap width, and the maximum number of characters to export.
|
|
1459 |
@param aResult On return, contains the number of characters read and written.
|
|
1460 |
@see CPlainText::TImportExportParam
|
|
1461 |
@see CPlainText::TImportExportResult */
|
|
1462 |
{
|
|
1463 |
TImportExportParam param = aParam;
|
|
1464 |
param.iInputInternal = TRUE; // force input to internal format
|
|
1465 |
param.iMaxInputChars = Min(param.iMaxInputChars,DocumentLength() - aPos); // ensure final paragraph delimiter is not exported
|
|
1466 |
RBufReadStream input(*iByteStore,aPos);
|
|
1467 |
TPlainTextWriter::TranslateL(param,aResult,aOutput,input);
|
|
1468 |
}
|
|
1469 |
|
|
1470 |
|
|
1471 |
EXPORT_C TPtrC CPlainText::Read(TInt aStartPos)const
|
|
1472 |
/** Gets a read-only view of a portion of the text object.
|
|
1473 |
|
|
1474 |
The extent of the view is the range of characters starting at aStartPos and ending at whichever of the
|
|
1475 |
following document positions is reached first:
|
|
1476 |
|
|
1477 |
- The end of the document.
|
|
1478 |
- The end of the segment if using segmented storage (the storage type is specified in the NewL().
|
|
1479 |
|
|
1480 |
Therefore, when using a segmented buffer to store the document, the length of the resultant view may be
|
|
1481 |
less than the requested length. In this case multiple calls to Read() may be necessary.
|
|
1482 |
|
|
1483 |
@param aStartPos The document position at which to begin reading. Must be valid or a panic occurs.
|
|
1484 |
@return Constant pointer to a section of the text object.
|
|
1485 |
*/
|
|
1486 |
{
|
|
1487 |
__TEST_INVARIANT;
|
|
1488 |
__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1489 |
|
|
1490 |
TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
|
|
1491 |
return TPtrC((TText*)buf.Ptr(),buf.Length()/sizeof(TText));
|
|
1492 |
}
|
|
1493 |
|
|
1494 |
|
|
1495 |
EXPORT_C TPtrC CPlainText::Read(TInt aStartPos,TInt aLength)const
|
|
1496 |
/** Gets a read-only view of a portion of the text object.
|
|
1497 |
|
|
1498 |
The extent of the view is the range of characters starting at aStartPos and ending at whichever of the
|
|
1499 |
following document positions is reached first:
|
|
1500 |
|
|
1501 |
- The end of the document.
|
|
1502 |
- The end of the segment if using segmented storage (the storage type is specified in the NewL().
|
|
1503 |
- The sum of aStartPos and (aLength-1).
|
|
1504 |
|
|
1505 |
Therefore, when using a segmented buffer to store the document, the length of the resultant view may be
|
|
1506 |
less than the requested length. In this case multiple calls to Read() may be necessary.
|
|
1507 |
|
|
1508 |
@param aStartPos The document position at which to begin reading. Must be valid or a panic occurs.
|
|
1509 |
@param aLength The number of characters to read, inclusive of the character at position aStartPos.
|
|
1510 |
@return Constant pointer to a section of the text object.
|
|
1511 |
*/
|
|
1512 |
{
|
|
1513 |
__TEST_INVARIANT;
|
|
1514 |
__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1515 |
|
|
1516 |
TPtr8 buf=iByteStore->Ptr(aStartPos*sizeof(TText));
|
|
1517 |
TInt length=Min(aLength,((TInt)buf.Length()/sizeof(TText)));
|
|
1518 |
return TPtrC((TText*)buf.Ptr(),length);
|
|
1519 |
}
|
|
1520 |
|
|
1521 |
|
|
1522 |
EXPORT_C void CPlainText::Extract(TDes& aBuf,TInt aPos)const
|
|
1523 |
/** Copies the contents of the text object into a descriptor overloaded
|
|
1524 |
function. The function copies all characters from and including the document
|
|
1525 |
position specified, to the end of the document or the end of the range
|
|
1526 |
of characters, if specified.
|
|
1527 |
|
|
1528 |
The buffer's maximum length must be greater than or equal to the number
|
|
1529 |
of characters to extract, or a panic occurs.
|
|
1530 |
|
|
1531 |
@param aBuf A buffer; on return contains the extracted text.
|
|
1532 |
@param aPos The document position from which to copy. Must be valid or a
|
|
1533 |
panic occurs.*/
|
|
1534 |
{
|
|
1535 |
__TEST_INVARIANT;
|
|
1536 |
TInt documentLength=DocumentLength();
|
|
1537 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=documentLength,Panic(ECharPosBeyondDocument));
|
|
1538 |
__ASSERT_ALWAYS(aBuf.MaxLength()>=documentLength - aPos,Panic(EExtractBufferTooSmall));
|
|
1539 |
|
|
1540 |
DoExtract(aBuf,aPos,documentLength-aPos);
|
|
1541 |
}
|
|
1542 |
|
|
1543 |
|
|
1544 |
EXPORT_C void CPlainText::Extract(TDes& aBuf,TInt aPos,TInt aLength)const
|
|
1545 |
/** Copies the contents of the text object into a descriptor-overloaded function.
|
|
1546 |
The function copies all characters from and including the document position
|
|
1547 |
specified, to the end of the document or the end of the range of characters,
|
|
1548 |
if specified.
|
|
1549 |
|
|
1550 |
The buffer's maximum length must be greater than or equal to aLength, or a
|
|
1551 |
panic ocurs.
|
|
1552 |
|
|
1553 |
@param aBuf A buffer; on return contains the extracted text.
|
|
1554 |
@param aPos The document position from which to copy. Must be valid or a panic
|
|
1555 |
occurs.
|
|
1556 |
@param aLength The number of characters to copy. */
|
|
1557 |
{
|
|
1558 |
__TEST_INVARIANT;
|
|
1559 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1560 |
__ASSERT_ALWAYS(aBuf.MaxLength()>=aLength,Panic(EExtractBufferTooSmall));
|
|
1561 |
|
|
1562 |
DoExtract(aBuf,aPos,aLength);
|
|
1563 |
}
|
|
1564 |
|
|
1565 |
// Extract text, optionally discarding some characters such as control characters and soft hyphens or
|
|
1566 |
// inline text, depending on the flag.
|
|
1567 |
EXPORT_C void CPlainText::ExtractSelectively(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags)
|
|
1568 |
{
|
|
1569 |
__ASSERT_ALWAYS(aPos >= 0 && aPos <= DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1570 |
DoExtract(aBuf,aPos,aLength,aFlags);
|
|
1571 |
}
|
|
1572 |
|
|
1573 |
|
|
1574 |
void CPlainText::DoExtract(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags) const
|
|
1575 |
/** Copies aLength characters, commencing at aPos, into the specified
|
|
1576 |
buffer aBuf. If aLength is greater than the amount of data left,
|
|
1577 |
then all remaining characters are written.*/
|
|
1578 |
{
|
|
1579 |
aBuf.SetLength(0);
|
|
1580 |
TInt remainingLength=Min(aLength,DocumentLength()-aPos);
|
|
1581 |
TInt startPos=aPos;
|
|
1582 |
FOREVER
|
|
1583 |
{
|
|
1584 |
TPtrC textRead=Read(startPos);
|
|
1585 |
TInt lengthRead=textRead.Length();
|
|
1586 |
if (lengthRead>remainingLength)
|
|
1587 |
lengthRead=remainingLength;
|
|
1588 |
|
|
1589 |
// Remove specific characters
|
|
1590 |
if (aFlags & EExtractVisible)
|
|
1591 |
{
|
|
1592 |
const TText* p = textRead.Ptr();
|
|
1593 |
const TText* q = p + lengthRead;
|
|
1594 |
while (p < q)
|
|
1595 |
{
|
|
1596 |
TChar c(*p++);
|
|
1597 |
if (c == EParagraphDelimiter || c == ELineBreak || c == ETabCharacter)
|
|
1598 |
aBuf.Append(' ');
|
|
1599 |
else if (c != EPotentialHyphen && c.IsPrint())
|
|
1600 |
aBuf.Append(c);
|
|
1601 |
}
|
|
1602 |
}
|
|
1603 |
|
|
1604 |
// Remove inline text from the specified section
|
|
1605 |
else if (aFlags & EExcludeInlineEditedText)
|
|
1606 |
{
|
|
1607 |
const TInt inlineTextPos = GetPositionOfInlineTextInDocument();
|
|
1608 |
const TText* p = textRead.Ptr();
|
|
1609 |
|
|
1610 |
if (inlineTextPos != KErrNotFound)
|
|
1611 |
{
|
|
1612 |
for (TInt i=aPos; i<(aPos+lengthRead); i++)
|
|
1613 |
{
|
|
1614 |
if (!((i >= inlineTextPos) && (i <= (inlineTextPos + GetLengthOfInlineText() - 1))))
|
|
1615 |
{
|
|
1616 |
TChar c(*p++);
|
|
1617 |
aBuf.Append(c);
|
|
1618 |
continue;
|
|
1619 |
}
|
|
1620 |
++p;
|
|
1621 |
}
|
|
1622 |
}
|
|
1623 |
else
|
|
1624 |
aBuf.Append(textRead.Ptr(),lengthRead);
|
|
1625 |
}
|
|
1626 |
else
|
|
1627 |
aBuf.Append(textRead.Ptr(),lengthRead);
|
|
1628 |
remainingLength-=lengthRead;
|
|
1629 |
if (remainingLength==0)
|
|
1630 |
return;
|
|
1631 |
startPos+=lengthRead;
|
|
1632 |
}
|
|
1633 |
}
|
|
1634 |
|
|
1635 |
|
|
1636 |
|
|
1637 |
EXPORT_C void CPlainText::SetPageTable(TPageTable* aPageTable)
|
|
1638 |
/** Links the text object to a page table. A page table is an array of integers;
|
|
1639 |
each integer represents the number of characters on a page. It is required
|
|
1640 |
for pagination. The page table is updated when changes are made to the document,
|
|
1641 |
e.g. after pasting from the clipboard, inserting, importing or deleting text.
|
|
1642 |
|
|
1643 |
The text object does not take ownership of the page table specified.
|
|
1644 |
|
|
1645 |
@param aPageTable The page table to be referenced by the text object. */
|
|
1646 |
{
|
|
1647 |
iPageTable=aPageTable;
|
|
1648 |
SetHasChanged(ETrue);
|
|
1649 |
}
|
|
1650 |
|
|
1651 |
|
|
1652 |
void CPlainText::UpdatePageTable(TInt aPos,TInt aLength)
|
|
1653 |
// Adds aLength number of characters to the page in the page table
|
|
1654 |
// specified by the character position aPos.
|
|
1655 |
// Called from i) Insert ii) Delete iii) Paste from clipboard iv) Text file import.
|
|
1656 |
//
|
|
1657 |
{
|
|
1658 |
__TEST_INVARIANT;
|
|
1659 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength()+1,Panic(ECharPosBeyondDocument));
|
|
1660 |
|
|
1661 |
if (iPageTable)
|
|
1662 |
(*iPageTable)[PageContainingPos(aPos)]+=aLength;
|
|
1663 |
}
|
|
1664 |
|
|
1665 |
|
|
1666 |
EXPORT_C TInt CPlainText::PageContainingPos(TInt aPos)const
|
|
1667 |
/** Gets the number of the page which contains the specified document position.
|
|
1668 |
If no page table has been set up, the function returns a value of zero. Use
|
|
1669 |
SetPageTable() to set up the page table.
|
|
1670 |
|
|
1671 |
@param aPos A document position. Must be valid or a panic occurs.
|
|
1672 |
@return The page number containing document position aPos. */
|
|
1673 |
{
|
|
1674 |
__TEST_INVARIANT;
|
|
1675 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1676 |
|
|
1677 |
if (!iPageTable || (iPageTable->Count()<1))
|
|
1678 |
return 0;
|
|
1679 |
else
|
|
1680 |
{
|
|
1681 |
TInt pageOffset=0;
|
|
1682 |
TInt charCount=(*iPageTable)[pageOffset];
|
|
1683 |
while (charCount<=aPos)
|
|
1684 |
{
|
|
1685 |
pageOffset++;
|
|
1686 |
charCount+=(*iPageTable)[pageOffset];
|
|
1687 |
}
|
|
1688 |
return pageOffset;
|
|
1689 |
}
|
|
1690 |
}
|
|
1691 |
|
|
1692 |
EXPORT_C TEtextComponentInfo CPlainText::ComponentInfo()const
|
|
1693 |
/** Gets information about the number of components contained in the text object.
|
|
1694 |
For plain text, only the field count has relevance.
|
|
1695 |
|
|
1696 |
@return Contains the field count. */
|
|
1697 |
{return TEtextComponentInfo(FieldCount(),0,0);}
|
|
1698 |
|
|
1699 |
|
|
1700 |
|
|
1701 |
EXPORT_C TInt CPlainText::FieldCount() const
|
|
1702 |
/** Gets a count of the number of fields in the text object's field set.
|
|
1703 |
|
|
1704 |
@return The number of fields in the field set. */
|
|
1705 |
{
|
|
1706 |
__TEST_INVARIANT;
|
|
1707 |
|
|
1708 |
return (FieldSetPresent())
|
|
1709 |
? iFieldSet->FieldCount()
|
|
1710 |
: 0;
|
|
1711 |
}
|
|
1712 |
|
|
1713 |
EXPORT_C void CPlainText::InsertFieldL(TInt aPos,CTextField* aField,TUid aFieldType)
|
|
1714 |
/** Inserts a field into the text object at a specified document position. creating a zero-length field record.
|
|
1715 |
Maintain the field set.
|
|
1716 |
|
|
1717 |
Note: After insertion, the field should be evaluated in order to make its contents
|
|
1718 |
visible; use UpdateFieldL().
|
|
1719 |
|
|
1720 |
@param aPos The document position at which to insert the field. Must be valid,
|
|
1721 |
or a panic occurs.
|
|
1722 |
@param aField The field to insert, created by NewTextFieldL(). Must not be
|
|
1723 |
NULL, or a panic occurs.
|
|
1724 |
@param aFieldType Identifies the type of field to insert. For the built in
|
|
1725 |
field types, see the UID values defined in flddef.h. */
|
|
1726 |
{
|
|
1727 |
__TEST_INVARIANT;
|
|
1728 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1729 |
__ASSERT_ALWAYS(aField,Panic(ENoTextField));
|
|
1730 |
|
|
1731 |
if (!FieldSetPresent())
|
|
1732 |
CreateFieldSetL(DocumentLength());
|
|
1733 |
iFieldSet->InsertFieldL(aPos,aField,aFieldType);
|
|
1734 |
SetHasChanged(ETrue);
|
|
1735 |
|
|
1736 |
__TEST_INVARIANT;
|
|
1737 |
}
|
|
1738 |
|
|
1739 |
EXPORT_C void CPlainText::UpdateFieldL(TInt aPos)
|
|
1740 |
/** Re-evaluates the field which covers the document position specified. Re-evaluating
|
|
1741 |
a field means calculating the field's new value, then inserting that value
|
|
1742 |
into the text object, replacing the previous value.
|
|
1743 |
|
|
1744 |
Notes:
|
|
1745 |
|
|
1746 |
fields have a maximum length of 20 characters.
|
|
1747 |
|
|
1748 |
the first time a field is updated, the position specified should be the position
|
|
1749 |
at which the field was inserted.
|
|
1750 |
|
|
1751 |
@param aPos A document position in the field to be updated. Must be a valid
|
|
1752 |
position, or a panic occurs. */
|
|
1753 |
{
|
|
1754 |
__TEST_INVARIANT;
|
|
1755 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1756 |
|
|
1757 |
if (!FieldSetPresent())
|
|
1758 |
return;
|
|
1759 |
TFindFieldInfo info;
|
|
1760 |
if (iFieldSet->FindFields(info,aPos))
|
|
1761 |
{// a field exists at aPos, so update it.
|
|
1762 |
HBufC* valueBuf=HBufC::NewL(KMaxFieldBufferSize); // will hold the new value,max length 20
|
|
1763 |
/*
|
|
1764 |
Don't put valueBuf on the cleanup stack before calling NewFieldValueL because NewFieldValueL
|
|
1765 |
sometimes changes valueBuf, in which case it itself puts it on the cleanup stack.
|
|
1766 |
*/
|
|
1767 |
iFieldSet->NewFieldValueL(valueBuf,info.iFirstFieldPos); // get the new value
|
|
1768 |
CleanupStack::PushL(valueBuf);
|
|
1769 |
DoPtInsertL(info.iFirstFieldPos,*valueBuf); // insert the new text into the document
|
|
1770 |
DoPtDelete(info.iFirstFieldPos+valueBuf->Length(),info.iFirstFieldLen); // delete the old text of the field
|
|
1771 |
iFieldSet->NotifyFieldUpdate(aPos,valueBuf->Length()); // inform the field set
|
|
1772 |
CleanupStack::PopAndDestroy();
|
|
1773 |
}
|
|
1774 |
SetHasChanged(ETrue);
|
|
1775 |
|
|
1776 |
__TEST_INVARIANT;
|
|
1777 |
}
|
|
1778 |
|
|
1779 |
|
|
1780 |
|
|
1781 |
EXPORT_C void CPlainText::UpdateAllFieldsL()
|
|
1782 |
/** Re-evaluates all of the fields in the text object. Re-evaluating a field means
|
|
1783 |
calculating the field's new value, then inserting that value into the text
|
|
1784 |
object, replacing the previous value.
|
|
1785 |
|
|
1786 |
Note: Fields have a maximum length of 20 characters. */
|
|
1787 |
{
|
|
1788 |
__TEST_INVARIANT;
|
|
1789 |
|
|
1790 |
TInt numFields=FieldCount();
|
|
1791 |
TInt pos=0;
|
|
1792 |
TFindFieldInfo info;
|
|
1793 |
for (TInt item=0;item<numFields;item++)
|
|
1794 |
{
|
|
1795 |
// find the next field and go to its beginning
|
|
1796 |
iFieldSet->FindFields(info,pos,DocumentLength()-pos);
|
|
1797 |
pos=info.iFirstFieldPos;
|
|
1798 |
UpdateFieldL(pos);
|
|
1799 |
// the field has changed, find out its new length and go to the end of it
|
|
1800 |
iFieldSet->FindFields(info,pos);
|
|
1801 |
pos+=info.iFirstFieldLen;
|
|
1802 |
}
|
|
1803 |
|
|
1804 |
__TEST_INVARIANT;
|
|
1805 |
}
|
|
1806 |
|
|
1807 |
|
|
1808 |
|
|
1809 |
EXPORT_C TBool CPlainText::RemoveField(TInt aPos)
|
|
1810 |
/** Removes the field covering the document position specified from the field set,
|
|
1811 |
and deletes all text content associated with the field from the text object.
|
|
1812 |
|
|
1813 |
@param aPos A document position within the field to be deleted. Must be a
|
|
1814 |
valid position or a panic occurs.
|
|
1815 |
@return ETrue if a field was located at aPos. EFalse if no field was located
|
|
1816 |
at aPos. */
|
|
1817 |
{
|
|
1818 |
__TEST_INVARIANT;
|
|
1819 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1820 |
|
|
1821 |
TBool fieldRemoved=EFalse;
|
|
1822 |
|
|
1823 |
if (FieldSetPresent())
|
|
1824 |
{
|
|
1825 |
TFindFieldInfo info;
|
|
1826 |
if (iFieldSet->FindFields(info,aPos))
|
|
1827 |
{// remove the field's record & associated text
|
|
1828 |
Delete(info.iFirstFieldPos,info.iFirstFieldLen);
|
|
1829 |
iFieldSet->RemoveField(aPos);
|
|
1830 |
fieldRemoved=ETrue;
|
|
1831 |
}
|
|
1832 |
}
|
|
1833 |
if (fieldRemoved)
|
|
1834 |
SetHasChanged(ETrue);
|
|
1835 |
|
|
1836 |
__TEST_INVARIANT;
|
|
1837 |
return fieldRemoved;
|
|
1838 |
}
|
|
1839 |
|
|
1840 |
|
|
1841 |
|
|
1842 |
EXPORT_C TBool CPlainText::FindFields(TInt aPos) const
|
|
1843 |
{
|
|
1844 |
__TEST_INVARIANT;
|
|
1845 |
|
|
1846 |
if (FieldSetPresent())
|
|
1847 |
return iFieldSet->FindFields(aPos);
|
|
1848 |
else
|
|
1849 |
return EFalse;
|
|
1850 |
}
|
|
1851 |
|
|
1852 |
|
|
1853 |
EXPORT_C TBool CPlainText::FindFields(TFindFieldInfo& aInfo,TInt aPos,TInt aRange)const
|
|
1854 |
/** Tests whether a document position is located within a field overloaded
|
|
1855 |
function.
|
|
1856 |
|
|
1857 |
The second overload extracts information about all fields located
|
|
1858 |
within a range of characters.
|
|
1859 |
|
|
1860 |
@param aPos The document position. Must be valid or a panic occurs.
|
|
1861 |
@param aInfo On return, contains the number of fields fully or partially
|
|
1862 |
within the range of characters specified and the start position and length
|
|
1863 |
of the first field found.
|
|
1864 |
@param aRange The number of characters to search, beginning at aPos. Must
|
|
1865 |
not be negative, or a panic occurs. The sum of aPos and aRange must be less
|
|
1866 |
than the document length, or a panic occurs. The default range is zero. In
|
|
1867 |
this case the function just returns information about the single field located
|
|
1868 |
at the position specified.
|
|
1869 |
@return ETrue if aPos is located within a field, or if there were one or more
|
|
1870 |
fields found in the range. EFalse if not. */
|
|
1871 |
{
|
|
1872 |
__TEST_INVARIANT;
|
|
1873 |
|
|
1874 |
if (FieldSetPresent())
|
|
1875 |
return iFieldSet->FindFields(aInfo,aPos,aRange);
|
|
1876 |
else
|
|
1877 |
return EFalse;
|
|
1878 |
}
|
|
1879 |
|
|
1880 |
EXPORT_C const CTextField* CPlainText::TextField(TInt aPos)const
|
|
1881 |
/** Returns a pointer to the field located at the specified document position.
|
|
1882 |
|
|
1883 |
@param aPos A document position within the field. Must be a valid document
|
|
1884 |
position, or a panic occurs.
|
|
1885 |
@return Pointer to the field which covers position aPos. NULL if there is no
|
|
1886 |
field at the specified position. */
|
|
1887 |
{
|
|
1888 |
__TEST_INVARIANT;
|
|
1889 |
|
|
1890 |
return (FieldSetPresent())
|
|
1891 |
? iFieldSet->TextField(aPos)
|
|
1892 |
: NULL;
|
|
1893 |
}
|
|
1894 |
|
|
1895 |
EXPORT_C TBool CPlainText::ConvertFieldToText(TInt aPos)
|
|
1896 |
/** Converts the field containing the specified document position into text, leaving
|
|
1897 |
its current value in the text object. Does not update the field beforehand.
|
|
1898 |
|
|
1899 |
@param aPos A document position within the field to convert. Must be a valid
|
|
1900 |
position or a panic occurs.
|
|
1901 |
@return ETrue if there was a field located at aPos. EFalse if there was no
|
|
1902 |
field located at aPos. */
|
|
1903 |
{
|
|
1904 |
__TEST_INVARIANT;
|
|
1905 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
|
|
1906 |
|
|
1907 |
TBool fieldConverted=EFalse;
|
|
1908 |
|
|
1909 |
if (FieldSetPresent())
|
|
1910 |
{
|
|
1911 |
TFindFieldInfo info;
|
|
1912 |
iFieldSet->FindFields(info,aPos);
|
|
1913 |
if (iFieldSet->RemoveField(aPos))
|
|
1914 |
fieldConverted=ETrue;
|
|
1915 |
}
|
|
1916 |
if (fieldConverted)
|
|
1917 |
SetHasChanged(ETrue);
|
|
1918 |
|
|
1919 |
__TEST_INVARIANT;
|
|
1920 |
return fieldConverted;
|
|
1921 |
}
|
|
1922 |
|
|
1923 |
|
|
1924 |
EXPORT_C void CPlainText::ConvertAllFieldsToText()
|
|
1925 |
/** Removes all fields from the text object's field set, leaving their current
|
|
1926 |
text value in the text object. Does not update the fields beforehand. */
|
|
1927 |
{
|
|
1928 |
__TEST_INVARIANT;
|
|
1929 |
|
|
1930 |
TInt fieldCount=FieldCount();
|
|
1931 |
TInt pos=0;
|
|
1932 |
for (TInt item=0;item<fieldCount;item++)
|
|
1933 |
{// Convert each field in turn.
|
|
1934 |
TFindFieldInfo info;
|
|
1935 |
iFieldSet->FindFields(info,pos); // find the next field and go to its beginning
|
|
1936 |
pos=info.iFirstFieldPos;
|
|
1937 |
ConvertFieldToText(pos);
|
|
1938 |
}
|
|
1939 |
|
|
1940 |
__TEST_INVARIANT;
|
|
1941 |
}
|
|
1942 |
|
|
1943 |
EXPORT_C void CPlainText::SetFieldFactory(MTextFieldFactory* aFactory)
|
|
1944 |
/** Sets up a field factory. A field factory is an instance of a class deriving
|
|
1945 |
from MTextFieldFactory. It must implement a NewFieldL() function to create
|
|
1946 |
and return fields of the desired type. The field factory's NewFieldL() function
|
|
1947 |
is called by CPlainText::NewTextFieldL(). A field factory must be set up if
|
|
1948 |
you intend to add any fields to the text object.
|
|
1949 |
|
|
1950 |
@param aFactory The field factory. */
|
|
1951 |
{
|
|
1952 |
// Set the FieldSet's header factory handle (this points to the built-in factory by default)
|
|
1953 |
//+ This function has no way to report failure, which can happen if CreateFieldSetL leaves. It ought to leave.
|
|
1954 |
|
|
1955 |
// Create field set if necessary & set the factory
|
|
1956 |
int error = 0;
|
|
1957 |
if (!FieldSetPresent())
|
|
1958 |
TRAP(error,CreateFieldSetL(DocumentLength()));
|
|
1959 |
if (!error)
|
|
1960 |
iFieldSet->SetFieldFactory(aFactory);
|
|
1961 |
}
|
|
1962 |
|
|
1963 |
|
|
1964 |
|
|
1965 |
EXPORT_C CTextField* CPlainText::NewTextFieldL(TUid aFieldType)const
|
|
1966 |
/** Creates and returns a new field. Before calling this function, a field
|
|
1967 |
factory should have been set up, either by calling SetFieldFactory(), or by
|
|
1968 |
specifying one in the NewL(). The field factory's NewFieldL() function is
|
|
1969 |
called to create a field of the type specified in the argument. A NULL field
|
|
1970 |
is returned if no field factory has been set up.
|
|
1971 |
|
|
1972 |
@param aFieldType Identifies the field type.
|
|
1973 |
@return Pointer to the new text field. NULL if no field factory has been set
|
|
1974 |
up. */
|
|
1975 |
{
|
|
1976 |
__TEST_INVARIANT;
|
|
1977 |
|
|
1978 |
CTextField* field=NULL;
|
|
1979 |
if (FieldSetPresent())
|
|
1980 |
field=iFieldSet->NewFieldL(aFieldType);
|
|
1981 |
|
|
1982 |
__TEST_INVARIANT;
|
|
1983 |
return field;
|
|
1984 |
}
|
|
1985 |
|
|
1986 |
void CPlainText::CreateFieldSetL(TInt aDocumentLength)
|
|
1987 |
{
|
|
1988 |
iFieldSet = CTextFieldSet::NewL(aDocumentLength);
|
|
1989 |
}
|
|
1990 |
|
|
1991 |
EXPORT_C const MTextFieldFactory* CPlainText::FieldFactory()const
|
|
1992 |
/** Gets a pointer to the field factory used by the text object. The field factory
|
|
1993 |
may be set up using SetFieldFactory(), or may be specified in the NewL().
|
|
1994 |
|
|
1995 |
@return The field factory. NULL if no field factory has been set up. */
|
|
1996 |
{return (FieldSetPresent()) ? iFieldSet->FieldFactory() : NULL;}
|
|
1997 |
|
|
1998 |
CEditableTextOptionalData::CEditableTextOptionalData()
|
|
1999 |
{
|
|
2000 |
// do nothing
|
|
2001 |
}
|
|
2002 |
|
|
2003 |
CEditableTextOptionalData::~CEditableTextOptionalData()
|
|
2004 |
{
|
|
2005 |
delete iInlineEditData;
|
|
2006 |
}
|