|
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 |
|
21 #include "AknInlineText.h" |
|
22 |
|
23 // LOCAL FUNCTIONS |
|
24 |
|
25 GLDEF_C void Panic(TAknInlineTextFormattingPanic aPanic) |
|
26 { |
|
27 User::Panic(KAknInlineTextFormatting, aPanic); |
|
28 } |
|
29 |
|
30 // MODULE TEMPLATES |
|
31 |
|
32 // MODULE DATA STRUCTURES |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 //////////////////////////////////////////////////////////////////////////////// |
|
37 // |
|
38 // CAknPositionedInlineText |
|
39 // |
|
40 //////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // 2 stage constructor |
|
44 // ----------------------------------------------------------------------------- |
|
45 |
|
46 CAknPositionedInlineText* CAknPositionedInlineText::NewL( const TTmDocPos& aPosition, const TDesC& aInlineText ) |
|
47 { |
|
48 CAknPositionedInlineText* self = |
|
49 new (ELeave) CAknPositionedInlineText( aPosition ); // Only partially constructed at this point |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL( aInlineText ); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 CAknPositionedInlineText::~CAknPositionedInlineText() |
|
57 { |
|
58 delete iText; |
|
59 } |
|
60 |
|
61 const TTmDocPos& CAknPositionedInlineText::DocPos() const |
|
62 { |
|
63 return iDocPos; |
|
64 } |
|
65 |
|
66 const TDesC& CAknPositionedInlineText::InlineText() const |
|
67 { |
|
68 return *iText; |
|
69 } |
|
70 |
|
71 CAknPositionedInlineText::CAknPositionedInlineText( const TTmDocPos& aPosition ) |
|
72 : iDocPos(aPosition) |
|
73 { |
|
74 } |
|
75 |
|
76 void CAknPositionedInlineText::ConstructL( const TDesC& aInlineText ) |
|
77 { |
|
78 iText = aInlineText.AllocL(); |
|
79 } |
|
80 //////////////////////////////////////////////////////////////////////////////// |
|
81 // |
|
82 // CAknInlineTextStore |
|
83 // |
|
84 //////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
86 const TInt KAknInlineTextStoreGranularity(2); |
|
87 |
|
88 CAknInlineTextStore* CAknInlineTextStore::NewL() |
|
89 { |
|
90 return new (ELeave) CAknInlineTextStore(); |
|
91 } |
|
92 |
|
93 CAknInlineTextStore::~CAknInlineTextStore() |
|
94 { |
|
95 ResetAndDestroy(); |
|
96 } |
|
97 |
|
98 void CAknInlineTextStore::Clear() |
|
99 { |
|
100 ResetAndDestroy(); |
|
101 } |
|
102 |
|
103 void CAknInlineTextStore::ClearRange( const TTmDocPos& aStart, const TTmDocPos& aEnd ) |
|
104 { |
|
105 TInt nToDelete(0); |
|
106 TInt firstToDelete(0); |
|
107 for (TInt index = Count() - 1; index >=0 ; --index) |
|
108 { |
|
109 CAknPositionedInlineText* inlineText = At(index); |
|
110 const TTmDocPos& docPos = inlineText->DocPos(); |
|
111 if ( aStart <= docPos && docPos <= aEnd ) |
|
112 { |
|
113 delete ( inlineText ); |
|
114 firstToDelete = index; // running lowest index to delete |
|
115 nToDelete++; |
|
116 } |
|
117 } |
|
118 // Perform deletions from array in one go as this is an expensive operation |
|
119 if ( nToDelete > 0 ) |
|
120 Delete( firstToDelete, nToDelete ); |
|
121 } |
|
122 |
|
123 void CAknInlineTextStore::InsertInlineTextL( CAknPositionedInlineText* aInlineText ) |
|
124 { |
|
125 TInt insertPosition(0); |
|
126 for (TInt ii = Count()-1; ii >= 0; --ii) |
|
127 { |
|
128 if ( At(ii)->DocPos() <= aInlineText->DocPos() ) |
|
129 { |
|
130 insertPosition = ii+1; |
|
131 break; |
|
132 } |
|
133 } |
|
134 |
|
135 InsertL( insertPosition, aInlineText ); |
|
136 } |
|
137 |
|
138 const TTmDocPos* CAknInlineTextStore::NextInlineTextDocPos( const TTmDocPos& aDocPos ) const |
|
139 { |
|
140 const TTmDocPos* retPtr = NULL; |
|
141 TInt index = NextIndexStartingAtDocPos( aDocPos ); |
|
142 if ( index >=0 ) |
|
143 retPtr = &(At( index )->DocPos()); |
|
144 return retPtr; |
|
145 } |
|
146 |
|
147 TInt CAknInlineTextStore::NextIndexStartingAtDocPos( const TTmDocPos& aDocPos ) const |
|
148 { |
|
149 |
|
150 TInt count = Count(); |
|
151 if ( count == 0 ) |
|
152 return -1; |
|
153 |
|
154 if ( At(count-1)->DocPos() < aDocPos ) // even biggest is at lower docpos |
|
155 return -1; |
|
156 |
|
157 TInt index; |
|
158 for (index = 0; index < count ; ++index) |
|
159 { |
|
160 if ( At(index)->DocPos() >= aDocPos ) |
|
161 { |
|
162 break; |
|
163 } |
|
164 } |
|
165 |
|
166 __ASSERT_DEBUG( index < count , Panic( EAknInlineTextFormattingStoreCorrupted) ); |
|
167 |
|
168 return index; |
|
169 } |
|
170 |
|
171 TInt CAknInlineTextStore::IndexFromDocPos( const TTmDocPos& aDocPos ) const |
|
172 { |
|
173 TInt matchedIndex = -1; |
|
174 TInt indexFound = NextIndexStartingAtDocPos( aDocPos ); |
|
175 if (indexFound != -1 && At(indexFound)->DocPos() == aDocPos ) |
|
176 matchedIndex = indexFound; |
|
177 return matchedIndex; |
|
178 } |
|
179 |
|
180 CAknInlineTextStore::CAknInlineTextStore() : CArrayPtrFlat<CAknPositionedInlineText>( KAknInlineTextStoreGranularity ) |
|
181 {} |
|
182 |
|
183 |
|
184 //////////////////////////////////////////////////////////////////////////////// |
|
185 // |
|
186 // CAknInlineTextSource |
|
187 // |
|
188 //////////////////////////////////////////////////////////////////////////////// |
|
189 |
|
190 CAknInlineTextSource::CAknInlineTextSource() |
|
191 {} |
|
192 |
|
193 void CAknInlineTextSource::ConstructL() |
|
194 { |
|
195 iInlineTextStore = CAknInlineTextStore::NewL(); |
|
196 } |
|
197 |
|
198 CAknInlineTextSource::~CAknInlineTextSource() |
|
199 { |
|
200 delete iInlineTextStore; |
|
201 } |
|
202 |
|
203 TInt CAknInlineTextSource::GetNextInlineTextPosition( |
|
204 const TTmDocPos& aFrom, |
|
205 TInt aMaxLength, |
|
206 TTmDocPos& aNext) |
|
207 { |
|
208 |
|
209 TInt errReturn = KErrNotFound; // Default is that there is nothing found |
|
210 |
|
211 const TTmDocPos* nextPos = iInlineTextStore->NextInlineTextDocPos( aFrom ); |
|
212 // This returns NULL if nothing found |
|
213 if ( nextPos ) |
|
214 { |
|
215 |
|
216 if ( // pos must be strictly less than aFrom + aMaxLength, but may be 1 further if trailing |
|
217 (nextPos->iPos < (aFrom.iPos + aMaxLength) ) |
|
218 || |
|
219 (!nextPos->iLeadingEdge && (nextPos->iPos <= (aFrom.iPos + aMaxLength)) ) |
|
220 ) |
|
221 { |
|
222 aNext = *nextPos; // Copies the structure |
|
223 errReturn = KErrNone; // Report valid data |
|
224 } |
|
225 } |
|
226 |
|
227 return errReturn; |
|
228 } |
|
229 |
|
230 TPtrC CAknInlineTextSource::GetInlineText(const TTmDocPos& aPos) |
|
231 { |
|
232 TInt index = iInlineTextStore->IndexFromDocPos( aPos ); |
|
233 if ( index >= 0 ) |
|
234 return iInlineTextStore->At( index )->InlineText(); |
|
235 else |
|
236 { |
|
237 __ASSERT_DEBUG( EFalse, Panic(EAknInlineTextFormattingBadInlineTextFetch) ); |
|
238 return KNullDesC(); |
|
239 } |
|
240 } |
|
241 |
|
242 TBool CAknInlineTextSource::HasInlineTextAt(const TTmDocPos& aPos, TPtrC& aPtrFound) const |
|
243 { |
|
244 TBool retVal( EFalse ); |
|
245 TInt index = iInlineTextStore->IndexFromDocPos( aPos ); |
|
246 if ( index != -1 ) |
|
247 { |
|
248 retVal = ETrue; |
|
249 aPtrFound.Set(iInlineTextStore->At( index )->InlineText()) ; |
|
250 } |
|
251 return retVal; |
|
252 } |
|
253 |
|
254 CAknInlineTextStore* CAknInlineTextSource::InlineTextStore() const |
|
255 { |
|
256 return iInlineTextStore; |
|
257 } |
|
258 |
|
259 /** |
|
260 * Empty implementation as all "when to format policy" is determined by sub-classes. However, |
|
261 * this class implements so that sub-classes only have to implement what they need. |
|
262 */ |
|
263 void CAknInlineTextSource::CheckFormattingL(const TTmDocPos& /*aFrom*/, const TTmDocPos& /*aTo*/ ) |
|
264 {} |
|
265 |
|
266 /** |
|
267 * Empty implementation as all upon-edit policy is determined by sub-classes. However, |
|
268 * this class implements so that sub-classes only have to implement what they need. |
|
269 */ |
|
270 void CAknInlineTextSource::EditObserver( TInt /*aStart*/, TInt /*aExtent*/ ) |
|
271 {} |
|
272 |
|
273 |
|
274 |
|
275 // End of File |