author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:06:50 +0300 | |
branch | RCL_3 |
changeset 71 | d5e927d5853b |
parent 66 | 2455ef1f5bbc |
child 83 | 26b2b12093af |
permissions | -rw-r--r-- |
66 | 1 |
/******************************************************************************* |
2 |
* Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. This program and the accompanying materials |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
5 |
* which accompanies this distribution, and is available at |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
7 |
* |
|
8 |
* Contributors: |
|
9 |
* Nokia Corporation - S60 implementation |
|
10 |
*******************************************************************************/ |
|
11 |
||
12 |
||
71
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
13 |
#include <eikcoctl.rsg> |
66 | 14 |
#include <AknUtils.h> |
15 |
#include <eikedwin.h> |
|
16 |
#include <AknNumEdwin.h> |
|
17 |
#include <eikfpne.h> |
|
18 |
#include "swttext.h" |
|
19 |
#include "swtcontrolhelper.h" |
|
20 |
#include "swtscrollbar.h" |
|
21 |
#include "swtedwin.h" |
|
22 |
||
23 |
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 |
#include <tagma_internal.h> |
|
25 |
#endif |
|
26 |
||
27 |
static const TText KDefaultSecretChar = '*'; |
|
28 |
||
29 |
#define KInputModesRequiringFeedbackWithSingleChar (EAknEditorTextInputMode | EAknEditorKatakanaInputMode | EAknEditorFullWidthTextInputMode | EAknEditorFullWidthKatakanaInputMode | EAknEditorHiraganaKanjiInputMode | EAknEditorHiraganaInputMode | EAknEditorHalfWidthTextInputMode) |
|
30 |
#define KInputModesRequiringFeedbackWithString (EAknEditorHiraganaInputMode | EAknEditorHiraganaKanjiInputMode) |
|
31 |
||
32 |
const TInt KPasswordCharTimeout = 700000; // 700 msecs |
|
33 |
||
34 |
||
35 |
// ======== MEMBER FUNCTIONS ======== |
|
36 |
||
37 |
||
38 |
// --------------------------------------------------------------------------- |
|
39 |
// CSwtText::CPasswordText::CPasswordText |
|
40 |
// --------------------------------------------------------------------------- |
|
41 |
// |
|
42 |
inline CSwtText::CPasswordText::CPasswordText( |
|
43 |
const CParaFormatLayer* aParaLayer, const CCharFormatLayer* aCharLayer, |
|
44 |
CEikEdwin* aEdwin, TBool aPswdEnable) |
|
45 |
: CGlobalText(aParaLayer, aCharLayer) |
|
46 |
, iEchoChar(0), iEditor(aEdwin), iClearCharPos(-1), iPswdEnable(aPswdEnable) |
|
47 |
{ |
|
48 |
} |
|
49 |
||
50 |
// --------------------------------------------------------------------------- |
|
51 |
// CSwtText::CPasswordText::~CPasswordText |
|
52 |
// --------------------------------------------------------------------------- |
|
53 |
// |
|
54 |
CSwtText::CPasswordText::~CPasswordText() |
|
55 |
{ |
|
56 |
delete iTimer; |
|
57 |
delete iClearText; |
|
58 |
} |
|
59 |
||
60 |
// --------------------------------------------------------------------------- |
|
61 |
// CSwtText::CPasswordText::ConstructL |
|
62 |
// --------------------------------------------------------------------------- |
|
63 |
// |
|
64 |
inline void CSwtText::CPasswordText::ConstructL() |
|
65 |
{ |
|
66 |
CGlobalText::ConstructL(ESegmentedStorage, EDefaultTextGranularity); |
|
67 |
||
68 |
iTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
69 |
iClearText = HBufC::NewL(CEditableText::EDefaultTextGranularity); |
|
70 |
} |
|
71 |
||
72 |
// --------------------------------------------------------------------------- |
|
73 |
// CSwtText::CPasswordText::NewL |
|
74 |
// --------------------------------------------------------------------------- |
|
75 |
// |
|
76 |
CSwtText::CPasswordText* CSwtText::CPasswordText::NewL( |
|
77 |
const CParaFormatLayer* aParaLayer, |
|
78 |
const CCharFormatLayer* aCharLayer, CEikEdwin* aEdwin, TBool aPswdEnable) |
|
79 |
{ |
|
80 |
CPasswordText* self = new(ELeave) CPasswordText( |
|
81 |
aParaLayer, aCharLayer, aEdwin, aPswdEnable); |
|
82 |
CleanupStack::PushL(self); |
|
83 |
self->ConstructL(); |
|
84 |
CleanupStack::Pop(self); |
|
85 |
return self; |
|
86 |
} |
|
87 |
||
88 |
||
89 |
// --------------------------------------------------------------------------- |
|
90 |
// CSwtText::CPasswordText::SaveClearTextL |
|
91 |
// We save our clear text. We reallocate if not enough memory. |
|
92 |
// --------------------------------------------------------------------------- |
|
93 |
// |
|
94 |
void CSwtText::CPasswordText::SaveClearTextL(TInt aPos, const TDesC& aBuf) |
|
95 |
{ |
|
96 |
ASSERT(iClearText); |
|
97 |
TPtr ptr(iClearText->Des()); |
|
98 |
||
99 |
TInt totalLength = ptr.Length() + aBuf.Length(); |
|
100 |
// |
|
101 |
if (totalLength > ptr.MaxLength()) |
|
102 |
{ |
|
103 |
iClearText = iClearText->ReAllocL(totalLength); |
|
104 |
ptr.Set(iClearText->Des()); |
|
105 |
} |
|
106 |
||
107 |
ptr.Insert(aPos,aBuf); |
|
108 |
} |
|
109 |
||
110 |
// --------------------------------------------------------------------------- |
|
111 |
// CSwtText::CPasswordText::Reset |
|
112 |
// --------------------------------------------------------------------------- |
|
113 |
// |
|
114 |
void CSwtText::CPasswordText::Reset() |
|
115 |
{ |
|
116 |
if (iPswdEnable) |
|
117 |
{ |
|
118 |
if (iTimer->IsActive()) |
|
119 |
{ //commit any previous character before deleting or else we |
|
120 |
// may crash in the timer callback when trying to replace |
|
121 |
// an uncommited but already deleted char |
|
122 |
TRAP_IGNORE(DoTimerCallbackL(EFalse)); |
|
123 |
} |
|
124 |
} |
|
125 |
// clear local (hidden) copy |
|
126 |
TPtr ptr = iClearText->Des(); |
|
127 |
ptr.SetLength(0); |
|
128 |
CGlobalText::Reset(); |
|
129 |
} |
|
130 |
||
131 |
// --------------------------------------------------------------------------- |
|
132 |
// CSwtText::CPasswordText::InsertL |
|
133 |
// Insert a single character. First we save the character in the clear text by |
|
134 |
// calling SaveClearTextL(). Then if the character is a paragraph delimiter |
|
135 |
// insert a space.Otherwise if we are in alpha mode insert the clear |
|
136 |
// character and start the timer. Otherwise insert the asterisks. |
|
137 |
// --------------------------------------------------------------------------- |
|
138 |
// |
|
139 |
void CSwtText::CPasswordText::InsertL(TInt aPos, const TChar& aChar) |
|
140 |
{ |
|
141 |
TBuf<1> buf; |
|
142 |
buf.Append(aChar); |
|
143 |
SaveClearTextL(aPos, buf); |
|
144 |
if (iPswdEnable) |
|
145 |
{ |
|
146 |
if (aChar == CEditableText::EParagraphDelimiter) |
|
147 |
{ |
|
148 |
CGlobalText::InsertL(aPos, ' '); |
|
149 |
} |
|
150 |
else if (iEditor->AknEditorCurrentInputMode() & |
|
151 |
KInputModesRequiringFeedbackWithSingleChar) |
|
152 |
{ |
|
153 |
if (iTimer->IsActive() && iClearCharPos != aPos) |
|
154 |
{ //commit any previous character in a different position |
|
155 |
DoTimerCallbackL(ETrue); |
|
156 |
} |
|
157 |
else |
|
158 |
{ //or restart the timer if the char is in the same |
|
159 |
//position (multi-tap looping) |
|
160 |
iTimer->Cancel(); |
|
161 |
} |
|
162 |
||
163 |
CGlobalText::InsertL(aPos, aChar); |
|
164 |
iClearCharPos = aPos; |
|
165 |
iTimer->Start(KPasswordCharTimeout, KPasswordCharTimeout, |
|
166 |
TCallBack(TimerCallback, this)); |
|
167 |
} |
|
168 |
else |
|
169 |
{ |
|
170 |
CGlobalText::InsertL(aPos, iEchoChar); |
|
171 |
} |
|
172 |
} |
|
173 |
else |
|
174 |
{ |
|
175 |
if (iEchoChar) |
|
176 |
{ |
|
177 |
CGlobalText::InsertL(aPos, iEchoChar); |
|
178 |
} |
|
179 |
else |
|
180 |
{ |
|
181 |
CGlobalText::InsertL(aPos, aChar); |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
} |
|
186 |
||
187 |
// --------------------------------------------------------------------------- |
|
188 |
// CSwtText::CPasswordText::InsertL |
|
189 |
// Insert one or more characters. If inserting only one character rely |
|
190 |
// on InsertL() accepting only one char. Otherwise, save the clear text by |
|
191 |
// calling SaveClearTextL(). Then for every character either insert an asterisk |
|
192 |
// or a space if the character is a space delimiter. Note: this method is |
|
193 |
// called at start-up so it makes no sense to show a temporary clear character. |
|
194 |
// --------------------------------------------------------------------------- |
|
195 |
// |
|
196 |
void CSwtText::CPasswordText::InsertL(TInt aPos,const TDesC& aBuf) |
|
197 |
{ |
|
198 |
if (iPswdEnable) |
|
199 |
{ |
|
200 |
||
201 |
if (aBuf.Length() == 1) |
|
202 |
{ |
|
203 |
CSwtText::CPasswordText::InsertL(aPos, aBuf[0]); |
|
204 |
} |
|
205 |
else if (aBuf.Length() > 1 && (iEditor->AknEditorCurrentInputMode() & |
|
206 |
KInputModesRequiringFeedbackWithString)) |
|
207 |
{ |
|
208 |
// When writing in kanji or hiragana input mode, the characters are |
|
209 |
// entered in sequences. Insert the sequence char by char so that |
|
210 |
// the user will see the last character temporarily for feedback. |
|
211 |
for (TInt i = 0; i < aBuf.Length(); i++) |
|
212 |
{ |
|
213 |
CSwtText::CPasswordText::InsertL(aPos + i, aBuf[i]); |
|
214 |
} |
|
215 |
} |
|
216 |
else |
|
217 |
{ |
|
218 |
SaveClearTextL(aPos, aBuf); |
|
219 |
||
220 |
for (TInt i = 0; i < aBuf.Length(); i++) |
|
221 |
{ |
|
222 |
if (aBuf[i] == CEditableText::EParagraphDelimiter) |
|
223 |
{ |
|
224 |
CGlobalText::InsertL(aPos + i, ' '); |
|
225 |
} |
|
226 |
else |
|
227 |
{ |
|
228 |
CGlobalText::InsertL(aPos + i, iEchoChar); |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
else |
|
234 |
{ |
|
235 |
if (iEchoChar) |
|
236 |
{ |
|
237 |
SaveClearTextL(aPos, aBuf); |
|
238 |
for (TInt i = 0; i < aBuf.Length(); i++) |
|
239 |
{ |
|
240 |
if (aBuf[i] == CEditableText::EParagraphDelimiter) |
|
241 |
{ |
|
242 |
CGlobalText::InsertL(aPos + i, ' '); |
|
243 |
} |
|
244 |
else |
|
245 |
{ |
|
246 |
CGlobalText::InsertL(aPos + i, iEchoChar); |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
else |
|
251 |
{ |
|
252 |
for (TInt i = 0; i < aBuf.Length(); i++) |
|
253 |
{ |
|
254 |
CSwtText::CPasswordText::InsertL(aPos + i, aBuf[i]); |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
} |
|
259 |
||
260 |
} |
|
261 |
||
262 |
// --------------------------------------------------------------------------- |
|
263 |
// CSwtText::CPasswordText::SetEchoCharL |
|
264 |
// Support Changin all characters to masked character when we set the |
|
265 |
// SetEchoCharater |
|
266 |
// --------------------------------------------------------------------------- |
|
267 |
// |
|
268 |
void CSwtText::CPasswordText::SetEchoCharL() |
|
269 |
{ |
|
270 |
TInt length = iClearText->Des().Length(); |
|
271 |
if (length > 0) |
|
272 |
{ |
|
273 |
CGlobalText::DeleteL(0,length); |
|
274 |
if (iEchoChar) |
|
275 |
{ |
|
276 |
for (int i = 0; i < length; i++) |
|
277 |
{ |
|
278 |
CGlobalText::InsertL(i, iEchoChar); |
|
279 |
} |
|
280 |
} |
|
281 |
else |
|
282 |
{ |
|
283 |
CGlobalText::InsertL(0 , iClearText->Des()); |
|
284 |
} |
|
285 |
iEditor->NotifyNewFormatL(); |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
// --------------------------------------------------------------------------- |
|
290 |
// CSwtText::CPasswordText::PasteFromStoreL |
|
291 |
// Support for pasting in the Text with EchoCharacter. The normal insertion |
|
292 |
// mechanism is not used in the paste operation, so it must be handled separately |
|
293 |
// here. This is an overriden method that stores the pasted chars to the local |
|
294 |
// store and puts masked chars (*) to the visible store (in super class). |
|
295 |
// --------------------------------------------------------------------------- |
|
296 |
// |
|
297 |
TInt CSwtText::CPasswordText::PasteFromStoreL(const CStreamStore& aStore, |
|
298 |
const CStreamDictionary& aDictionary, |
|
299 |
TInt aPos) |
|
300 |
{ |
|
301 |
// 1. Paste clipboard text (to visible text) |
|
302 |
TInt numCharsPasted = CGlobalText::PasteFromStoreL(aStore, aDictionary, aPos); |
|
303 |
// 2. Insert the pasted text to the local clear text store |
|
304 |
TPtr content(SwtControlHelper::GetClipboardTextContentLC()); |
|
305 |
TPtrC ptr = content.Ptr(); |
|
306 |
SaveClearTextL(aPos, ptr); |
|
307 |
||
308 |
if (iEchoChar) |
|
309 |
{ |
|
310 |
// 3. Mask the visible text |
|
311 |
for (int i = 0; i < numCharsPasted; i++) |
|
312 |
{ |
|
313 |
TPtrC charToProcess = Read(aPos+i, 1); |
|
314 |
TChar replaceChar = iEchoChar; |
|
315 |
if (charToProcess[0] == CEditableText::EParagraphDelimiter) |
|
316 |
{ |
|
317 |
replaceChar = ' '; |
|
318 |
} |
|
319 |
CGlobalText::DeleteL(aPos+i,1); |
|
320 |
CGlobalText::InsertL(aPos+i, replaceChar); |
|
321 |
} |
|
322 |
} |
|
323 |
if (content.Ptr()) |
|
324 |
{ |
|
325 |
CleanupStack::PopAndDestroy(); |
|
326 |
} |
|
327 |
return numCharsPasted; |
|
328 |
} |
|
329 |
||
330 |
// --------------------------------------------------------------------------- |
|
331 |
// CSwtText::CPasswordText::CopyToStoreL |
|
332 |
// Support for copying Text with EchoCharacter constraint. The normal mechanism |
|
333 |
// is not used in the copy operation, so it must be handled separately here. |
|
334 |
// This is an overriden method that stores the copied chars to the local store |
|
335 |
// and puts masked chars (*) to the visible store (in super class). |
|
336 |
// --------------------------------------------------------------------------- |
|
337 |
// |
|
338 |
void CSwtText::CPasswordText::CopyToStoreL(CStreamStore& aStore, |
|
339 |
CStreamDictionary& aDictionary, |
|
340 |
TInt aPos, |
|
341 |
TInt aLength) const |
|
342 |
{ |
|
343 |
if (!iEchoChar) |
|
344 |
{ |
|
345 |
// this allow to copy in single line text without |
|
346 |
// Echo Character set |
|
347 |
CGlobalText::CopyToStoreL(aStore, aDictionary, |
|
348 |
aPos, aLength); |
|
349 |
} |
|
350 |
else |
|
351 |
{ |
|
352 |
// here we should handle the situation that it shouldn't |
|
353 |
// delete already existing clipboard contents. |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
// --------------------------------------------------------------------------- |
|
358 |
// CSwtText::CPasswordText::Delete |
|
359 |
// Delete one or more chars, this makes sure our clear text stays |
|
360 |
// in sync. |
|
361 |
// --------------------------------------------------------------------------- |
|
362 |
// |
|
363 |
TBool CSwtText::CPasswordText::DeleteL(TInt aPos,TInt aLength) |
|
364 |
{ |
|
365 |
if (iPswdEnable) |
|
366 |
{ |
|
367 |
if (iTimer->IsActive()) |
|
368 |
{ //commit any previous character before deleting or else we |
|
369 |
// may crash in the timer callback when trying to replace |
|
370 |
// an uncommited but already deleted char |
|
371 |
DoTimerCallbackL(EFalse); |
|
372 |
} |
|
373 |
} |
|
374 |
TPtr ptr = iClearText->Des(); |
|
375 |
ptr.Delete(aPos, aLength); |
|
376 |
||
377 |
return CGlobalText::DeleteL(aPos, aLength); |
|
378 |
} |
|
379 |
||
380 |
// --------------------------------------------------------------------------- |
|
381 |
// CSwtText::CPasswordText::Extract |
|
382 |
// This method is called by edwin when returning text to the user via |
|
383 |
// a GetText() call. We make sure we return the clear text instead of the |
|
384 |
// masking used by edwin. |
|
385 |
// --------------------------------------------------------------------------- |
|
386 |
// |
|
387 |
void CSwtText::CPasswordText::Extract(TDes& aBuf,TInt aPos) const |
|
388 |
{ |
|
389 |
if (iPswdEnable || iEchoChar) |
|
390 |
{ |
|
391 |
aBuf.SetLength(0); |
|
392 |
aBuf.Append(iClearText->Mid(aPos)); |
|
393 |
} |
|
394 |
else |
|
395 |
{ |
|
396 |
CGlobalText::Extract(aBuf, aPos); |
|
397 |
} |
|
398 |
} |
|
399 |
||
400 |
// --------------------------------------------------------------------------- |
|
401 |
// CSwtText::CPasswordText::Extract |
|
402 |
// This method is called by edwin when returning text to the user via |
|
403 |
// a GetText() call. We make sure we return the clear text instead of the |
|
404 |
// masking used by edwin. |
|
405 |
// --------------------------------------------------------------------------- |
|
406 |
// |
|
407 |
void CSwtText::CPasswordText::Extract(TDes& aBuf, |
|
408 |
TInt aPos, |
|
409 |
TInt aLength) const |
|
410 |
{ |
|
411 |
if (iPswdEnable || iEchoChar) |
|
412 |
{ |
|
413 |
aBuf.SetLength(0); |
|
414 |
aBuf.Append(iClearText->Mid(aPos, aLength)); |
|
415 |
} |
|
416 |
else |
|
417 |
{ |
|
418 |
CGlobalText::Extract(aBuf, aPos, aLength); |
|
419 |
} |
|
420 |
} |
|
421 |
||
422 |
// --------------------------------------------------------------------------- |
|
423 |
// CSwtText::CPasswordText::TimerCallbackL |
|
424 |
// --------------------------------------------------------------------------- |
|
425 |
// |
|
426 |
TInt CSwtText::CPasswordText::TimerCallback(TAny* aThis) |
|
427 |
{ |
|
428 |
CPasswordText* self = STATIC_CAST(CPasswordText*, aThis); |
|
429 |
ASSERT(self); |
|
430 |
||
431 |
TRAPD(err, self->DoTimerCallbackL(ETrue)); |
|
432 |
return err; |
|
433 |
} |
|
434 |
||
435 |
// --------------------------------------------------------------------------- |
|
436 |
// CSwtText::CPasswordText::DoTimerCallbackL |
|
437 |
// It is time to remove the temporary clear character. Do a delete at |
|
438 |
// iClearCharPos and then insert an asterisk at this position. Then we need to |
|
439 |
// call something that signals the edwin to update its characters, |
|
440 |
// NotifyNewFormatL() seems to do the job. Note: this is only needed when inse- |
|
441 |
// rting a char from the special char table or when holding a key down so that |
|
442 |
// a number is inserted even if in alpha input mode. Otherwise you do not notice |
|
443 |
// the differece as edwin update its text anyway when commiting a fep transaction |
|
444 |
// after a timeout that seems just about longer than our timeout. |
|
445 |
// --------------------------------------------------------------------------- |
|
446 |
// |
|
447 |
void CSwtText::CPasswordText::DoTimerCallbackL(TBool aNotifyFormat) |
|
448 |
{ |
|
449 |
||
450 |
iTimer->Cancel(); |
|
451 |
||
452 |
ASSERT(iClearCharPos != -1 && (DocumentLength() > iClearCharPos)); |
|
453 |
// here checking iEchochar is for null character in iEchoChar that does mask |
|
454 |
// the characters so we dont need to insert or delete. |
|
455 |
if (iClearCharPos != -1 && (DocumentLength() > iClearCharPos) && iEchoChar) |
|
456 |
{ |
|
457 |
CGlobalText::DeleteL(iClearCharPos,1); |
|
458 |
CGlobalText::InsertL(iClearCharPos, iEchoChar); |
|
459 |
||
460 |
if (aNotifyFormat && iEditor->TextView()) |
|
461 |
{ |
|
462 |
iEditor->NotifyNewFormatL(); |
|
463 |
} |
|
464 |
iEditor->DrawDeferred(); |
|
465 |
} |
|
466 |
} |
|
467 |
||
468 |
// CSwtText::~CSwtText |
|
469 |
// --------------------------------------------------------------------------- |
|
470 |
// |
|
471 |
CSwtText::~CSwtText() |
|
472 |
{ |
|
473 |
//iiBufferToVerify.Close(); |
|
474 |
} |
|
475 |
||
476 |
// --------------------------------------------------------------------------- |
|
477 |
// CSwtText::ConstructL |
|
478 |
// --------------------------------------------------------------------------- |
|
479 |
// |
|
480 |
void CSwtText::ConstructL() |
|
481 |
{ |
|
482 |
CSwtTextBase::ConstructL(); |
|
483 |
TUint aknFlags = 0; |
|
484 |
// Compute edwin flags from our style |
|
485 |
TUint flags = CEikEdwin::ESegmentedStorage | CEikEdwin::ELineCursor |
|
486 |
| CEikEdwin::EInclusiveSizeFixed | CEikEdwin::ENoAutoSelection |
|
487 |
| CEikEdwin::EResizable | CEikEdwin::EWidthInPixels; |
|
488 |
if (!(iStyle & KSwtStyleWrap)) |
|
489 |
{ |
|
490 |
flags |= CEikEdwin::ENoWrap; |
|
491 |
} |
|
492 |
||
493 |
if (iStyle & KSwtStyleReadOnly) |
|
494 |
{ |
|
495 |
flags |= CEikEdwin::EReadOnly; |
|
496 |
} |
|
497 |
||
498 |
// Single/multi - line |
|
499 |
TInt lineCount; |
|
500 |
if (iStyle & KSwtStyleSingle) |
|
501 |
{ |
|
502 |
flags |= CEikEdwin::ENoLineOrParaBreaks | CEikEdwin::ENoWrap; |
|
503 |
lineCount = 1; |
|
504 |
} |
|
505 |
else |
|
506 |
{ |
|
507 |
lineCount = 0; |
|
508 |
} |
|
509 |
||
510 |
// Construct the editor |
|
511 |
CSwtEdwin* editor = new(ELeave) CSwtEdwin; |
|
512 |
SetEditor(editor); |
|
513 |
editor->ConstructL(flags, 0, ETextLimit, lineCount); |
|
514 |
editor->SetContainerWindowL(*this); |
|
515 |
||
516 |
if (iStyle & KSwtStyleSingle) |
|
517 |
{ |
|
518 |
CParaFormatLayer* paraLayer = iEikonEnv->SystemSingleLineParaFormatLayerL(); |
|
519 |
CCharFormatLayer* charLayer = iEikonEnv->SystemCharFormatLayerL(); |
|
520 |
CPasswordText* passwordText = CPasswordText::NewL( |
|
521 |
paraLayer, charLayer, editor, iStyle & KSwtStylePassword); |
|
522 |
delete editor->Text(); |
|
523 |
// Ownership of passwordText is transferred |
|
524 |
editor->SetDocumentContentL(*passwordText, CEikEdwin::EUseText); |
|
525 |
||
526 |
} |
|
527 |
editor->CreateTextViewL(); |
|
528 |
editor->SetDimmed(IsDimmed()); |
|
529 |
editor->AddEdwinObserverL(this); |
|
530 |
||
531 |
ActivateL(); |
|
532 |
||
533 |
// Password: default to echo char = '*' |
|
534 |
if (iStyle & KSwtStylePassword) |
|
535 |
{ |
|
536 |
ASSERT(iStyle & KSwtStyleSingle); |
|
537 |
static_cast < CPasswordText* >(Editor().Text())-> |
|
538 |
iEchoChar = KDefaultSecretChar; |
|
539 |
editor->SetAknEditorCase(EAknEditorLowerCase); |
|
540 |
editor->SetAknEditorCurrentCase(EAknEditorLowerCase); |
|
541 |
editor->EnableCcpuSupportL(EFalse); |
|
542 |
aknFlags |= EAknEditorFlagNoT9; |
|
543 |
// Based on MIDP constraints, checks if the text is a PASSWORD text |
|
544 |
TCoeInputCapabilities inputCapabilities = editor->InputCapabilities(); |
|
545 |
if (inputCapabilities != TCoeInputCapabilities::ENone) |
|
546 |
{ |
|
547 |
CSwtLafFacade::SetPasswordCapability(inputCapabilities); |
|
548 |
} |
|
549 |
} |
|
550 |
#ifdef RD_SCALABLE_UI_V2 |
|
551 |
aknFlags |= EAknEditorFlagDeliverVirtualKeyEventsToApplication; |
|
552 |
#endif // RD_SCALABLE_UI_V2 |
|
553 |
||
554 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
555 |
aknFlags |= EAknEditorFlagEnablePartialScreen; |
|
556 |
#endif |
|
557 |
||
558 |
editor->SetAknEditorFlags(aknFlags); |
|
559 |
||
560 |
// Scrollbars |
|
561 |
if (iStyle & (KSwtStyleHScroll | KSwtStyleVScroll)) |
|
562 |
{ |
|
563 |
editor->CreatePreAllocatedScrollBarFrameL(); |
|
564 |
||
565 |
CEikScrollBarFrame* sbFrame = editor->ScrollBarFrame(); |
|
566 |
#ifdef RD_SCALABLE_UI_V2 |
|
567 |
// WARNING!!! The expanded touch area does not move correctly togehter with the scrollbars! |
|
568 |
sbFrame->SetScrollBarFrameFlags(CEikScrollBarFrame::EDisableExpandedTouchArea); |
|
569 |
#endif // RD_SCALABLE_UI_V2 |
|
570 |
||
571 |
sbFrame->CreateDoubleSpanScrollBarsL(EFalse, EFalse); |
|
572 |
CEikScrollBarFrame::TScrollBarVisibility horizVis = |
|
573 |
/*( iStyle & KSwtStyleHScroll ) ? |
|
574 |
CEikScrollBarFrame::EOn : */ |
|
575 |
CEikScrollBarFrame::EOff; |
|
576 |
CEikScrollBarFrame::TScrollBarVisibility vertVis = |
|
577 |
(iStyle & KSwtStyleVScroll) ? |
|
578 |
CEikScrollBarFrame::EOn : |
|
579 |
CEikScrollBarFrame::EOff; |
|
580 |
sbFrame->SetScrollBarVisibilityL(horizVis, vertVis); |
|
581 |
} |
|
582 |
//To avoid editor cursor to blink |
|
583 |
//if the user doesnt set size and position |
|
584 |
editor->SetPosition(TPoint(0,0)); |
|
585 |
editor->SetSize(TSize(0,0)); |
|
586 |
SetAlignmentL(); |
|
587 |
RetrieveDefaultFontL(); |
|
588 |
FixPadding(); |
|
589 |
} |
|
590 |
||
591 |
// --------------------------------------------------------------------------- |
|
592 |
// CSwtText::NewL |
|
593 |
// --------------------------------------------------------------------------- |
|
594 |
// |
|
595 |
CSwtText* CSwtText::NewL(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
596 |
MSwtComposite& aParent, TInt aStyle) |
|
597 |
{ |
|
598 |
CSwtText* self = new(ELeave) CSwtText( |
|
599 |
aDisplay, aPeer, aParent, aStyle); |
|
600 |
CleanupStack::PushL(self); |
|
601 |
self->ConstructL(); |
|
602 |
self->InitControlBaseL(); |
|
603 |
CleanupStack::Pop(self); |
|
604 |
return self; |
|
605 |
} |
|
606 |
||
607 |
// --------------------------------------------------------------------------- |
|
608 |
// CSwtText::Draw |
|
609 |
// --------------------------------------------------------------------------- |
|
610 |
// |
|
611 |
void CSwtText::Draw(const TRect& /*aRect*/) const |
|
612 |
{ |
|
613 |
if (GetShell().UrgentPaintControl() == this) |
|
614 |
return; |
|
615 |
||
616 |
CEikEdwin& editor(Editor()); |
|
617 |
if (editor.TextView() == NULL) |
|
618 |
{ |
|
619 |
return; |
|
620 |
} |
|
621 |
||
622 |
// Update editor's visibility, otherwise text will be drawn |
|
623 |
// when performing clipboard operations on invisible control. |
|
624 |
const TBool visible = GetVisibleRecursively(); |
|
625 |
if (visible != editor.IsVisible()) |
|
626 |
{ |
|
627 |
editor.MakeVisible(visible); |
|
628 |
} |
|
629 |
||
630 |
// Update custom clipping, otherwise edwin will draw outside of |
|
631 |
// its parent control. |
|
632 |
TRect clipRect(ClipToVisibleRect(editor.TextView()->ViewRect())); |
|
633 |
if (clipRect != iLastViewVisibleRect) |
|
634 |
{ |
|
635 |
((CSwtEdwin*)&editor)->SetClippingRect(clipRect); |
|
636 |
iLastViewVisibleRect = clipRect; |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
// --------------------------------------------------------------------------- |
|
641 |
// CSwtText::ComputeAlignment |
|
642 |
// --------------------------------------------------------------------------- |
|
643 |
// |
|
644 |
CParaFormat::TAlignment CSwtText::ComputeAlignment() const |
|
645 |
{ |
|
646 |
CParaFormat::TAlignment result; |
|
647 |
const TInt alignment = iStyle & KSwtAlignmentMask; |
|
648 |
||
649 |
if (alignment == KSwtStyleCenter) |
|
650 |
{ |
|
651 |
result = CParaFormat::ECenterAlign; |
|
652 |
} |
|
653 |
else if (alignment == KSwtStyleTrail) |
|
654 |
{ |
|
655 |
if ((iStyle & KSwtOrientationMask) == KSwtStyleRightToLeft |
|
656 |
|| AknLayoutUtils::LayoutMirrored()) |
|
657 |
{ |
|
658 |
result = CParaFormat::ELeftAlign; |
|
659 |
} |
|
660 |
else |
|
661 |
{ |
|
662 |
result = CParaFormat::ERightAlign; |
|
663 |
} |
|
664 |
} |
|
665 |
else |
|
666 |
{ |
|
667 |
ASSERT(alignment == KSwtStyleLead); |
|
668 |
if ((iStyle & KSwtOrientationMask) == KSwtStyleRightToLeft |
|
669 |
|| AknLayoutUtils::LayoutMirrored()) |
|
670 |
{ |
|
671 |
result = CParaFormat::ERightAlign; |
|
672 |
} |
|
673 |
else |
|
674 |
{ |
|
675 |
result = CParaFormat::ELeftAlign; |
|
676 |
} |
|
677 |
} |
|
678 |
||
679 |
return result; |
|
680 |
} |
|
681 |
||
682 |
// --------------------------------------------------------------------------- |
|
683 |
// CSwtText::SetAlignmentL |
|
684 |
// --------------------------------------------------------------------------- |
|
685 |
// |
|
686 |
void CSwtText::SetAlignmentL() |
|
687 |
{ |
|
688 |
CParaFormat* paraFormat = CParaFormat::NewL(); |
|
689 |
CleanupStack::PushL(paraFormat); |
|
690 |
paraFormat->iHorizontalAlignment = ComputeAlignment(); |
|
691 |
TParaFormatMask paraMask; |
|
692 |
paraMask.SetAttrib(EAttAlignment); |
|
693 |
static_cast < CGlobalText* >(Editor().Text())-> |
|
694 |
ApplyParaFormatL(paraFormat, paraMask, 0, 0); |
|
695 |
CleanupStack::PopAndDestroy(paraFormat); |
|
696 |
} |
|
697 |
||
698 |
// --------------------------------------------------------------------------- |
|
699 |
// CSwtText::CropToFirstLine |
|
700 |
// --------------------------------------------------------------------------- |
|
701 |
// |
|
702 |
void CSwtText::CropToFirstLine(TDes& aText) |
|
703 |
{ |
|
704 |
const TInt length = aText.Length(); |
|
705 |
const TText* ptr = aText.Ptr(); |
|
706 |
TInt i = 0; |
|
707 |
||
708 |
// As of Unicode 4.0.1 there is only one character in each of the line |
|
709 |
// or paragraph separator categories. Therefore, if speed was an issue, |
|
710 |
// the below code could be replaced by a simpler and faster test against |
|
711 |
// those two characters. The current code, however, is more future proof. |
|
712 |
for (i = 0; i < length; i++) |
|
713 |
{ |
|
714 |
const TText ch = ptr[i]; |
|
715 |
||
716 |
// CR or LF |
|
717 |
if (ch == 0x0D || ch == 0x0A) |
|
718 |
{ |
|
719 |
break; |
|
720 |
} |
|
721 |
||
722 |
const TChar::TCategory category = TChar(ch).GetCategory(); |
|
723 |
if (category == TChar::EZlCategory |
|
724 |
|| category == TChar::EZpCategory) |
|
725 |
{ |
|
726 |
break; |
|
727 |
} |
|
728 |
} |
|
729 |
||
730 |
aText.SetLength(i); |
|
731 |
} |
|
732 |
||
733 |
||
734 |
// --------------------------------------------------------------------------- |
|
735 |
// CSwtText::ConvertToUnicodeBreaks |
|
736 |
// --------------------------------------------------------------------------- |
|
737 |
// |
|
738 |
void CSwtText::ConvertToUnicodeBreaks(TDes& aText) |
|
739 |
{ |
|
740 |
const TText KCr = 0x0D; // CR |
|
741 |
const TText KLf = 0x0A; // LF |
|
742 |
||
743 |
const TInt length = aText.Length(); |
|
744 |
TText* ptr = const_cast < TText* >(aText.Ptr()); |
|
745 |
||
746 |
// First loop: just scans for CR & LF and stops at the first occurrence. |
|
747 |
// This loop is faster than the second one. |
|
748 |
TInt inputIndex = 0; |
|
749 |
for (; inputIndex < length; ++ inputIndex) |
|
750 |
{ |
|
751 |
if (ptr[inputIndex] == KCr || ptr[inputIndex] == KLf) |
|
752 |
{ |
|
753 |
break; |
|
754 |
} |
|
755 |
} |
|
756 |
||
757 |
// Second loop: starts at the first CR or LF and does the actual replacement. |
|
758 |
// It will only be triggered if the first loop didn't reach the end. |
|
759 |
TText prevChar = 0; |
|
760 |
TInt outputIndex = inputIndex; |
|
761 |
for (; inputIndex < length; ++ inputIndex) |
|
762 |
{ |
|
763 |
TText ch = ptr[inputIndex]; |
|
764 |
if (ch != KCr && ch != KLf) |
|
765 |
{ |
|
766 |
ptr[outputIndex ++ ] = ch; |
|
767 |
} |
|
768 |
else |
|
769 |
{ |
|
770 |
// Don't replace LF if preceded by CR, just skip it. |
|
771 |
if (!(ch == KLf && prevChar == KCr)) |
|
772 |
{ |
|
773 |
ptr[outputIndex ++ ] = CEditableText::EParagraphDelimiter; |
|
774 |
} |
|
775 |
} |
|
776 |
||
777 |
prevChar = ch; |
|
778 |
} |
|
779 |
||
780 |
aText.SetLength(outputIndex); |
|
781 |
} |
|
782 |
||
783 |
// --------------------------------------------------------------------------- |
|
784 |
// CSwtText::ProcessLineBrakes |
|
785 |
// --------------------------------------------------------------------------- |
|
786 |
// |
|
787 |
void CSwtText::ProcessLineBrakes(TDes& aText) const |
|
788 |
{ |
|
789 |
if (iStyle & KSwtStyleSingle) |
|
790 |
{ |
|
791 |
CropToFirstLine(aText); |
|
792 |
} |
|
793 |
else |
|
794 |
{ |
|
795 |
ConvertToUnicodeBreaks(aText); |
|
796 |
} |
|
797 |
} |
|
798 |
||
799 |
// --------------------------------------------------------------------------- |
|
800 |
// CSwtText::PostVerifyEventL |
|
801 |
// --------------------------------------------------------------------------- |
|
802 |
// |
|
803 |
void CSwtText::PostVerifyEventL( |
|
804 |
TInt aStart, TInt aEnd, TDes& aText) |
|
805 |
{ |
|
806 |
iDisplay.PostVerifyEventL( |
|
807 |
*this, iPeer, aStart, aEnd, aText); |
|
808 |
} |
|
809 |
||
810 |
// --------------------------------------------------------------------------- |
|
811 |
// CSwtText::PostVerifyEventL |
|
812 |
// --------------------------------------------------------------------------- |
|
813 |
// |
|
814 |
void CSwtText::PostVerifyEventL(TInt aStart, TInt aEnd, TInt aChar) |
|
815 |
{ |
|
816 |
TBuf<1> charString; |
|
817 |
charString.Append(aChar); |
|
818 |
PostVerifyEventL(aStart, aEnd, charString); |
|
819 |
} |
|
820 |
||
821 |
// --------------------------------------------------------------------------- |
|
822 |
// CSwtText::SendCharacterL |
|
823 |
// --------------------------------------------------------------------------- |
|
824 |
// |
|
825 |
void CSwtText::SendCharacterL(TText aChar) |
|
826 |
{ |
|
827 |
TKeyEvent keyEvent; |
|
828 |
||
829 |
// For some reason TChar::IsPrint() returns false for line separator and |
|
830 |
// paragraph separator, so we have to emulate them. |
|
831 |
if (aChar == CEditableText::EParagraphDelimiter) |
|
832 |
{ |
|
833 |
keyEvent.iCode = EKeyEnter; |
|
834 |
keyEvent.iModifiers = 0; |
|
835 |
} |
|
836 |
else if (aChar == CEditableText::ELineBreak) |
|
837 |
{ |
|
838 |
keyEvent.iCode = EKeyEnter; |
|
839 |
keyEvent.iModifiers = EModifierShift; |
|
840 |
} |
|
841 |
else |
|
842 |
{ |
|
843 |
keyEvent.iCode = aChar; |
|
844 |
keyEvent.iModifiers = 0; |
|
845 |
} |
|
846 |
||
847 |
keyEvent.iScanCode = 0; |
|
848 |
keyEvent.iRepeats = 0; |
|
849 |
ForwardKeyEventL(keyEvent, EEventKey); |
|
850 |
iDisplay.PostModifyEventL(iPeer); |
|
851 |
} |
|
852 |
||
853 |
// --------------------------------------------------------------------------- |
|
854 |
// CSwtText::HandleResourceChange |
|
855 |
// From CSwtTextBase |
|
856 |
// --------------------------------------------------------------------------- |
|
857 |
// |
|
858 |
void CSwtText::HandleResourceChange(TInt aType) |
|
859 |
{ |
|
860 |
CSwtTextBase::HandleResourceChange(aType); |
|
861 |
||
862 |
if (aType == KEikDynamicLayoutVariantSwitch) |
|
863 |
{ |
|
864 |
TRAP_IGNORE( |
|
865 |
TInt topIndex = 0; |
|
866 |
if (iStyle & KSwtStyleMulti) |
|
867 |
{ |
|
868 |
// SetOrientationL method changes the TopIndex, we need to save it and set it again. |
|
869 |
topIndex = GetTopIndexL(); |
|
870 |
} |
|
871 |
// Update text orientation (left-to-right / right-to-left) |
|
872 |
SetOrientationL(iStyle & KSwtOrientationMask); |
|
873 |
if (iStyle & KSwtStyleMulti) |
|
874 |
{ |
|
875 |
SetTopIndexL(topIndex); |
|
876 |
} |
|
877 |
); |
|
878 |
} |
|
879 |
} |
|
880 |
||
881 |
// --------------------------------------------------------------------------- |
|
882 |
// CSwtText::SizeChanged |
|
883 |
// From CCoeControl |
|
884 |
// --------------------------------------------------------------------------- |
|
885 |
// |
|
886 |
void CSwtText::SizeChanged() |
|
887 |
{ |
|
888 |
CSwtTextBase::SizeChanged(); |
|
889 |
Editor().TextLayout()->RestrictScrollToTopsOfLines(EFalse); |
|
890 |
} |
|
891 |
||
892 |
// --------------------------------------------------------------------------- |
|
893 |
// CSwtText::OfferKeyEventL |
|
894 |
// From CCoeControl |
|
895 |
// --------------------------------------------------------------------------- |
|
896 |
// |
|
897 |
TKeyResponse CSwtText::OfferKeyEventL( |
|
898 |
const TKeyEvent& aKeyEvent, |
|
899 |
TEventCode aType) |
|
900 |
{ |
|
901 |
TBool traversalDoIt = ETrue; |
|
902 |
CEikEdwin& editor = Editor(); |
|
903 |
||
904 |
#ifdef RD_SCALABLE_UI_V2 |
|
905 |
// If focus gets changed by keys, iIgnorePointerDown is set to ETrue. We |
|
906 |
// don't want this since the next pointer event should be ignored only |
|
907 |
// when focus gets changed by tapping on the screen. |
|
908 |
iIgnorePointerDown = EFalse; |
|
909 |
#endif //RD_SCALABLE_UI_V2 |
|
910 |
||
911 |
switch (aKeyEvent.iCode) |
|
912 |
{ |
|
913 |
case EKeyEnter: |
|
914 |
traversalDoIt = iStyle & KSwtStyleSingle; |
|
915 |
break; |
|
916 |
||
917 |
case EKeyEscape: |
|
918 |
traversalDoIt = EFalse; |
|
919 |
break; |
|
920 |
||
921 |
case EKeyTab: |
|
922 |
traversalDoIt = (iStyle & KSwtStyleMulti) |
|
923 |
&& (aKeyEvent.iModifiers & ECtrlFuncShiftMask); |
|
924 |
break; |
|
925 |
||
926 |
case EKeyDownArrow: |
|
927 |
traversalDoIt = (!(aKeyEvent.iModifiers & EModifierShift)) |
|
928 |
&& (GetCaretLineNumber() == GetLineCount() - 1) |
|
929 |
&& (GetShell().FindTraversalTargetL( |
|
930 |
ESwtTraverseArrowNext, *this)); |
|
931 |
break; |
|
932 |
||
933 |
case EKeyUpArrow: |
|
934 |
traversalDoIt = (!(aKeyEvent.iModifiers & EModifierShift)) |
|
935 |
&& (GetCaretLineNumber() == 0) |
|
936 |
&& (GetShell().FindTraversalTargetL( |
|
937 |
ESwtTraverseArrowPrevious, *this)); |
|
938 |
break; |
|
939 |
||
940 |
case EKeyLeftArrow: |
|
941 |
case EKeyRightArrow: |
|
942 |
traversalDoIt = EFalse; |
|
943 |
break; |
|
944 |
||
945 |
default: |
|
946 |
// traversalDoIt remains ETrue |
|
947 |
break; |
|
948 |
} |
|
949 |
||
950 |
/* |
|
951 |
* This is a workaround for issue with traversing between Text if cursor |
|
952 |
* was on first position and LEFT key was pressed, the event was |
|
953 |
* consumed somewhere in AknFep. The same problem was in case RIGHT key |
|
954 |
* and end cursor position. In this case we don't recieve EEventKey, so |
|
955 |
* we must simulate it. |
|
956 |
*/ |
|
957 |
if (aType == EEventKeyDown) |
|
958 |
{ |
|
959 |
if (aKeyEvent.iScanCode == EStdKeyLeftArrow && |
|
960 |
editor.CursorPos() == 0) |
|
961 |
{ |
|
962 |
HandleKeyL(aKeyEvent, EEventKey, EFalse); |
|
963 |
} |
|
964 |
else if (aKeyEvent.iScanCode == EStdKeyRightArrow && |
|
965 |
editor.CursorPos() == editor.TextLength()) |
|
966 |
{ |
|
967 |
HandleKeyL(aKeyEvent, EEventKey, EFalse); |
|
968 |
} |
|
969 |
} |
|
970 |
||
971 |
return HandleKeyL(aKeyEvent, aType, traversalDoIt); |
|
972 |
} |
|
973 |
||
974 |
// --------------------------------------------------------------------------- |
|
975 |
// CSwtText::ProcessKeyEventL |
|
976 |
// From MSwtControl |
|
977 |
// --------------------------------------------------------------------------- |
|
978 |
// |
|
979 |
void CSwtText::ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
980 |
{ |
|
981 |
CEikEdwin& editor = Editor(); |
|
982 |
||
983 |
if (aType != EEventKey) |
|
984 |
{ |
|
985 |
return; |
|
986 |
} |
|
987 |
||
988 |
// Read - only: CEikEdwin displays a message and leaves. We want the message |
|
989 |
// but not the leaving, hence the trap. |
|
990 |
if (iStyle & KSwtStyleReadOnly) |
|
991 |
{ |
|
992 |
TRAP_IGNORE(ForwardKeyEventL(aKeyEvent, aType)); |
|
993 |
return; |
|
994 |
} |
|
995 |
||
996 |
// Single - line: enter not consumed, translated to default selection event |
|
997 |
if ((iStyle & KSwtStyleSingle) && aKeyEvent.iCode == EKeyEnter) |
|
998 |
{ |
|
999 |
iDisplay.PostDefaultSelectionEventL(iPeer); |
|
1000 |
return; |
|
1001 |
} |
|
1002 |
||
1003 |
const TInt modifiers = aKeyEvent.iModifiers & ECtrlFuncShiftMask; |
|
1004 |
const TCursorSelection selection(editor.Selection()); |
|
1005 |
const TInt selStart = selection.LowerPos(); |
|
1006 |
const TInt selEnd = selection.HigherPos(); |
|
1007 |
const TInt selLength = selEnd - selStart; |
|
1008 |
const TInt length = editor.TextLength(); |
|
1009 |
const TInt hotkey = HotKeyL(aKeyEvent); |
|
1010 |
||
1011 |
// Cut |
|
1012 |
if (hotkey == CEikEdwin::EHotKeyCut) |
|
1013 |
{ |
|
1014 |
TText echoChar = static_cast < CPasswordText* >( |
|
1015 |
Editor().Text())->iEchoChar; |
|
1016 |
if (!(iStyle & KSwtStylePassword) || !(echoChar)) |
|
1017 |
{ |
|
1018 |
Editor().ClipboardL(CEikEdwin::ECopy); |
|
1019 |
if (selLength != 0) |
|
1020 |
{ |
|
1021 |
TPtr text(NULL, 0, 0); |
|
1022 |
PostVerifyEventL(selStart, selEnd, text); |
|
1023 |
} |
|
1024 |
} |
|
1025 |
} |
|
1026 |
// Copy |
|
1027 |
else if (hotkey == CEikEdwin::EHotKeyCopy) |
|
1028 |
{ |
|
1029 |
TText echoChar = static_cast < CPasswordText* >( |
|
1030 |
Editor().Text())->iEchoChar; |
|
1031 |
if (!(iStyle & KSwtStylePassword) || !(echoChar)) |
|
1032 |
{ |
|
1033 |
editor.ClipboardL(CEikEdwin::ECopy); |
|
1034 |
} |
|
1035 |
} |
|
1036 |
// Paste |
|
1037 |
else if (hotkey == CEikEdwin::EHotKeyPaste) |
|
1038 |
{ |
|
1039 |
TPtr content(SwtControlHelper::GetClipboardTextContentLC()); |
|
1040 |
if (content.Length() == 0) |
|
1041 |
{ |
|
1042 |
// Nothing to paste: CEikEdwin displays a message and leaves. We want |
|
1043 |
// the message but not the leaving, hence the trap. |
|
1044 |
TRAP_IGNORE(ForwardKeyEventL(aKeyEvent, aType)); |
|
1045 |
} |
|
1046 |
else |
|
1047 |
{ |
|
1048 |
PostVerifyEventL(selStart, selEnd, content); |
|
1049 |
} |
|
1050 |
if (content.Ptr()) |
|
1051 |
{ |
|
1052 |
CleanupStack::PopAndDestroy(); |
|
1053 |
} |
|
1054 |
} |
|
1055 |
// Undo |
|
1056 |
else if (hotkey == CEikEdwin::EHotKeyUndo) |
|
1057 |
{ |
|
1058 |
// Do nothing |
|
1059 |
} |
|
1060 |
// Delete |
|
1061 |
else if (aKeyEvent.iCode == EKeyDelete && modifiers == 0) |
|
1062 |
{ |
|
1063 |
TPtr text(NULL, 0, 0); |
|
1064 |
if (selLength != 0) |
|
1065 |
{ |
|
1066 |
PostVerifyEventL(selStart, selEnd, text); |
|
1067 |
} |
|
1068 |
else if (selection.iCursorPos < length) |
|
1069 |
{ |
|
1070 |
PostVerifyEventL(selection.iCursorPos, selection.iCursorPos + 1, text); |
|
1071 |
} |
|
1072 |
} |
|
1073 |
// Backspace |
|
1074 |
else if (aKeyEvent.iCode == EKeyBackspace && modifiers == 0) |
|
1075 |
{ |
|
1076 |
TPtr text(NULL, 0, 0); |
|
1077 |
if (selLength != 0) |
|
1078 |
{ |
|
1079 |
PostVerifyEventL(selStart, selEnd, text); |
|
1080 |
} |
|
1081 |
else if (selection.iCursorPos > 0) |
|
1082 |
{ |
|
1083 |
PostVerifyEventL(selection.iCursorPos - 1, selection.iCursorPos, text); |
|
1084 |
} |
|
1085 |
} |
|
1086 |
// Enter: paragraph separator |
|
1087 |
else if (aKeyEvent.iCode == EKeyEnter && modifiers == 0) |
|
1088 |
{ |
|
1089 |
PostVerifyEventL(selStart, selEnd, CEditableText::ELineBreak); |
|
1090 |
} |
|
1091 |
// Shift + Enter: line separator |
|
1092 |
else if (aKeyEvent.iCode == EKeyEnter && (modifiers & EModifierShift)) |
|
1093 |
{ |
|
1094 |
PostVerifyEventL(selStart, selEnd, CEditableText::ELineBreak); |
|
1095 |
} |
|
1096 |
// Ctrl + Minus: non - breaking hyphen |
|
1097 |
else if (aKeyEvent.iCode == '-' && (modifiers & EModifierCtrl)) |
|
1098 |
{ |
|
1099 |
PostVerifyEventL(selStart, selEnd, CEditableText::ENonBreakingHyphen); |
|
1100 |
} |
|
1101 |
// Shift + Space: non - breaking space |
|
1102 |
else if (aKeyEvent.iCode == ' ' && (modifiers & EModifierShift)) |
|
1103 |
{ |
|
1104 |
PostVerifyEventL(selStart, selEnd, CEditableText::ENonBreakingSpace); |
|
1105 |
} |
|
1106 |
// Regular character |
|
1107 |
else if (aKeyEvent.iCode == EKeyTab || TChar(aKeyEvent.iCode).IsPrint()) |
|
1108 |
{ |
|
1109 |
PostVerifyEventL(selStart, selEnd, aKeyEvent.iCode); |
|
1110 |
} |
|
1111 |
// Other |
|
1112 |
else |
|
1113 |
{ |
|
1114 |
ForwardKeyEventL(aKeyEvent, aType); |
|
1115 |
} |
|
1116 |
} |
|
1117 |
||
1118 |
// --------------------------------------------------------------------------- |
|
1119 |
// CSwtText::Scrollable |
|
1120 |
// From MSwtText |
|
1121 |
// --------------------------------------------------------------------------- |
|
1122 |
// |
|
1123 |
MSwtScrollable* CSwtText::Scrollable() |
|
1124 |
{ |
|
1125 |
return this; |
|
1126 |
} |
|
1127 |
||
1128 |
// --------------------------------------------------------------------------- |
|
1129 |
// CSwtText::GetTextL |
|
1130 |
// From MSwtText |
|
1131 |
// --------------------------------------------------------------------------- |
|
1132 |
// |
|
1133 |
HBufC* CSwtText::GetTextL() const |
|
1134 |
{ |
|
1135 |
return Editor().GetTextInHBufL(); |
|
1136 |
} |
|
1137 |
||
1138 |
// --------------------------------------------------------------------------- |
|
1139 |
// CSwtText::GetTextRangeL |
|
1140 |
// From MSwtText |
|
1141 |
// --------------------------------------------------------------------------- |
|
1142 |
// |
|
1143 |
HBufC* CSwtText::GetTextRangeL(TInt aStart, TInt aEnd) const |
|
1144 |
{ |
|
1145 |
ASSERT(aStart <=aEnd); |
|
1146 |
||
1147 |
const TInt length = Editor().TextLength(); |
|
1148 |
if (length == 0) |
|
1149 |
{ |
|
1150 |
return NULL; |
|
1151 |
} |
|
1152 |
||
1153 |
TInt pos1 = Max(0, aStart); |
|
1154 |
TInt pos2 = Min(aEnd, length - 1); |
|
1155 |
TInt count = pos2 - pos1 + 1; |
|
1156 |
if (pos1 >= length || pos2 < 0 || count <= 0) |
|
1157 |
{ |
|
1158 |
return NULL; |
|
1159 |
} |
|
1160 |
||
1161 |
HBufC* buffer = HBufC::NewL(count); |
|
1162 |
TPtr des(buffer->Des()); |
|
1163 |
Editor().Text()->Extract(des, pos1, count); |
|
1164 |
return buffer; |
|
1165 |
} |
|
1166 |
||
1167 |
// --------------------------------------------------------------------------- |
|
1168 |
// CSwtText::SetTextL |
|
1169 |
// From MSwtText |
|
1170 |
// --------------------------------------------------------------------------- |
|
1171 |
// |
|
1172 |
TBool CSwtText::SetTextL(TDes& aText) |
|
1173 |
{ |
|
1174 |
ProcessLineBrakes(aText); |
|
1175 |
return CSwtTextBase::SetTextL(aText); |
|
1176 |
} |
|
1177 |
||
1178 |
// --------------------------------------------------------------------------- |
|
1179 |
// CSwtText::AppendL |
|
1180 |
// From MSwtText |
|
1181 |
// --------------------------------------------------------------------------- |
|
1182 |
// |
|
1183 |
TBool CSwtText::AppendL(TDes& aText) |
|
1184 |
{ |
|
1185 |
ProcessLineBrakes(aText); |
|
1186 |
return CSwtTextBase::AppendL(aText); |
|
1187 |
} |
|
1188 |
||
1189 |
// --------------------------------------------------------------------------- |
|
1190 |
// CSwtText::InsertL |
|
1191 |
// From MSwtText |
|
1192 |
// --------------------------------------------------------------------------- |
|
1193 |
// |
|
1194 |
TBool CSwtText::InsertL(TDes& aText) |
|
1195 |
{ |
|
1196 |
ProcessLineBrakes(aText); |
|
1197 |
return CSwtTextBase::InsertL(aText); |
|
1198 |
} |
|
1199 |
||
1200 |
// --------------------------------------------------------------------------- |
|
1201 |
// CSwtText::GetCharCount |
|
1202 |
// From MSwtText |
|
1203 |
// --------------------------------------------------------------------------- |
|
1204 |
// |
|
1205 |
TInt CSwtText::GetCharCount() const |
|
1206 |
{ |
|
1207 |
return Editor().TextLength(); |
|
1208 |
} |
|
1209 |
||
1210 |
// --------------------------------------------------------------------------- |
|
1211 |
// CSwtText::SetTextLimit |
|
1212 |
// From MSwtText |
|
1213 |
// --------------------------------------------------------------------------- |
|
1214 |
// |
|
1215 |
TBool CSwtText::SetTextLimitL(TInt aLimit) |
|
1216 |
{ |
|
1217 |
iTextLimit = aLimit; |
|
1218 |
return CSwtTextBase::SetLimitL(aLimit); |
|
1219 |
} |
|
1220 |
||
1221 |
// --------------------------------------------------------------------------- |
|
1222 |
// CSwtText::GetCaretLineNumber |
|
1223 |
// From MSwtText |
|
1224 |
// --------------------------------------------------------------------------- |
|
1225 |
// |
|
1226 |
TInt CSwtText::GetCaretLineNumber() const |
|
1227 |
{ |
|
1228 |
TTmLineInfo info; |
|
1229 |
TPoint origin(TPoint::EUninitialized); |
|
1230 |
TInt width; |
|
1231 |
TInt ascent; |
|
1232 |
TInt descent; |
|
1233 |
TTmDocPos curPos; |
|
1234 |
Editor().TextView()->GetCursorPos(curPos); |
|
1235 |
TTmDocPosSpec curPosSpec(curPos); |
|
1236 |
Editor().TextLayout()->TagmaTextLayout().GetCursor( |
|
1237 |
curPosSpec, ECursorVertical, info, origin, width, ascent, descent); |
|
1238 |
return info.iLineNumber; |
|
1239 |
} |
|
1240 |
||
1241 |
// --------------------------------------------------------------------------- |
|
1242 |
// CSwtText::GetCaretLocationL |
|
1243 |
// From MSwtText |
|
1244 |
// --------------------------------------------------------------------------- |
|
1245 |
// |
|
1246 |
TPoint CSwtText::GetCaretLocationL() const |
|
1247 |
{ |
|
1248 |
CTextView* textView = Editor().TextView(); |
|
1249 |
CTextLayout* layout = Editor().TextLayout(); |
|
1250 |
||
1251 |
TTmLineInfo info; |
|
1252 |
TPoint curLoc; |
|
1253 |
TInt width; |
|
1254 |
TInt ascent; |
|
1255 |
TInt descent; |
|
1256 |
TTmDocPos curPos; |
|
1257 |
textView->GetCursorPos(curPos); |
|
1258 |
TTmDocPosSpec curPosSpec(curPos); |
|
1259 |
layout->TagmaTextLayout().GetCursor( |
|
1260 |
curPosSpec, ECursorVertical, info, curLoc, width, ascent, descent); |
|
1261 |
TPoint result(TPoint::EUninitialized); |
|
1262 |
layout->GetOrigin(result); |
|
1263 |
result += curLoc; |
|
1264 |
result += textView->ViewRect().iTl; |
|
1265 |
result -= ClientRect().iTl; |
|
1266 |
result.iY += GetTopPixelL(); |
|
1267 |
return result; |
|
1268 |
} |
|
1269 |
||
1270 |
// --------------------------------------------------------------------------- |
|
1271 |
// CSwtText::GetCaretPosition |
|
1272 |
// From MSwtText |
|
1273 |
// --------------------------------------------------------------------------- |
|
1274 |
// |
|
1275 |
TInt CSwtText::GetCaretPosition() const |
|
1276 |
{ |
|
1277 |
return Editor().CursorPos(); |
|
1278 |
} |
|
1279 |
||
1280 |
// --------------------------------------------------------------------------- |
|
1281 |
// CSwtText::GetSelection |
|
1282 |
// From MSwtText |
|
1283 |
// --------------------------------------------------------------------------- |
|
1284 |
// |
|
1285 |
TPoint CSwtText::GetSelection() const |
|
1286 |
{ |
|
1287 |
const TCursorSelection selection(Editor().Selection()); |
|
1288 |
return TPoint(selection.LowerPos(), selection.HigherPos()); |
|
1289 |
} |
|
1290 |
||
1291 |
// --------------------------------------------------------------------------- |
|
1292 |
// CSwtText::GetSelectionTextL |
|
1293 |
// From MSwtText |
|
1294 |
// --------------------------------------------------------------------------- |
|
1295 |
// |
|
1296 |
HBufC* CSwtText::GetSelectionTextL() const |
|
1297 |
{ |
|
1298 |
const TCursorSelection selection(Editor().Selection()); |
|
1299 |
const TInt length = selection.Length(); |
|
1300 |
if (length == 0) |
|
1301 |
{ |
|
1302 |
return NULL; |
|
1303 |
} |
|
1304 |
||
1305 |
HBufC* buffer = HBufC::NewL(length); |
|
1306 |
TPtr des(buffer->Des()); |
|
1307 |
Editor().Text()->Extract(des, selection.LowerPos(), length); |
|
1308 |
return buffer; |
|
1309 |
} |
|
1310 |
||
1311 |
// --------------------------------------------------------------------------- |
|
1312 |
// CSwtText::SetSelectionL |
|
1313 |
// From MSwtText |
|
1314 |
// --------------------------------------------------------------------------- |
|
1315 |
// |
|
1316 |
void CSwtText::SetSelectionL(TInt aStart, TInt aEnd) |
|
1317 |
{ |
|
1318 |
const TInt length = Editor().TextLength(); |
|
1319 |
const TInt pos1 = Max(0, Min(aStart, length)); |
|
1320 |
const TInt pos2 = Max(0, Min(aEnd, length)); |
|
1321 |
const TInt cursor = Min(pos1, pos2); |
|
1322 |
const TInt anchor = Max(pos1, pos2); |
|
1323 |
Editor().SetSelectionL(cursor, anchor); |
|
1324 |
// This is neccessary, since CEikEdwin doesn't really set the selection |
|
1325 |
// until drawing occurs and clipboard operations can be |
|
1326 |
// broken in such a case |
|
1327 |
Editor().TextView()->SetSelectionL(TCursorSelection(cursor, anchor)); |
|
1328 |
} |
|
1329 |
||
1330 |
// --------------------------------------------------------------------------- |
|
1331 |
// CSwtText::ClearSelectionL |
|
1332 |
// From MSwtText |
|
1333 |
// --------------------------------------------------------------------------- |
|
1334 |
// |
|
1335 |
void CSwtText::ClearSelectionL() |
|
1336 |
{ |
|
1337 |
TCursorSelection selection(Editor().Selection()); |
|
1338 |
Editor().SetSelectionL(selection.iCursorPos, selection.iCursorPos); |
|
1339 |
Editor().TextView()->SetSelectionL(TCursorSelection( |
|
1340 |
selection.iCursorPos, selection.iCursorPos)); |
|
1341 |
} |
|
1342 |
||
1343 |
// --------------------------------------------------------------------------- |
|
1344 |
// CSwtText::SelectAllL |
|
1345 |
// From MSwtText |
|
1346 |
// --------------------------------------------------------------------------- |
|
1347 |
// |
|
1348 |
void CSwtText::SelectAllL() |
|
1349 |
{ |
|
1350 |
const TInt length = Editor().TextLength(); |
|
1351 |
Editor().SetSelectionL(length, 0); |
|
1352 |
Editor().TextView()->SetSelectionL(TCursorSelection(length, 0)); |
|
1353 |
} |
|
1354 |
||
1355 |
// --------------------------------------------------------------------------- |
|
1356 |
// CSwtText::ShowSelectionL |
|
1357 |
// From MSwtText |
|
1358 |
// --------------------------------------------------------------------------- |
|
1359 |
// |
|
1360 |
void CSwtText::ShowSelectionL() |
|
1361 |
{ |
|
1362 |
TCursorSelection selection(Editor().Selection()); |
|
1363 |
Editor().SetSelectionL(selection.iCursorPos, selection.iAnchorPos); |
|
1364 |
} |
|
1365 |
||
1366 |
// --------------------------------------------------------------------------- |
|
1367 |
// CSwtText::CopyL |
|
1368 |
// From MSwtText |
|
1369 |
// --------------------------------------------------------------------------- |
|
1370 |
// |
|
1371 |
void CSwtText::CopyL() |
|
1372 |
{ |
|
1373 |
if (!(iStyle & KSwtStylePassword)) |
|
1374 |
{ |
|
1375 |
Editor().ClipboardL(CEikEdwin::ECopy); |
|
1376 |
} |
|
1377 |
} |
|
1378 |
||
1379 |
// --------------------------------------------------------------------------- |
|
1380 |
// CSwtText::PasteL |
|
1381 |
// From MSwtText |
|
1382 |
// --------------------------------------------------------------------------- |
|
1383 |
// |
|
1384 |
TBool CSwtText::PasteL() |
|
1385 |
{ |
|
1386 |
TPtrC content(SwtControlHelper::GetClipboardTextContentLC()); |
|
1387 |
TInt length = content.Length(); |
|
1388 |
if (content.Ptr() != NULL) |
|
1389 |
{ |
|
1390 |
CleanupStack::PopAndDestroy(); // content |
|
1391 |
} |
|
1392 |
if (length == 0) |
|
1393 |
{ |
|
1394 |
// Nothing to paste: CEikEdwin displays a message and leaves. |
|
1395 |
// We want the message but not the leaving, hence the trap. |
|
1396 |
TRAP_IGNORE(Editor().ClipboardL(CEikEdwin::EPaste)); |
|
1397 |
return EFalse; |
|
1398 |
} |
|
1399 |
||
1400 |
Editor().ClipboardL(CEikEdwin::EPaste); |
|
1401 |
return ETrue; |
|
1402 |
} |
|
1403 |
||
1404 |
// --------------------------------------------------------------------------- |
|
1405 |
// CSwtText::GetEditable |
|
1406 |
// From MSwtText |
|
1407 |
// --------------------------------------------------------------------------- |
|
1408 |
// |
|
1409 |
TBool CSwtText::GetEditable() const |
|
1410 |
{ |
|
1411 |
return CSwtTextBase::GetEditable(); |
|
1412 |
} |
|
1413 |
||
1414 |
// --------------------------------------------------------------------------- |
|
1415 |
// CSwtText::SetEditable |
|
1416 |
// From MSwtText |
|
1417 |
// --------------------------------------------------------------------------- |
|
1418 |
// |
|
1419 |
void CSwtText::SetEditable(TBool aEditable) |
|
1420 |
{ |
|
1421 |
CSwtTextBase::SetEditable(aEditable); |
|
1422 |
} |
|
1423 |
||
1424 |
// --------------------------------------------------------------------------- |
|
1425 |
// CSwtText::GetLineCount |
|
1426 |
// From MSwtText |
|
1427 |
// --------------------------------------------------------------------------- |
|
1428 |
// |
|
1429 |
TInt CSwtText::GetLineCount() const |
|
1430 |
{ |
|
1431 |
return Editor().TextLayout()->NumFormattedLines(); |
|
1432 |
} |
|
1433 |
||
1434 |
// --------------------------------------------------------------------------- |
|
1435 |
// CSwtText::GetLineHeightL |
|
1436 |
// From MSwtText |
|
1437 |
// --------------------------------------------------------------------------- |
|
1438 |
// |
|
1439 |
TInt CSwtText::GetLineHeightL() const |
|
1440 |
{ |
|
1441 |
CTextLayout* layout = Editor().TextLayout(); |
|
1442 |
TPoint xyPos(TPoint::EUninitialized); |
|
1443 |
layout->DocPosToXyPosL(0, xyPos); |
|
1444 |
TRect lineRect(TRect::EUninitialized); |
|
1445 |
layout->GetLineRect(xyPos.iY, lineRect); |
|
1446 |
return lineRect.Height(); |
|
1447 |
} |
|
1448 |
||
1449 |
// --------------------------------------------------------------------------- |
|
1450 |
// CSwtText::GetTopIndexL |
|
1451 |
// From MSwtText |
|
1452 |
// --------------------------------------------------------------------------- |
|
1453 |
// |
|
1454 |
TInt CSwtText::GetTopIndexL() const |
|
1455 |
{ |
|
1456 |
ASSERT(iStyle & KSwtStyleMulti); |
|
1457 |
||
1458 |
CTextLayout* layout = Editor().TextLayout(); |
|
1459 |
||
1460 |
// First fully visible line |
|
1461 |
TInt firstLine = layout->FirstLineInBand(); |
|
1462 |
||
1463 |
// Adjust ( if needed ) to return the first partially visible line |
|
1464 |
// FirstCharOnLine() counts lines from 1 |
|
1465 |
TInt lineStart = layout->FirstCharOnLine(firstLine + 1); |
|
1466 |
TRect lineRect(layout->GetLineRectL(lineStart, lineStart)); |
|
1467 |
if (lineRect.iTl.iY != 0) |
|
1468 |
{ |
|
1469 |
--firstLine; |
|
1470 |
} |
|
1471 |
||
1472 |
return firstLine; |
|
1473 |
} |
|
1474 |
||
1475 |
// --------------------------------------------------------------------------- |
|
1476 |
// CSwtText::SetTopIndexL |
|
1477 |
// From MSwtText |
|
1478 |
// --------------------------------------------------------------------------- |
|
1479 |
// |
|
1480 |
void CSwtText::SetTopIndexL(TInt aIndex) |
|
1481 |
{ |
|
1482 |
ASSERT(iStyle & KSwtStyleMulti); |
|
1483 |
||
1484 |
if (aIndex < 0) |
|
1485 |
{ |
|
1486 |
aIndex = 0; |
|
1487 |
} |
|
1488 |
Editor().TextView()->SetViewLineAtTopL(aIndex + 1); |
|
1489 |
||
1490 |
// Update vertical scroll - bar |
|
1491 |
CEikScrollBarFrame* sbFrame = Editor().ScrollBarFrame(); |
|
1492 |
if (sbFrame) |
|
1493 |
{ |
|
1494 |
CEikScrollBar* vsb = sbFrame->GetScrollBarHandle( |
|
1495 |
CEikScrollBar::EVertical); |
|
1496 |
if (vsb) |
|
1497 |
{ |
|
1498 |
Editor().HandleScrollEventL( |
|
1499 |
vsb, EEikScrollThumbReleaseVert); |
|
1500 |
} |
|
1501 |
} |
|
1502 |
} |
|
1503 |
||
1504 |
// --------------------------------------------------------------------------- |
|
1505 |
// CSwtText::GetTopPixelL |
|
1506 |
// From MSwtText |
|
1507 |
// --------------------------------------------------------------------------- |
|
1508 |
// |
|
1509 |
TInt CSwtText::GetTopPixelL() const |
|
1510 |
{ |
|
1511 |
if (iStyle & KSwtStyleSingle) |
|
1512 |
{ |
|
1513 |
return 0; |
|
1514 |
} |
|
1515 |
||
1516 |
CTextLayout* layout = Editor().TextLayout(); |
|
1517 |
TInt topLine = layout->FirstLineInBand(); |
|
1518 |
TInt lineStart = layout->FirstCharOnLine(topLine + 1); |
|
1519 |
TRect lineRect(layout->GetLineRectL(lineStart, lineStart)); |
|
1520 |
TInt lineHeight = lineRect.Height(); |
|
1521 |
if (lineRect.iTl.iY != 0) |
|
1522 |
{ |
|
1523 |
--topLine; |
|
1524 |
} |
|
1525 |
TInt topPixel = (lineHeight * topLine) + lineRect.iTl.iY; |
|
1526 |
return topPixel; |
|
1527 |
} |
|
1528 |
||
1529 |
// --------------------------------------------------------------------------- |
|
1530 |
// CSwtText::GetEchoChar |
|
1531 |
// From MSwtText |
|
1532 |
// --------------------------------------------------------------------------- |
|
1533 |
// |
|
1534 |
TText CSwtText::GetEchoChar() const |
|
1535 |
{ |
|
1536 |
return static_cast < CPasswordText* >(Editor().Text())->iEchoChar; |
|
1537 |
} |
|
1538 |
||
1539 |
// --------------------------------------------------------------------------- |
|
1540 |
// CSwtText::SetEchoChar |
|
1541 |
// From MSwtText |
|
1542 |
// --------------------------------------------------------------------------- |
|
1543 |
// |
|
1544 |
void CSwtText::SetEchoCharL(TText aEcho) |
|
1545 |
{ |
|
1546 |
if (aEcho!=0 && !TChar(aEcho).IsPrint()) |
|
1547 |
{ |
|
1548 |
aEcho = KDefaultSecretChar; |
|
1549 |
} |
|
1550 |
static_cast < CPasswordText* >(Editor().Text())->iEchoChar = aEcho; |
|
1551 |
static_cast < CPasswordText* >(Editor().Text())->SetEchoCharL(); |
|
1552 |
Redraw(); |
|
1553 |
} |
|
1554 |
||
1555 |
// --------------------------------------------------------------------------- |
|
1556 |
// CSwtText::SetDoubleClickEnabled |
|
1557 |
// From MSwtText |
|
1558 |
// --------------------------------------------------------------------------- |
|
1559 |
// |
|
1560 |
void CSwtText::SetDoubleClickEnabled(TBool /*aEnabled*/) |
|
1561 |
{ |
|
1562 |
// No pointer, nothing to do |
|
1563 |
} |
|
1564 |
||
1565 |
// --------------------------------------------------------------------------- |
|
1566 |
// CSwtText::GetOrientation |
|
1567 |
// From MSwtText |
|
1568 |
// --------------------------------------------------------------------------- |
|
1569 |
// |
|
1570 |
TInt CSwtText::GetOrientation() const |
|
1571 |
{ |
|
1572 |
return iStyle & KSwtOrientationMask; |
|
1573 |
} |
|
1574 |
||
1575 |
// --------------------------------------------------------------------------- |
|
1576 |
// CSwtText::SetOrientationL |
|
1577 |
// From MSwtText |
|
1578 |
// --------------------------------------------------------------------------- |
|
1579 |
// |
|
1580 |
void CSwtText::SetOrientationL(TInt aOrientation) |
|
1581 |
{ |
|
1582 |
ASSERT(aOrientation == KSwtStyleLeftToRight |
|
1583 |
|| aOrientation == KSwtStyleRightToLeft); |
|
1584 |
iStyle &= ~KSwtOrientationMask; |
|
1585 |
iStyle |= aOrientation; |
|
1586 |
SetAlignmentL(); |
|
1587 |
Editor().HandleTextChangedL(); |
|
1588 |
} |
|
1589 |
||
1590 |
// --------------------------------------------------------------------------- |
|
1591 |
// CSwtText::ProcessVerifiedTextL |
|
1592 |
// From MSwtVerifyEventObserver |
|
1593 |
// --------------------------------------------------------------------------- |
|
1594 |
// |
|
1595 |
void CSwtText::ProcessVerifiedTextL( |
|
1596 |
TInt aStart, TInt aEnd, TDes& aText) |
|
1597 |
{ |
|
1598 |
ProcessLineBrakes(aText); |
|
1599 |
Editor().CancelFepTransaction(); |
|
1600 |
const TCursorSelection oldSelection(Editor().Selection()); |
|
1601 |
||
1602 |
// Special treatment for the most common cases, we simply send a key |
|
1603 |
// instead of replacing the text. This helps reduce flicker. |
|
1604 |
||
1605 |
// Single printable character |
|
1606 |
if (aText.Length() == 1 |
|
1607 |
&& oldSelection.LowerPos() == aStart |
|
1608 |
&& oldSelection.HigherPos() == aEnd) |
|
1609 |
{ |
|
1610 |
TText ch = aText[0]; |
|
1611 |
if (TChar(ch).IsPrint() |
|
1612 |
|| ch == CEditableText::EParagraphDelimiter |
|
1613 |
|| ch == CEditableText::ELineBreak) |
|
1614 |
{ |
|
1615 |
SendCharacterL(aText[0]); |
|
1616 |
return; |
|
1617 |
} |
|
1618 |
} |
|
1619 |
||
1620 |
if (aText.Length() == 0 && oldSelection.Length() == 0) |
|
1621 |
{ |
|
1622 |
// Delete |
|
1623 |
if (aStart == oldSelection.iCursorPos |
|
1624 |
&& aEnd == oldSelection.iCursorPos + 1) |
|
1625 |
{ |
|
1626 |
SendCharacterL(EKeyDelete); |
|
1627 |
return; |
|
1628 |
} |
|
1629 |
||
1630 |
// Backspace |
|
1631 |
if (aStart == oldSelection.iCursorPos - 1 |
|
1632 |
&& aEnd == oldSelection.iCursorPos) |
|
1633 |
{ |
|
1634 |
SendCharacterL(EKeyBackspace); |
|
1635 |
return; |
|
1636 |
} |
|
1637 |
} |
|
1638 |
||
1639 |
Editor().ClearSelectionL(); |
|
1640 |
||
1641 |
// Delete old range and insert new text |
|
1642 |
CPlainText* plainText = Editor().Text(); |
|
1643 |
TInt textLength = plainText->DocumentLength(); |
|
1644 |
if (aStart > textLength) |
|
1645 |
{ |
|
1646 |
aStart = textLength; |
|
1647 |
} |
|
1648 |
if (aEnd > textLength) |
|
1649 |
{ |
|
1650 |
aEnd = textLength; |
|
1651 |
} |
|
1652 |
||
1653 |
plainText->DeleteL(aStart, aEnd - aStart); |
|
1654 |
||
1655 |
textLength = aText.Length(); |
|
1656 |
if (textLength > 0) |
|
1657 |
{ |
|
1658 |
TInt nbExtraChar = ((iTextLimit > 0) |
|
1659 |
&& (iTextLimit < (plainText->DocumentLength() + textLength))) ? |
|
1660 |
(plainText->DocumentLength() + textLength - iTextLimit) : 0; |
|
1661 |
if (nbExtraChar > 0) |
|
1662 |
{ |
|
1663 |
aText.Delete(textLength - nbExtraChar, nbExtraChar); |
|
1664 |
iEikonEnv->InfoMsg(R_EIK_TBUF_MAX_CHARACTERS_REACHED); |
|
1665 |
} |
|
1666 |
plainText->InsertL(aStart, aText); |
|
1667 |
} |
|
1668 |
Editor().HandleTextChangedL(); |
|
1669 |
TInt newCursorPos; |
|
1670 |
if (oldSelection.HigherPos()>=aStart && oldSelection.LowerPos()<=aEnd) |
|
1671 |
{ |
|
1672 |
newCursorPos=aStart+aText.Length(); |
|
1673 |
} |
|
1674 |
else if (oldSelection.iCursorPos>aEnd) |
|
1675 |
{ |
|
1676 |
newCursorPos=oldSelection.iCursorPos-(aEnd-aStart)+aText.Length(); |
|
1677 |
} |
|
1678 |
else |
|
1679 |
{ |
|
1680 |
newCursorPos=oldSelection.iCursorPos; |
|
1681 |
} |
|
1682 |
||
1683 |
Editor().SetSelectionL(newCursorPos,newCursorPos); |
|
1684 |
iDisplay.PostModifyEventL(iPeer); |
|
1685 |
} |
|
1686 |
||
1687 |
||
1688 |
// --------------------------------------------------------------------------- |
|
1689 |
// CSwtText::HandleEdwinEventL |
|
1690 |
// From MEikEdwinObserver |
|
1691 |
// --------------------------------------------------------------------------- |
|
1692 |
// |
|
1693 |
void CSwtText::HandleEdwinEventL(CEikEdwin*, TEdwinEvent aEventType) |
|
1694 |
{ |
|
1695 |
if (aEventType == EEventTextUpdate) |
|
1696 |
{ |
|
1697 |
iDisplay.PostModifyEventL(iPeer); |
|
1698 |
} |
|
1699 |
} |
|
1700 |
||
1701 |
// --------------------------------------------------------------------------- |
|
1702 |
// CSwtText::SetVisibleScrollBar |
|
1703 |
// From MEikEdwinObserver |
|
1704 |
// --------------------------------------------------------------------------- |
|
1705 |
// |
|
1706 |
void CSwtText::SetVisibleScrollBar( |
|
1707 |
TInt aStyle, TBool aVisible) |
|
1708 |
{ |
|
1709 |
// Get frame |
|
1710 |
CEikScrollBarFrame* sbFrame = SbFrame(); |
|
1711 |
if (!sbFrame) |
|
1712 |
{ |
|
1713 |
return; |
|
1714 |
} |
|
1715 |
||
1716 |
// Calculate new visibility states |
|
1717 |
if (aStyle & KSwtStyleHScroll) |
|
1718 |
{ |
|
1719 |
iHScroll->SetVisible(aVisible); |
|
1720 |
} |
|
1721 |
||
1722 |
if (aStyle & KSwtStyleVScroll) |
|
1723 |
{ |
|
1724 |
iVScroll->SetVisible(aVisible); |
|
1725 |
} |
|
1726 |
||
1727 |
// Resize Scrollable, as the client area has changed |
|
1728 |
CCoeControl& coeCtrl = CoeControl(); |
|
1729 |
coeCtrl.SetSize(coeCtrl.Size()); |
|
1730 |
||
1731 |
// Force a redraw here as some Scrollables do not update the screen after |
|
1732 |
// a scrollbar as been switched on or off. |
|
1733 |
Redraw(); |
|
1734 |
} |
|
1735 |