|
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 "FLDINFO.H" |
|
21 #include "FLDSET.H" |
|
22 #include "TXTRICH.H" |
|
23 |
|
24 #include "TXTSTD.H" |
|
25 #include "TXTINDEX.H" |
|
26 #include "ParseLst.h" |
|
27 |
|
28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
29 #include "TXTETEXT_INTERNAL.H" |
|
30 #endif |
|
31 |
|
32 EXPORT_C void CRichText::UpdateFieldL(TInt aPos) |
|
33 // Updates the field at aPos, adjusting the rich text index by the required amount. |
|
34 // |
|
35 /** Re-evaluates the field which covers the document position specified. Re-evaluating |
|
36 a field means calculating the field's new value, then inserting that value |
|
37 into the text object, replacing the previous value. |
|
38 |
|
39 Notes: |
|
40 |
|
41 fields have a maximum length of 20 characters |
|
42 |
|
43 the first time a field is updated, the position specified should be the position |
|
44 at which the field was inserted |
|
45 |
|
46 @param aPos A document position in the field to be updated. Must be a valid |
|
47 position, or a panic occurs. */ |
|
48 { |
|
49 __TEST_INVARIANT; |
|
50 __ASSERT_ALWAYS(aPos >= 0 && aPos <= DocumentLength(), Panic(ECharPosBeyondDocument)); |
|
51 |
|
52 TFindFieldInfo fieldInfo; |
|
53 if (iFieldSet->FindFields(fieldInfo, aPos)) |
|
54 {// a field exists at aPos, so update it. |
|
55 HBufC* valueBuf = HBufC::NewL(KMaxFieldBufferSize); // will hold the new value |
|
56 |
|
57 /* |
|
58 Calculate new field value and insert it. |
|
59 Don't put valueBuf on the cleanup stack before calling NewFieldValueL because NewFieldValueL |
|
60 sometimes changes valueBuf, in which case it itself puts it on the cleanup stack. |
|
61 */ |
|
62 iFieldSet->NewFieldValueL(valueBuf, fieldInfo.iFirstFieldPos); // get the new value |
|
63 CleanupStack::PushL(valueBuf); |
|
64 DoPtInsertL(fieldInfo.iFirstFieldPos, *valueBuf); // insert the new text into the document |
|
65 TBool indexPresent = IndexPresent(); |
|
66 if (indexPresent) |
|
67 { |
|
68 TRAPD(ret, iIndex->InsertL(aPos, valueBuf->Des(), *iGlobalParaFormatLayer)); |
|
69 if (ret != KErrNone) |
|
70 { |
|
71 DoPtDelete(fieldInfo.iFirstFieldPos, valueBuf->Length()); |
|
72 User::Leave(ret); |
|
73 } |
|
74 } |
|
75 // |
|
76 // Now delete the old field value from the text. |
|
77 TIndexDeleteInfo indexInfo; |
|
78 if (indexPresent) |
|
79 { |
|
80 TRAPD(ret, iIndex->SetForDeleteL(indexInfo, fieldInfo.iFirstFieldPos + valueBuf->Length(), fieldInfo.iFirstFieldLen)); |
|
81 if (ret != KErrNone) |
|
82 {// Maintain rich text invariant. Both old&new values now make up the current field value. |
|
83 iFieldSet->NotifyFieldUpdate(aPos, valueBuf->Length() + fieldInfo.iFirstFieldLen); |
|
84 User::Leave(ret); |
|
85 }// Not the greatest but at least the text stream is consistent with the rich text index. |
|
86 iIndex->DeleteNow(indexInfo); |
|
87 } |
|
88 DoPtDelete(fieldInfo.iFirstFieldPos + valueBuf->Length(), fieldInfo.iFirstFieldLen); // delete the old text of the field |
|
89 iFieldSet->NotifyFieldUpdate(aPos, valueBuf->Length()); // inform the field set |
|
90 // |
|
91 iParserData->MergeRange(aPos,fieldInfo.iFirstFieldLen,valueBuf->Length()); |
|
92 CallEditObserver(aPos, valueBuf->Length() - fieldInfo.iFirstFieldLen); |
|
93 CleanupStack::PopAndDestroy(); // valueBuf |
|
94 } |
|
95 |
|
96 __TEST_INVARIANT; |
|
97 } |