|
1 /* |
|
2 * Copyright (c) 2002 - 2008 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 #ifndef AKNPHEDMODEL_H |
|
19 #define AKNPHEDMODEL_H |
|
20 |
|
21 #include <e32base.h> |
|
22 |
|
23 #include "AknPhedDataObserver.h" |
|
24 #include "NumberGrouping.h" |
|
25 |
|
26 |
|
27 class CAknPhedBuffers; |
|
28 class CAknPhedModel; |
|
29 class TAknPhedDataMirror; |
|
30 |
|
31 |
|
32 NONSHARABLE_CLASS(CAknPhedScratchBuffer) : public CBase |
|
33 { |
|
34 public: |
|
35 CAknPhedScratchBuffer(); |
|
36 ~CAknPhedScratchBuffer(); |
|
37 void ConstructL(TInt aMaxLen); |
|
38 |
|
39 // Writable access to the scratch area |
|
40 inline TPtr ScratchBuffer() const; |
|
41 protected: |
|
42 HBufC* iBuf; |
|
43 TPtr iPtr; |
|
44 }; |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 // |
|
50 // CAknPhedModel |
|
51 // |
|
52 // The editor model combines a two way text buffer with cursor and selection logic |
|
53 // |
|
54 NONSHARABLE_CLASS(CAknPhedModel) : public CBase |
|
55 { |
|
56 public: |
|
57 // construction & destruction |
|
58 static CAknPhedModel* NewL(TInt aMaxLen); |
|
59 ~CAknPhedModel(); |
|
60 |
|
61 // Observer interface |
|
62 inline MPhedDataObserver* Observer(); |
|
63 inline void SetObserver(MPhedDataObserver* aObserver); |
|
64 |
|
65 // Text access |
|
66 inline TInt Length() const; |
|
67 inline TInt MaxDisplayLength() const; |
|
68 inline TPtrC Text(TInt aFrom=0) const; |
|
69 inline TPtrC Text(TInt aFrom, TInt aTo) const; |
|
70 inline TPtrC ReverseText(TInt aFrom=0) const; |
|
71 inline TPtrC ReverseText(TInt aFrom, TInt aTo) const; |
|
72 |
|
73 inline TPtrC UnFormattedText(TInt aFrom=0) const; |
|
74 inline TPtrC UnFormattedText(TInt aFrom, TInt aTo) const; |
|
75 |
|
76 inline TBool IsSpace(TInt aPos) const; |
|
77 TInt Spaces(TInt aTo, TInt aFrom) const; |
|
78 TInt Spaces( TInt aToPos ) const; |
|
79 inline TPtr TranslationBuffer() const; |
|
80 |
|
81 // Text setting |
|
82 void SetText(const TDesC& aText); |
|
83 |
|
84 enum TDirection{EDown, EUp}; |
|
85 |
|
86 // Cursor/selection relative text manipulation |
|
87 void Insert(TText aChar); |
|
88 void DeleteLeft(); |
|
89 void DeleteLeft(TInt aIndex, TInt aCount=1); |
|
90 void Cut(TDes& aCutText); |
|
91 void Copy(TDes& aCopiedText) const; |
|
92 void Paste(const TDesC& aText); |
|
93 |
|
94 // Cursor manipulation |
|
95 inline TInt CursorPosition() const; |
|
96 // The following three functions clear any selection |
|
97 // Now return a TInt indicating the new cursor position |
|
98 TInt SetRealCursorPosition(TInt aCursorPos); |
|
99 TInt SetCompensatedCursorPosition(TInt aCursorPos); |
|
100 TInt CursorLeft(); |
|
101 TInt CursorRight(); |
|
102 |
|
103 // Selection manipulation |
|
104 TPtrC Selection() const; |
|
105 inline TBool SelectionExists() const; |
|
106 inline TInt AnchorPosition() const; |
|
107 TInt SetAnchorPosition(TInt aAnchorPos); |
|
108 inline void SelectLeft(); |
|
109 inline void SelectRight(); |
|
110 inline TInt LeftMark() const; |
|
111 inline TInt RightMark() const; |
|
112 inline TInt SelectionWidth() const; |
|
113 |
|
114 // testing support |
|
115 inline TBool InvariantOk() const; |
|
116 inline void ForceLanguage(TLanguage aLanguage); |
|
117 TInt Language() const; |
|
118 TInt Uncompensate( TInt aCompensatedPosition ) const; |
|
119 friend class TAknPhedDataMirror; |
|
120 |
|
121 private: |
|
122 void ConstructL(TInt aMaxLen); |
|
123 void Insert(const TDesC& aText); |
|
124 TBool ClearAnySelection(); |
|
125 void SelectMove(TInt aInc); |
|
126 TBool CursorPositionIsSpace(); |
|
127 TInt Compensate(TInt aRealPosition) const; |
|
128 |
|
129 void StartEvent(); |
|
130 void ReportEvent(const MPhedDataObserver::TAknPhedDataEvent& aEvent); |
|
131 |
|
132 private: |
|
133 TDirection iCursorDirection; |
|
134 CAknPhedScratchBuffer* iBuf; // owned |
|
135 CPNGNumberGrouping* iNumberGroupingBuffer; |
|
136 TInt iRealLength; |
|
137 |
|
138 TInt iRealCursor; |
|
139 TInt iRealAnchor; |
|
140 TPtrC iSelection; |
|
141 |
|
142 TInt iCount; |
|
143 |
|
144 MPhedDataObserver* iObserver; |
|
145 MPhedDataObserver::TAknPhedDataEvent iEvent; |
|
146 TInt iEventDepth; |
|
147 }; |
|
148 |
|
149 |
|
150 // |
|
151 // TAknPhedDataMirror |
|
152 // |
|
153 // CAknPhedModel position indexing is from the left hand side. This class reverses |
|
154 // all the positioning functions so that they index from the right hand side. |
|
155 // |
|
156 NONSHARABLE_CLASS(TAknPhedDataMirror) : public MPhedDataObserver |
|
157 { |
|
158 public: |
|
159 inline TAknPhedDataMirror(); |
|
160 inline void SetPhedModel(CAknPhedModel* aPhed); |
|
161 |
|
162 // Position mirror+ iBuf 0x13c42088 |
|
163 |
|
164 inline TInt Mirror(TInt aPos) const; |
|
165 inline TInt Compensate(TInt aMirroredPosition, TInt aRealPosition) const; |
|
166 |
|
167 // Text access |
|
168 inline TPtrC Text(TInt aFrom=0) const; |
|
169 inline TPtrC Text(TInt aFrom, TInt aTo) const; |
|
170 inline TPtrC ReverseText(TInt aFrom=0) const; |
|
171 inline TPtrC ReverseText(TInt aFrom, TInt aTo) const; |
|
172 |
|
173 // Observer interface |
|
174 inline MPhedDataObserver* Observer(); |
|
175 inline void SetObserver(MPhedDataObserver* aObserver); |
|
176 |
|
177 // Cursor manipulation |
|
178 inline TInt CursorPosition() const; |
|
179 inline TInt SetCompensatedCursorPosition(TInt aCursorPos); |
|
180 inline TInt SetRealCursorPosition(TInt aCursorPos); |
|
181 |
|
182 // Selection manipulation |
|
183 inline TInt AnchorPosition() const; |
|
184 inline TInt SetAnchorPosition(TInt aAnchorPos); |
|
185 inline TInt LeftMark() const; |
|
186 inline TInt RightMark() const; |
|
187 |
|
188 void HandlePhedDataEvent(const TAknPhedDataEvent& aEvent, |
|
189 CAknPhedModel* aPhedData); |
|
190 |
|
191 TInt Compensate(TInt aMirrorPosition) const; |
|
192 |
|
193 private: |
|
194 CAknPhedModel* iPhed; |
|
195 MPhedDataObserver* iObserver; |
|
196 }; |
|
197 |
|
198 inline TPtr CAknPhedScratchBuffer::ScratchBuffer() const |
|
199 { return iPtr; } |
|
200 // MPhedDataObserver inlines |
|
201 inline MPhedDataObserver::TAknPhedDataEvent::TAknPhedDataEvent() |
|
202 : iType(0), iStart(0), iEnd(0) |
|
203 {} |
|
204 |
|
205 inline MPhedDataObserver::TAknPhedDataEvent::TAknPhedDataEvent(TInt aType) |
|
206 : iType(aType), iStart(0), iEnd(0) |
|
207 {} |
|
208 |
|
209 inline MPhedDataObserver::TAknPhedDataEvent::TAknPhedDataEvent( TInt aType, |
|
210 TInt aStart, |
|
211 TInt aEnd ) |
|
212 : iType(aType), iStart(aStart), iEnd(aEnd) |
|
213 {} |
|
214 |
|
215 inline void MPhedDataObserver::TAknPhedDataEvent::Reset() |
|
216 { iType = iStart = iEnd = 0; } |
|
217 |
|
218 inline TBool MPhedDataObserver::TAknPhedDataEvent::TextChanged() const |
|
219 { return iType & EText; } |
|
220 |
|
221 inline TBool MPhedDataObserver::TAknPhedDataEvent::CursorChanged() const |
|
222 { return iType & ECursor; } |
|
223 |
|
224 inline TBool MPhedDataObserver::TAknPhedDataEvent::SelectionChanged() const |
|
225 { return iType & ESelection; } |
|
226 |
|
227 inline void MPhedDataObserver::TAknPhedDataEvent::TextChangeRange( TInt& aStart, |
|
228 TInt& aEnd ) const |
|
229 { aStart = iStart; aEnd = iEnd; } |
|
230 |
|
231 inline TInt MPhedDataObserver::TAknPhedDataEvent::Type() const |
|
232 { return iType; } |
|
233 |
|
234 |
|
235 // CAknPhedModel inlines |
|
236 inline MPhedDataObserver* CAknPhedModel::Observer() |
|
237 { return iObserver; } |
|
238 |
|
239 inline void CAknPhedModel::SetObserver(MPhedDataObserver* aObserver) |
|
240 { iObserver = aObserver; } |
|
241 |
|
242 inline TInt CAknPhedModel::Length() const |
|
243 { return iNumberGroupingBuffer->Length();} |
|
244 |
|
245 inline TInt CAknPhedModel::MaxDisplayLength() const |
|
246 { return iNumberGroupingBuffer->MaxDisplayLength(); } |
|
247 |
|
248 inline TPtr CAknPhedModel::TranslationBuffer() const |
|
249 { return iBuf->ScratchBuffer(); } |
|
250 |
|
251 inline TInt CAknPhedModel::CursorPosition() const |
|
252 { return Compensate(iRealCursor); } |
|
253 |
|
254 inline TBool CAknPhedModel::SelectionExists() const |
|
255 { return CursorPosition() != AnchorPosition(); } |
|
256 |
|
257 inline TInt CAknPhedModel::AnchorPosition() const |
|
258 { return Compensate(iRealAnchor); } |
|
259 |
|
260 inline TBool CAknPhedModel::IsSpace(TInt aPos) const |
|
261 { return iNumberGroupingBuffer->IsSpace(aPos); } |
|
262 |
|
263 inline TInt CAknPhedModel::LeftMark() const |
|
264 { return (iRealAnchor < iRealCursor) |
|
265 ? iRealAnchor |
|
266 : iRealCursor; } |
|
267 |
|
268 inline TInt CAknPhedModel::RightMark() const |
|
269 { return (iRealAnchor > iRealCursor) |
|
270 ? iRealAnchor |
|
271 : iRealCursor; } |
|
272 |
|
273 inline TInt CAknPhedModel::SelectionWidth() const |
|
274 { return RightMark() - LeftMark(); } |
|
275 |
|
276 inline void CAknPhedModel::SelectLeft() |
|
277 { SelectMove(-1); } |
|
278 |
|
279 inline void CAknPhedModel::SelectRight() |
|
280 { SelectMove(+1); } |
|
281 |
|
282 inline TPtrC CAknPhedModel::Text(TInt aFrom) const |
|
283 { return Text(aFrom, iNumberGroupingBuffer->Length() - 1); } |
|
284 |
|
285 inline TPtrC CAknPhedModel::Text(TInt aFrom, TInt aTo) const |
|
286 { return iNumberGroupingBuffer->FormattedNumber(aFrom, aTo); } |
|
287 |
|
288 inline TPtrC CAknPhedModel::ReverseText(TInt aFrom) const |
|
289 { return ReverseText(aFrom, iNumberGroupingBuffer->Length() - 1); } |
|
290 |
|
291 inline TPtrC CAknPhedModel::ReverseText(TInt aFrom, TInt aTo) const |
|
292 { return iNumberGroupingBuffer->ReverseFormattedNumber(aFrom, aTo); } |
|
293 |
|
294 inline TPtrC CAknPhedModel::UnFormattedText(TInt aFrom) const |
|
295 { return iNumberGroupingBuffer->UnFormattedNumber(aFrom, iNumberGroupingBuffer->UnFormattedLength() - 1); } |
|
296 |
|
297 inline TPtrC CAknPhedModel::UnFormattedText(TInt aFrom, TInt aTo) const |
|
298 { return iNumberGroupingBuffer->UnFormattedNumber(aFrom, aTo); } |
|
299 |
|
300 inline TBool CAknPhedModel::InvariantOk() const |
|
301 { /*return |
|
302 0 <= iCompensatedCursor && iCompensatedCursor <= Length() && |
|
303 0 <= iCompensatedAnchor && iCompensatedAnchor <= Length() && |
|
304 iEventDepth == 0; */ |
|
305 return ETrue; } |
|
306 |
|
307 void CAknPhedModel::ForceLanguage(TLanguage aLanguage) |
|
308 { iNumberGroupingBuffer->iForceLanguage = aLanguage; } |
|
309 |
|
310 // TAknPhedDataMirror inlines |
|
311 inline TAknPhedDataMirror::TAknPhedDataMirror() : iPhed(0), iObserver(0) |
|
312 {} |
|
313 |
|
314 inline void TAknPhedDataMirror::SetPhedModel(CAknPhedModel* aPhed) |
|
315 { iPhed = aPhed; } |
|
316 |
|
317 inline TInt TAknPhedDataMirror::Mirror(TInt aPos) const |
|
318 { return iPhed->iNumberGroupingBuffer->Length() - aPos; } |
|
319 |
|
320 inline TPtrC TAknPhedDataMirror::Text(TInt aFrom) const |
|
321 { return iPhed->ReverseText(aFrom); } |
|
322 |
|
323 inline TPtrC TAknPhedDataMirror::Text(TInt aFrom, TInt aTo) const |
|
324 { return iPhed->ReverseText(aFrom, aTo); } |
|
325 |
|
326 inline TPtrC TAknPhedDataMirror::ReverseText(TInt aFrom) const |
|
327 { return iPhed->Text(aFrom); } |
|
328 |
|
329 inline MPhedDataObserver* TAknPhedDataMirror::Observer() |
|
330 { return iObserver; } |
|
331 |
|
332 inline void TAknPhedDataMirror::SetObserver(MPhedDataObserver* aObserver) |
|
333 { iObserver = aObserver; iPhed->SetObserver(this); } |
|
334 |
|
335 inline TInt TAknPhedDataMirror::CursorPosition() const |
|
336 { return Compensate(Mirror(iPhed->iRealCursor), iPhed->iRealCursor); } |
|
337 |
|
338 // This function is defective. It uses Mirror, |
|
339 // which does not work in real space see MRED-5GPJQQ |
|
340 inline TInt TAknPhedDataMirror::SetRealCursorPosition(TInt aCursorPos) |
|
341 { return iPhed->SetRealCursorPosition(Mirror(aCursorPos)); } |
|
342 |
|
343 inline TInt TAknPhedDataMirror::SetCompensatedCursorPosition(TInt aCursorPos) |
|
344 { return iPhed->SetCompensatedCursorPosition(Mirror(aCursorPos)); } |
|
345 |
|
346 inline TInt TAknPhedDataMirror::AnchorPosition() const |
|
347 { return Compensate(Mirror(iPhed->iRealAnchor), iPhed->iRealAnchor); } |
|
348 |
|
349 inline TInt TAknPhedDataMirror::SetAnchorPosition(TInt aAnchorPos) |
|
350 { return iPhed->SetAnchorPosition(Mirror(aAnchorPos)); } |
|
351 |
|
352 inline TInt TAknPhedDataMirror::LeftMark() const |
|
353 { return Compensate(Mirror(iPhed->LeftMark()), iPhed->LeftMark()); } |
|
354 |
|
355 inline TInt TAknPhedDataMirror::RightMark() const |
|
356 { return Compensate(Mirror(iPhed->RightMark()), iPhed->RightMark()); } |
|
357 |
|
358 inline TInt TAknPhedDataMirror::Compensate(TInt aMirrorPosition, TInt aRealPosistion) const |
|
359 { |
|
360 if ( iPhed->Language() ) |
|
361 { |
|
362 return aMirrorPosition - iPhed->Spaces(0, aRealPosistion); |
|
363 } |
|
364 else |
|
365 { |
|
366 return aMirrorPosition; |
|
367 } |
|
368 } |
|
369 |
|
370 #endif |
|
371 |