|
1 /* |
|
2 * Copyright (c) 2003 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <tagma.h> |
|
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include <tagmalayoutandsource.h> |
|
23 #endif |
|
24 #include "AknNoMatchesIndicatorInlineTextSource.h" |
|
25 |
|
26 // MODULE TEMPLATES |
|
27 |
|
28 // MODULE DATA STRUCTURES |
|
29 |
|
30 // LOCAL CONSTANTS |
|
31 _LIT(KTextForUnknownPredictiveTextWestern, "?" ); |
|
32 _LIT(KTextForUnknownPredictiveTextArabic, "\x061f" ); // Arabic Question Mark |
|
33 |
|
34 #define ARABIC_CODE_PAGE_BASE 0x0600 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 |
|
39 //////////////////////////////////////////////////////////////////////////////// |
|
40 // |
|
41 // CAknNoMatchesIndicatorInlineTextSource |
|
42 // |
|
43 //////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
45 CAknNoMatchesIndicatorInlineTextSource* CAknNoMatchesIndicatorInlineTextSource::NewL( const CTextLayout& aTextLayout ) |
|
46 { |
|
47 CAknNoMatchesIndicatorInlineTextSource* self = |
|
48 new (ELeave) CAknNoMatchesIndicatorInlineTextSource( aTextLayout ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 CAknNoMatchesIndicatorInlineTextSource::~CAknNoMatchesIndicatorInlineTextSource() |
|
56 { |
|
57 } |
|
58 |
|
59 void CAknNoMatchesIndicatorInlineTextSource::CheckFormattingL(const TTmDocPos& aFrom, const TTmDocPos& aTo ) |
|
60 { |
|
61 DoFormatL( aFrom, aTo ); |
|
62 } |
|
63 |
|
64 void CAknNoMatchesIndicatorInlineTextSource::DoFormatL( const TTmDocPos& aFrom, const TTmDocPos& aTo) |
|
65 { |
|
66 |
|
67 InlineTextStore()->ClearRange( aFrom, aTo ); |
|
68 |
|
69 TTmCharFormat format; |
|
70 TPtrC buffer; |
|
71 TBool endOfPara(EFalse); |
|
72 |
|
73 TInt charPos = aFrom.iPos; |
|
74 // Process the buffer within the format |
|
75 while ( charPos <= aTo.iPos && !endOfPara ) |
|
76 { |
|
77 iTextLayout.TagmaTextLayout().Source()->GetText( charPos, buffer, format ); |
|
78 |
|
79 // Check for end of paragraph mark |
|
80 TInt lengthInFormat = buffer.Length(); |
|
81 // trim off the paragraph delimeter from the format chunk, or at least for our book-keeping of it |
|
82 if ( buffer[lengthInFormat-1] == 0x2029 ) |
|
83 { |
|
84 lengthInFormat--; |
|
85 endOfPara = ETrue; |
|
86 } |
|
87 |
|
88 if ( format.iEffects & TTmCharFormat::ENoMatchesIndicator ) |
|
89 { |
|
90 // Have to ensure that this is at the logical end of the markup (eg, there could be more |
|
91 // marked up text wrapped to the next line) |
|
92 if ( !FormatOfNextCharacterIsUnknownInlineFepTextStyle( charPos + lengthInFormat ) ) |
|
93 // Store at end/trailing |
|
94 StoreNoMatchesIndicatorInlineTextL( charPos + lengthInFormat, EFalse, buffer ); |
|
95 } |
|
96 |
|
97 charPos += lengthInFormat; |
|
98 } |
|
99 |
|
100 #ifdef INLINE_EDIT_DUMPING |
|
101 // Dumping code |
|
102 TBuf<80> buf; |
|
103 RDebug::Print(_L("\nDump of inline texts")); |
|
104 for ( TInt index = 0; index < iInlineTextStore->Count(); index++) |
|
105 { |
|
106 |
|
107 CAknPositionedInlineText* inlineText = iInlineTextStore->At( index ); |
|
108 TPtrC ptr = inlineText->InlineText(); |
|
109 buf.Format( _L("DocPos: %d Trailing/Leading: %d Text=<%S>"), |
|
110 inlineText->DocPos().iPos, |
|
111 inlineText->DocPos().iLeadingEdge, &ptr ); |
|
112 |
|
113 RDebug::Print( buf ); |
|
114 } |
|
115 #endif |
|
116 |
|
117 } |
|
118 |
|
119 |
|
120 CAknNoMatchesIndicatorInlineTextSource::CAknNoMatchesIndicatorInlineTextSource( const CTextLayout& aTextLayout ) |
|
121 : CAknInlineTextSource(), iTextLayout(aTextLayout) |
|
122 {} |
|
123 |
|
124 void CAknNoMatchesIndicatorInlineTextSource::StoreNoMatchesIndicatorInlineTextL( |
|
125 TInt aPos, |
|
126 TBool aLeadingEdge, |
|
127 const TDesC& aSampleText ) |
|
128 { |
|
129 TTmDocPos docPos( aPos, aLeadingEdge ); |
|
130 |
|
131 CAknPositionedInlineText* inlineText = |
|
132 CAknPositionedInlineText::NewL( |
|
133 docPos, |
|
134 TextForUnknownPredictiveTextIndication( aSampleText) ); |
|
135 |
|
136 CleanupStack::PushL( inlineText ); |
|
137 InlineTextStore()->InsertInlineTextL( inlineText ); |
|
138 CleanupStack::Pop(); // inlineText |
|
139 } |
|
140 |
|
141 TPtrC CAknNoMatchesIndicatorInlineTextSource::TextForUnknownPredictiveTextIndication( const TDesC& aSampleText ) const |
|
142 { |
|
143 TUint codebase = CodeBaseOfText( aSampleText); |
|
144 if ( codebase == ARABIC_CODE_PAGE_BASE ) |
|
145 return KTextForUnknownPredictiveTextArabic(); //unknownTextBuffer; |
|
146 else |
|
147 return KTextForUnknownPredictiveTextWestern(); //unknownTextBuffer; |
|
148 } |
|
149 /** |
|
150 * Implementation is not safe for surrogate pairs |
|
151 */ |
|
152 TUint CAknNoMatchesIndicatorInlineTextSource::CodeBaseOfText( const TDesC& aSampleText ) const |
|
153 { |
|
154 TUint base = 0; |
|
155 |
|
156 // examine buffer; take first printable character |
|
157 // if none found, then 0 is returned |
|
158 TChar character; |
|
159 for ( TInt index = 0;index < aSampleText.Length(); index++) |
|
160 { |
|
161 character = aSampleText[index]; |
|
162 if ( character.IsPrint() ) |
|
163 { |
|
164 TUint ch(character); |
|
165 ch &= 0xffffff00; // only interested in upper bits |
|
166 base = (TUint)ch; |
|
167 break; |
|
168 } |
|
169 } |
|
170 |
|
171 return base; |
|
172 } |
|
173 |
|
174 TBool CAknNoMatchesIndicatorInlineTextSource::FormatOfNextCharacterIsUnknownInlineFepTextStyle( TInt aNextPos) const |
|
175 { |
|
176 TBool effectIsUnknownInlineFepText(EFalse); |
|
177 |
|
178 TPtrC textPtr; |
|
179 |
|
180 // Use separate, new format on the stack to hold the info on the next character |
|
181 TTmCharFormat format; |
|
182 |
|
183 // Get characters immediately following current chunk. |
|
184 iTextLayout.TagmaTextLayout().Source()->GetText( aNextPos, textPtr, format ); |
|
185 |
|
186 // Must be at least one character |
|
187 if ( textPtr.Length() >= 1 ) |
|
188 // Check if it is the correct effect. |
|
189 if (format.iEffects & TTmCharFormat::ENoMatchesIndicator ) |
|
190 effectIsUnknownInlineFepText = ETrue; |
|
191 |
|
192 return effectIsUnknownInlineFepText; |
|
193 } |
|
194 |
|
195 // End of File |