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