|
1 /* |
|
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description : CEikRichTextEditor based Rich Text viewer |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cesmrrichtextviewer.h" |
|
19 |
|
20 #include "mesmrlistobserver.h"// SCROLLING_MOD: List observer header |
|
21 #include "esmrconfig.hrh" |
|
22 #include "esmrhelper.h" |
|
23 #include "cesmriconfield.h" |
|
24 #include "cesmrfieldcommandevent.h" |
|
25 #include "mesmrfieldeventqueue.h" |
|
26 #include "cesmrlayoutmgr.h" |
|
27 #include "cesmrrichtextlink.h" |
|
28 #include "cesmrcontactmenuhandler.h" |
|
29 #include "nmrbitmapmanager.h" |
|
30 |
|
31 #include <esmrgui.rsg> |
|
32 #include <commonphoneparser.h> |
|
33 #include <finditemengine.h> |
|
34 #include <txtrich.h> |
|
35 #include <AknsUtils.h> |
|
36 #include <eikenv.h> |
|
37 #include <data_caging_path_literals.hrh> |
|
38 #include <baclipb.h> // for clipboard copy |
|
39 #include <aknlongtapdetector.h> |
|
40 #include <touchfeedback.h> |
|
41 |
|
42 #ifndef FF_CMAIL_INTEGRATION |
|
43 #include <txtclipboard.h> |
|
44 #endif // FF_CMAIL_INTEGRATION |
|
45 |
|
46 // DEBUG |
|
47 #include "emailtrace.h" |
|
48 |
|
49 // <cmail> Removed profiling. </cmail> |
|
50 |
|
51 // Unnamed namespace for local definitions |
|
52 namespace{ // codescanner::namespace |
|
53 |
|
54 const TInt KArrowUpperMargin (2); |
|
55 const TInt KArrowRightMargin (5); |
|
56 |
|
57 }//namespace |
|
58 |
|
59 // ======== MEMBER FUNCTIONS ======== |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CESMRRichTextViewer::NewL |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CESMRRichTextViewer* CESMRRichTextViewer::NewL( |
|
66 const CCoeControl* aParent) |
|
67 { |
|
68 FUNC_LOG; |
|
69 CESMRRichTextViewer* self = new (ELeave) CESMRRichTextViewer; |
|
70 CleanupStack::PushL ( self ); |
|
71 self->ConstructL( aParent ); |
|
72 CleanupStack::Pop ( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CESMRRichTextViewer::~CESMRRichTextViewer |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C CESMRRichTextViewer::~CESMRRichTextViewer( ) |
|
81 { |
|
82 FUNC_LOG; |
|
83 iLinkList.ResetAndDestroy ( ); |
|
84 delete iActionMenuIcon; |
|
85 delete iActionMenuIconMask; |
|
86 iESMRStatic.Close ( ); |
|
87 delete iLongTapDetector; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CESMRRichTextViewer::PositionChanged |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C void CESMRRichTextViewer::PositionChanged( ) |
|
95 { |
|
96 FUNC_LOG; |
|
97 CTextView* view = TextView ( ); |
|
98 if ( view ) |
|
99 { |
|
100 view->SetViewRect ( Rect ( ) ); |
|
101 } |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CESMRRichTextViewer::FocusChanged |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C void CESMRRichTextViewer::FocusChanged( |
|
109 TDrawNow aDrawNow ) |
|
110 { |
|
111 FUNC_LOG; |
|
112 CEikRichTextEditor::FocusChanged( aDrawNow ); |
|
113 if ( !TextLayout() || !TextView() ) |
|
114 { |
|
115 // not constructed totally: |
|
116 return; |
|
117 } |
|
118 |
|
119 if ( IsFocused() ) |
|
120 { |
|
121 if( iLayout ) |
|
122 { |
|
123 TRAP_IGNORE( SetFontColorL( ETrue ) ); |
|
124 } |
|
125 |
|
126 if ( iCurrentLinkIndex == KErrNotFound ) |
|
127 { |
|
128 TInt linkRow = KErrNotFound; |
|
129 if ( CursorPos() == 0 ) |
|
130 { |
|
131 // focus is coming from field above: |
|
132 linkRow = FindTextLinkBetweenNextScrollArea( |
|
133 0, 1, TCursorPosition::EFLineDown ); |
|
134 } |
|
135 else |
|
136 { |
|
137 linkRow = FindTextLinkBetweenNextScrollArea( |
|
138 LineCount()-2, |
|
139 LineCount()-1, |
|
140 TCursorPosition::EFLineUp); |
|
141 } |
|
142 if ( linkRow != KErrNotFound ) |
|
143 { |
|
144 const CESMRRichTextLink* link = GetSelectedLink ( ); |
|
145 if (link ) |
|
146 { |
|
147 HighlightLink (*link ); |
|
148 DrawDeferred ( ); |
|
149 } |
|
150 } |
|
151 } |
|
152 else |
|
153 { |
|
154 const CESMRRichTextLink* link = GetSelectedLink ( ); |
|
155 HighlightLink( *link ); |
|
156 DrawDeferred(); |
|
157 } |
|
158 } |
|
159 |
|
160 if (!IsFocused()) |
|
161 { |
|
162 // losing focus |
|
163 // <cmail> codescanner |
|
164 TRAP_IGNORE(SetSelectionL(CursorPos(), CursorPos())); |
|
165 if( iLayout ) |
|
166 { |
|
167 TRAP_IGNORE(SetFontColorL( EFalse )); |
|
168 } |
|
169 // </cmail> |
|
170 TRAP_IGNORE( TextView()->SetDocPosL( 0 )); |
|
171 } |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CESMRRichTextViewer::FindTextLinkBetweenNextScrollArea |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TInt CESMRRichTextViewer::FindTextLinkBetweenNextScrollArea( |
|
179 TInt aStartRow, |
|
180 TInt aEndRow, |
|
181 TCursorPosition::TMovementType aDirection) |
|
182 { |
|
183 FUNC_LOG; |
|
184 TInt linkRow(KErrNotFound); |
|
185 |
|
186 // fetch the line number where the next link is located: |
|
187 if ( aDirection == TCursorPosition::EFLineDown ) |
|
188 { |
|
189 for (TInt i = 0; i<iLinkList.Count(); i++) |
|
190 { |
|
191 linkRow = ValidLinkForFocusing(i, aDirection, aStartRow, aEndRow); |
|
192 if ( linkRow != KErrNotFound) |
|
193 { |
|
194 return linkRow; |
|
195 } |
|
196 } |
|
197 } |
|
198 else |
|
199 for (TInt i = iLinkList.Count()-1; i>=0 ; i--) |
|
200 { |
|
201 linkRow = ValidLinkForFocusing(i, aDirection, aStartRow, aEndRow); |
|
202 if ( linkRow != KErrNotFound) |
|
203 { |
|
204 return linkRow; |
|
205 } |
|
206 } |
|
207 |
|
208 iCurrentLinkIndex = KErrNotFound; |
|
209 return linkRow; |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CESMRRichTextViewer::ValidLinkForFocusing |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 TInt CESMRRichTextViewer::ValidLinkForFocusing( |
|
217 TInt aIndex, |
|
218 TCursorPosition::TMovementType aDirection, |
|
219 TInt aStartRow, |
|
220 TInt aEndRow ) |
|
221 { |
|
222 FUNC_LOG; |
|
223 |
|
224 |
|
225 if(iLinkList.Count() > aIndex) |
|
226 { |
|
227 TInt pos = iLinkList[aIndex]->StartPos(); |
|
228 |
|
229 TInt checkRow = TextLayout()->GetLineNumber( pos ); |
|
230 |
|
231 if ( checkRow >= aStartRow && checkRow <= ( aEndRow ) ) |
|
232 { |
|
233 if ( aDirection == TCursorPosition::EFLineDown && |
|
234 aIndex > iCurrentLinkIndex || |
|
235 aDirection == TCursorPosition::EFLineUp && |
|
236 ( aIndex < iCurrentLinkIndex || |
|
237 iCurrentLinkIndex == KErrNotFound )) |
|
238 { |
|
239 iCurrentLinkIndex = aIndex; |
|
240 |
|
241 // link found between next scroll area. |
|
242 return checkRow; |
|
243 } |
|
244 } |
|
245 } |
|
246 return KErrNotFound; |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CESMRRichTextViewer::SetHighLightToNextLinkL |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 TBool CESMRRichTextViewer::SetHighLightToNextLinkL( |
|
254 TCursorPosition::TMovementType aDirection, |
|
255 TInt aStartRow, |
|
256 TInt aEndRow ) |
|
257 { |
|
258 FUNC_LOG; |
|
259 TBool ret( EFalse ); |
|
260 |
|
261 TInt currentLineNumber = TextLayout()->GetLineNumber( CursorPos() ); |
|
262 |
|
263 // check is there a link before next scroll point: |
|
264 TInt linkRow = FindTextLinkBetweenNextScrollArea( |
|
265 aStartRow , aEndRow, aDirection); |
|
266 |
|
267 if ( linkRow != KErrNotFound && iCurrentLinkIndex != KErrNotFound ) |
|
268 { |
|
269 const CESMRRichTextLink* link = GetSelectedLink ( ); |
|
270 if (link ) |
|
271 { |
|
272 HighlightLink (*link ); |
|
273 |
|
274 if ( iObserver && linkRow != currentLineNumber ) |
|
275 { |
|
276 TInt endOfLink = link->StartPos()+link->Length(); |
|
277 TInt line = TextLayout()->GetLineNumber( endOfLink ); |
|
278 if ( aDirection == TCursorPosition::EFLineUp ) // moving up: |
|
279 { |
|
280 iObserver->MoveListAreaDownL( |
|
281 RowHeight() * ( currentLineNumber - line )); |
|
282 } |
|
283 else |
|
284 { |
|
285 iObserver->MoveListAreaUpL( |
|
286 RowHeight() * ( line - currentLineNumber )); |
|
287 } |
|
288 } |
|
289 |
|
290 DrawDeferred ( ); |
|
291 ret = ETrue; |
|
292 } |
|
293 } |
|
294 else |
|
295 { |
|
296 // no link are focused, do reset work to refresh the option menu. |
|
297 ResetActionMenuL(); |
|
298 } |
|
299 |
|
300 return ret; |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CESMRRichTextViewer::OfferKeyEventL |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C TKeyResponse CESMRRichTextViewer::OfferKeyEventL( |
|
308 const TKeyEvent &aKeyEvent, |
|
309 TEventCode aType ) |
|
310 { |
|
311 FUNC_LOG; |
|
312 // Handle only event keys |
|
313 if ( aType == EEventKey ) |
|
314 { |
|
315 if ( iObserver ) // only description field has observer set. |
|
316 { |
|
317 // fetch the current line number: |
|
318 TInt currentLineNumber = TextLayout()->GetLineNumber( CursorPos() ); |
|
319 |
|
320 if ( aKeyEvent.iCode == EKeyDownArrow && aType == EEventKey ) |
|
321 { |
|
322 if ( !iObserver->IsFieldBottomVisible() && |
|
323 SetHighLightToNextLinkL( |
|
324 TCursorPosition::EFLineDown, |
|
325 currentLineNumber, |
|
326 currentLineNumber + KMaxAddressFieldLines) ) |
|
327 { |
|
328 return EKeyWasConsumed; |
|
329 } |
|
330 else if ( iObserver->IsFieldBottomVisible() ) |
|
331 { |
|
332 if ( SetHighLightToNextLinkL(TCursorPosition::EFLineDown, |
|
333 currentLineNumber, |
|
334 iNumberOfLines) ) |
|
335 { |
|
336 return EKeyWasConsumed; |
|
337 } |
|
338 // means that the whole control is visible: |
|
339 // and we can skip to next field |
|
340 return EKeyWasNotConsumed; |
|
341 } |
|
342 |
|
343 if ( currentLineNumber == iNumberOfLines ) |
|
344 { |
|
345 // the end of text has been reached |
|
346 return EKeyWasConsumed; |
|
347 } |
|
348 |
|
349 // move three lines... |
|
350 ScrollViewL( KMaxAddressFieldLines, |
|
351 TCursorPosition::EFLineDown); |
|
352 |
|
353 |
|
354 SetSelectionL( CursorPos(), CursorPos() ); |
|
355 iCurrentLinkIndex = KErrNotFound; |
|
356 if ( iObserver ) |
|
357 { |
|
358 iObserver->MoveListAreaUpL( |
|
359 RowHeight() * KMaxAddressFieldLines ); |
|
360 } |
|
361 |
|
362 return EKeyWasConsumed; |
|
363 } |
|
364 else if ( aKeyEvent.iCode == EKeyUpArrow && aType == EEventKey ) |
|
365 { |
|
366 if (iPosition.iY < 0 && |
|
367 SetHighLightToNextLinkL( |
|
368 TCursorPosition::EFLineUp, |
|
369 currentLineNumber - KMaxAddressFieldLines, |
|
370 currentLineNumber)) |
|
371 { |
|
372 return EKeyWasConsumed; |
|
373 } |
|
374 if ( iPosition.iY > 0 ) |
|
375 { |
|
376 // before changing the focus the field above, |
|
377 // check is there any links in rest of text |
|
378 if (SetHighLightToNextLinkL(TCursorPosition::EFLineUp, |
|
379 0, |
|
380 currentLineNumber)) |
|
381 { |
|
382 return EKeyWasConsumed; |
|
383 } |
|
384 |
|
385 // means that the whole control is visible: |
|
386 // and we can skip to next field |
|
387 return EKeyWasNotConsumed; |
|
388 } |
|
389 else |
|
390 { |
|
391 TInt currentLineNumber = |
|
392 TextLayout()->GetLineNumber( CursorPos() ); |
|
393 // move three lines... |
|
394 ScrollViewL( KMaxAddressFieldLines, |
|
395 TCursorPosition::EFLineUp); |
|
396 |
|
397 SetSelectionL( CursorPos(), CursorPos()); |
|
398 iCurrentLinkIndex = KErrNotFound; |
|
399 |
|
400 if ( iObserver ) |
|
401 { |
|
402 iObserver->MoveListAreaDownL( |
|
403 RowHeight() * KMaxAddressFieldLines ); |
|
404 } |
|
405 |
|
406 currentLineNumber = |
|
407 TextLayout()->GetLineNumber( CursorPos() ); |
|
408 return EKeyWasConsumed; |
|
409 } |
|
410 } |
|
411 } |
|
412 if ( aKeyEvent.iCode == EKeyRightArrow || |
|
413 aKeyEvent.iCode == EKeyDevice3 || |
|
414 aKeyEvent.iCode == EKeyDevice4 || |
|
415 aKeyEvent.iCode == EKeyEnter ) |
|
416 { |
|
417 // Show right click menu (action menu) |
|
418 const CESMRRichTextLink* link = GetSelectedLink(); |
|
419 if (link && |
|
420 link->TriggerKey ( )== CESMRRichTextLink::ETriggerKeyRight ) |
|
421 { |
|
422 if ( !iLinkObserver || |
|
423 !iLinkObserver->HandleRichTextLinkSelection(link) ) |
|
424 { |
|
425 iCntMenuHdlr->ShowActionMenuL(); |
|
426 } |
|
427 return EKeyWasConsumed; |
|
428 } |
|
429 } |
|
430 if ( aKeyEvent.iCode == EKeyLeftArrow ) |
|
431 { |
|
432 const CESMRRichTextLink* link = GetSelectedLink(); |
|
433 if ( link ) |
|
434 { |
|
435 return EKeyWasConsumed; |
|
436 } |
|
437 } |
|
438 if ( aKeyEvent.iCode == EKeyDevice3 || |
|
439 aKeyEvent.iCode == EKeyDevice4 || |
|
440 aKeyEvent.iCode == EKeyEnter ) |
|
441 { |
|
442 // Select link |
|
443 const CESMRRichTextLink* link = GetSelectedLink ( ); |
|
444 if (link && |
|
445 link->TriggerKey ( )== CESMRRichTextLink::ETriggerKeyOk ) |
|
446 { |
|
447 if (iLinkObserver && |
|
448 iLinkObserver->HandleRichTextLinkSelection (link ) ) |
|
449 { |
|
450 return EKeyWasConsumed; |
|
451 } |
|
452 } |
|
453 } |
|
454 } |
|
455 |
|
456 return EKeyWasNotConsumed; |
|
457 } |
|
458 |
|
459 |
|
460 // ----------------------------------------------------------------------------- |
|
461 // CESMRRichTextViewer::ScrollViewL |
|
462 // ----------------------------------------------------------------------------- |
|
463 // |
|
464 void CESMRRichTextViewer::ScrollViewL( |
|
465 TInt aNumberOfRows, |
|
466 TCursorPosition::TMovementType aDirection) |
|
467 { |
|
468 FUNC_LOG; |
|
469 for( TInt i=0; i < aNumberOfRows; i++ ) |
|
470 { |
|
471 MoveCursorL( aDirection, EFalse); |
|
472 } |
|
473 } |
|
474 |
|
475 // ----------------------------------------------------------------------------- |
|
476 // CESMRRichTextViewer::SetMargins |
|
477 // ----------------------------------------------------------------------------- |
|
478 // |
|
479 EXPORT_C void CESMRRichTextViewer::SetMargins( TInt sMargin ) |
|
480 { |
|
481 // Set new value for left and right margins |
|
482 if ( TextView() ) |
|
483 { |
|
484 TextView()->SetMarginWidths( sMargin ,0); |
|
485 } |
|
486 } |
|
487 |
|
488 // ----------------------------------------------------------------------------- |
|
489 // CESMRRichTextViewer::SetFontL |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 EXPORT_C void CESMRRichTextViewer::SetFontL( const CFont* aFont, |
|
493 CESMRLayoutManager* aLayout ) |
|
494 { |
|
495 FUNC_LOG; |
|
496 // These pointers are stored to able font color changing when losing or |
|
497 // gaining focus |
|
498 iLayout = aLayout; |
|
499 iFont = aFont; |
|
500 |
|
501 SetFontColorL( IsFocused() ); |
|
502 |
|
503 // This forces CEikEdwin::OnReformatL to notify observer |
|
504 // through HandleEdwinSizeEventL about changed size. |
|
505 // It is notified only if linecount changes. |
|
506 CEikEdwin::iNumberOfLines = 0; |
|
507 CEikEdwin::FormatTextL(); |
|
508 } |
|
509 |
|
510 // ----------------------------------------------------------------------------- |
|
511 // CESMRRichTextViewer::SetFontColor |
|
512 // ----------------------------------------------------------------------------- |
|
513 // |
|
514 void CESMRRichTextViewer::SetFontColorL( TBool aFocused ) |
|
515 { |
|
516 FUNC_LOG; |
|
517 // all this stuff is needed to be set, otherwise the |
|
518 // font loses its antialiasing drawing |
|
519 |
|
520 TFontSpec fontSpec = iFont->FontSpecInTwips(); |
|
521 |
|
522 CParaFormat paraFormat; |
|
523 TParaFormatMask paraFormatMask; |
|
524 paraFormat.iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels; |
|
525 |
|
526 paraFormatMask.SetAttrib( EAttLineSpacing ); |
|
527 paraFormat.iHorizontalAlignment = CParaFormat::ELeftAlign; |
|
528 paraFormatMask.SetAttrib( EAttAlignment ); |
|
529 |
|
530 TCharFormat charFormat; |
|
531 TCharFormatMask formatMask; |
|
532 charFormat.iFontSpec = fontSpec; |
|
533 |
|
534 formatMask.SetAttrib( EAttFontTypeface ); |
|
535 formatMask.SetAttrib( EAttFontHeight ); |
|
536 formatMask.SetAttrib( EAttFontPosture ); |
|
537 formatMask.SetAttrib( EAttFontStrokeWeight ); |
|
538 |
|
539 if( aFocused ) |
|
540 { |
|
541 charFormat.iFontPresentation.iTextColor = |
|
542 iLayout->ViewerListAreaHighlightedTextColor(); |
|
543 } |
|
544 else |
|
545 { |
|
546 charFormat.iFontPresentation.iTextColor = KRgbBlack; |
|
547 } |
|
548 formatMask.SetAttrib( EAttColor ); |
|
549 |
|
550 CParaFormatLayer* paraFormatLayer = |
|
551 CParaFormatLayer::NewL( ¶Format, paraFormatMask ); |
|
552 CleanupStack::PushL( paraFormatLayer ); |
|
553 |
|
554 CCharFormatLayer* charFormatLayer = |
|
555 CCharFormatLayer::NewL( charFormat, formatMask ); |
|
556 |
|
557 SetParaFormatLayer( paraFormatLayer ); |
|
558 SetCharFormatLayer( charFormatLayer ); |
|
559 |
|
560 CleanupStack::Pop( paraFormatLayer ); |
|
561 } |
|
562 |
|
563 // ----------------------------------------------------------------------------- |
|
564 // CESMRRichTextViewer::SetTextL |
|
565 // ----------------------------------------------------------------------------- |
|
566 // |
|
567 EXPORT_C void CESMRRichTextViewer::SetTextL( |
|
568 const TDesC* aText, |
|
569 TBool aSearchLinks ) |
|
570 { |
|
571 FUNC_LOG; |
|
572 iCurrentLinkIndex = KErrNotFound; |
|
573 iLinkList.ResetAndDestroy ( ); |
|
574 |
|
575 // Clear edwin text |
|
576 CEikEdwin::SetCursorPosL( 0, EFalse ); |
|
577 |
|
578 // text lenght plus one to ensure the formatting |
|
579 // used is full, not band formatting. |
|
580 SetUpperFullFormattingLength( aText->Length() + 1 ); |
|
581 |
|
582 // Set new edwin text |
|
583 CEikRichTextEditor::SetTextL( aText ); |
|
584 |
|
585 //Make sure cursor is invisible and selection visible |
|
586 TextView()->SetCursorVisibilityL (TCursor::EFCursorInvisible, |
|
587 TCursor::EFCursorInvisible ); |
|
588 TextView()->SetSelectionVisibilityL (ETrue ); |
|
589 |
|
590 // Search text for links (highlights) |
|
591 if (aSearchLinks ) |
|
592 { |
|
593 SearchLinksL( *aText ); |
|
594 // find first link. |
|
595 FindTextLinkBetweenNextScrollArea(0, KMaxAddressFieldLines, TCursorPosition::EFLineDown); |
|
596 } |
|
597 |
|
598 // first row is 0, so let's add one... |
|
599 iNumberOfLines = TextLayout()->GetLineNumber( TextLength() ) + 1; |
|
600 } |
|
601 |
|
602 // ----------------------------------------------------------------------------- |
|
603 // CESMRRichTextViewer::SetLinkObserver |
|
604 // ----------------------------------------------------------------------------- |
|
605 // |
|
606 EXPORT_C void CESMRRichTextViewer::SetLinkObserver( |
|
607 MESMRRichTextObserver* aLinkObserver ) |
|
608 { |
|
609 FUNC_LOG; |
|
610 iLinkObserver = aLinkObserver; |
|
611 } |
|
612 |
|
613 // ----------------------------------------------------------------------------- |
|
614 // CESMRRichTextViewer::AddLinkL |
|
615 // ----------------------------------------------------------------------------- |
|
616 // |
|
617 EXPORT_C void CESMRRichTextViewer::AddLinkL( CESMRRichTextLink* aLink ) |
|
618 { |
|
619 FUNC_LOG; |
|
620 // If this is first link, set it highlighted |
|
621 TBool highlight = IsFocused()&& ( iLinkList.Count() == 0 ); |
|
622 |
|
623 // Reserve space for new link |
|
624 iLinkList.ReserveL( iLinkList.Count() + 1 ); |
|
625 |
|
626 RichText()->ApplyCharFormatL( iFormat, |
|
627 iFormatMask, |
|
628 aLink->StartPos(), |
|
629 aLink->Length() ); |
|
630 |
|
631 // Append aLink to link list. Space has been reserved, so this cannot fail. |
|
632 iLinkList.AppendL( aLink ); |
|
633 |
|
634 if ( highlight ) |
|
635 { |
|
636 HighlightLink( *aLink ); |
|
637 } |
|
638 } |
|
639 |
|
640 // ----------------------------------------------------------------------------- |
|
641 // CESMRRichTextViewer::InsertLinkL |
|
642 // ----------------------------------------------------------------------------- |
|
643 // |
|
644 EXPORT_C void CESMRRichTextViewer::InsertLinkL( CESMRRichTextLink* aLink, |
|
645 TInt aPosition ) |
|
646 { |
|
647 FUNC_LOG; |
|
648 // If this is first link, set it highlighted |
|
649 TBool highlight = IsFocused()&& ( iLinkList.Count() == 0 ); |
|
650 |
|
651 // Reserve space for new link |
|
652 iLinkList.ReserveL( iLinkList.Count() + 1 ); |
|
653 |
|
654 RichText()->ApplyCharFormatL( iFormat, |
|
655 iFormatMask, |
|
656 aLink->StartPos(), |
|
657 aLink->Length() ); |
|
658 |
|
659 // Insert aLink to link list. Space has been reserved, so this cannot fail. |
|
660 // InsertL panics if aPosition is illegal. |
|
661 iLinkList.InsertL( aLink, aPosition ); |
|
662 |
|
663 if ( highlight ) |
|
664 { |
|
665 HighlightLink( *aLink ); |
|
666 } |
|
667 } |
|
668 |
|
669 // ----------------------------------------------------------------------------- |
|
670 // CESMRRichTextViewer::GetSelectedLink |
|
671 // ----------------------------------------------------------------------------- |
|
672 // |
|
673 EXPORT_C const CESMRRichTextLink* CESMRRichTextViewer::GetSelectedLink( ) const |
|
674 { |
|
675 FUNC_LOG; |
|
676 if (iCurrentLinkIndex >= 0 && iCurrentLinkIndex < iLinkList.Count ( ) ) |
|
677 { |
|
678 return iLinkList[iCurrentLinkIndex]; |
|
679 } |
|
680 else |
|
681 { |
|
682 return NULL; |
|
683 } |
|
684 } |
|
685 |
|
686 // ----------------------------------------------------------------------------- |
|
687 // CESMRRichTextViewer::GetLinkTextL |
|
688 // ----------------------------------------------------------------------------- |
|
689 // |
|
690 EXPORT_C HBufC* CESMRRichTextViewer::GetLinkTextL( |
|
691 const CESMRRichTextLink& aLink ) const |
|
692 { |
|
693 FUNC_LOG; |
|
694 return RichText()->Read( aLink.StartPos ( ), aLink.Length ( ) ).AllocL(); |
|
695 } |
|
696 |
|
697 // ----------------------------------------------------------------------------- |
|
698 // CESMRRichTextViewer::CESMRRichTextViewer |
|
699 // ----------------------------------------------------------------------------- |
|
700 // |
|
701 EXPORT_C void CESMRRichTextViewer::SetListObserver( |
|
702 MESMRListObserver* aObserver ) |
|
703 { |
|
704 FUNC_LOG; |
|
705 iObserver = aObserver; |
|
706 } |
|
707 |
|
708 // ----------------------------------------------------------------------------- |
|
709 // CESMRRichTextViewer::RowHeight |
|
710 // ----------------------------------------------------------------------------- |
|
711 // |
|
712 EXPORT_C TInt CESMRRichTextViewer::RowHeight() |
|
713 { |
|
714 FUNC_LOG; |
|
715 TInt bandHeight = TextLayout()->BandHeight(); |
|
716 // Starts from zero, so let's increase the count by one. |
|
717 TInt lineNumberCount = TextLayout()->GetLineNumber( TextLength() ) + 1; |
|
718 |
|
719 return ( bandHeight / lineNumberCount ); |
|
720 } |
|
721 |
|
722 // ----------------------------------------------------------------------------- |
|
723 // CESMRRichTextViewer::LineCount |
|
724 // ----------------------------------------------------------------------------- |
|
725 // |
|
726 EXPORT_C TInt CESMRRichTextViewer::LineCount() |
|
727 { |
|
728 FUNC_LOG; |
|
729 return iNumberOfLines; |
|
730 } |
|
731 // ----------------------------------------------------------------------------- |
|
732 // CESMRRichTextViewer::CurrentLineNumber |
|
733 // ----------------------------------------------------------------------------- |
|
734 // |
|
735 EXPORT_C TInt CESMRRichTextViewer::CurrentLineNumber() |
|
736 { |
|
737 FUNC_LOG; |
|
738 // first line is zero, let's increase it by one |
|
739 return TextLayout()->GetLineNumber( CursorPos() ) + 1; |
|
740 } |
|
741 |
|
742 // ----------------------------------------------------------------------------- |
|
743 // CESMRRichTextViewer::CESMRRichTextViewer |
|
744 // ----------------------------------------------------------------------------- |
|
745 // |
|
746 EXPORT_C void CESMRRichTextViewer::SetActionMenuStatus( TBool aStatus ) |
|
747 { |
|
748 FUNC_LOG; |
|
749 iActionMenuStatus = aStatus; |
|
750 } |
|
751 |
|
752 // ----------------------------------------------------------------------------- |
|
753 // CESMRRichTextViewer::CESMRRichTextViewer |
|
754 // ----------------------------------------------------------------------------- |
|
755 // |
|
756 CESMRRichTextViewer::CESMRRichTextViewer( ) |
|
757 : iActionMenuStatus( ETrue ), iActionMenuOpen( EFalse ) |
|
758 { |
|
759 FUNC_LOG; |
|
760 } |
|
761 |
|
762 // ----------------------------------------------------------------------------- |
|
763 // CESMRRichTextViewer::ConstructL |
|
764 // ----------------------------------------------------------------------------- |
|
765 // |
|
766 void CESMRRichTextViewer::ConstructL(const CCoeControl* aParent) |
|
767 { |
|
768 FUNC_LOG; |
|
769 |
|
770 TInt flags = CEikEdwin::EReadOnly | |
|
771 CEikEdwin::EResizable | |
|
772 CEikEdwin::ENoAutoSelection | |
|
773 CEikEdwin::EAvkonDisableCursor; |
|
774 if( !aParent ) |
|
775 { |
|
776 flags |= CEikEdwin::EOwnsWindow; |
|
777 } |
|
778 |
|
779 CEikRichTextEditor::ConstructL (aParent, 1, 1, flags ); |
|
780 SetSuppressBackgroundDrawing (ETrue ); |
|
781 |
|
782 User::LeaveIfError( |
|
783 NMRBitmapManager::GetSkinBasedBitmap( |
|
784 NMRBitmapManager::EMRBitmapRightClickArrow, iActionMenuIcon, |
|
785 iActionMenuIconMask, KIconSize ) ); |
|
786 |
|
787 iESMRStatic.ConnectL ( ); |
|
788 iCntMenuHdlr = &iESMRStatic.ContactMenuHandlerL(); |
|
789 iCurrentLinkIndex = KErrNotFound; |
|
790 iFormatMask.SetAttrib( EAttFontUnderline ); |
|
791 iFormat.iFontPresentation.iUnderline = EUnderlineOn; |
|
792 iFormatMask.SetAttrib( EAttColor ); |
|
793 iFormat.iFontPresentation.iTextColor = KRgbBlue; |
|
794 |
|
795 iLongTapDetector = CAknLongTapDetector::NewL(this); |
|
796 } |
|
797 |
|
798 // ----------------------------------------------------------------------------- |
|
799 // CESMRRichTextViewer::Draw |
|
800 // ----------------------------------------------------------------------------- |
|
801 // |
|
802 void CESMRRichTextViewer::Draw( const TRect& aRect ) const |
|
803 { |
|
804 FUNC_LOG; |
|
805 CEikEdwin::Draw( aRect ); |
|
806 if (IsFocused ( ) && iActionMenuStatus ) |
|
807 { |
|
808 const CESMRRichTextLink* link = GetSelectedLink ( ); |
|
809 if (link && link->TriggerKey ( )== CESMRRichTextLink::ETriggerKeyRight ) |
|
810 { |
|
811 TRAP_IGNORE(DrawRightClickIconL(*link)); |
|
812 } |
|
813 } |
|
814 } |
|
815 |
|
816 // ----------------------------------------------------------------------------- |
|
817 // CESMRRichTextViewer::DrawRightClickIconL |
|
818 // ----------------------------------------------------------------------------- |
|
819 // |
|
820 void CESMRRichTextViewer::DrawRightClickIconL( |
|
821 const CESMRRichTextLink& aLink ) const |
|
822 { |
|
823 FUNC_LOG; |
|
824 TTmDocPosSpec posSpec; |
|
825 TTmPosInfo2 posInfo; |
|
826 |
|
827 posSpec.iPos = aLink.StartPos ( )+ aLink.Length ( ); |
|
828 posSpec.iType = TTmDocPosSpec::ETrailing; |
|
829 |
|
830 if (TextView()->FindDocPosL (posSpec, posInfo ) ) |
|
831 { |
|
832 TPoint pt = posInfo.iEdge; |
|
833 pt -= iActionMenuIcon->SizeInPixels ( ); |
|
834 |
|
835 pt.iY = pt.iY + KArrowUpperMargin; |
|
836 pt.iX = Parent()->Rect().iBr.iX - |
|
837 iActionMenuIcon->SizeInPixels().iWidth - KArrowRightMargin; |
|
838 TRect dst(pt, iActionMenuIcon->SizeInPixels ( )); |
|
839 TRect src(TPoint (0, 0 ), iActionMenuIcon->SizeInPixels ( )); |
|
840 |
|
841 CWindowGc& gc = SystemGc ( ); |
|
842 gc.DrawBitmapMasked (dst, iActionMenuIcon, src, iActionMenuIconMask, |
|
843 EFalse ); |
|
844 } |
|
845 } |
|
846 |
|
847 // ----------------------------------------------------------------------------- |
|
848 // CESMRRichTextViewer::HighlightLink |
|
849 // ----------------------------------------------------------------------------- |
|
850 // |
|
851 void CESMRRichTextViewer::HighlightLink(const CESMRRichTextLink& aLink ) |
|
852 { |
|
853 FUNC_LOG; |
|
854 TInt error = KErrNone; |
|
855 TCursorSelection selection( aLink.StartPos(), aLink.StartPos() + aLink.Length() ); |
|
856 |
|
857 // If TextView is not constructed yet. |
|
858 if ( !TextView() ) |
|
859 { |
|
860 TRAP( error, SetSelectionL( selection.iCursorPos, selection.iAnchorPos ) ); |
|
861 } |
|
862 else |
|
863 { |
|
864 TextView()->SetPendingSelection( selection ); |
|
865 } |
|
866 |
|
867 if ( error == KErrNone ) |
|
868 { |
|
869 TRAP( error, SetValueL( aLink ) ); |
|
870 if ( error != KErrNone ) |
|
871 { |
|
872 CEikonEnv::Static()->// codescanner::eikonenvstatic |
|
873 HandleError( error ); |
|
874 } |
|
875 } |
|
876 } |
|
877 |
|
878 // ----------------------------------------------------------------------------- |
|
879 // CESMRRichTextViewer::SetValueL |
|
880 // ----------------------------------------------------------------------------- |
|
881 // |
|
882 void CESMRRichTextViewer::SetValueL( const CESMRRichTextLink& aLink ) |
|
883 { |
|
884 FUNC_LOG; |
|
885 // Instantiate contact action menu for selected link |
|
886 switch ( aLink.Type() ) |
|
887 { |
|
888 case CESMRRichTextLink::ETypeEmail: |
|
889 { |
|
890 iCntMenuHdlr->SetValueL( aLink.Value(), |
|
891 CESMRContactMenuHandler::EValueTypeEmail ); |
|
892 break; |
|
893 } |
|
894 case CESMRRichTextLink::ETypePhoneNumber: |
|
895 { |
|
896 iCntMenuHdlr->SetValueL( aLink.Value(), |
|
897 CESMRContactMenuHandler::EValueTypePhoneNumber ); |
|
898 break; |
|
899 } |
|
900 case CESMRRichTextLink::ETypeURL: |
|
901 { |
|
902 iCntMenuHdlr->SetValueL( aLink.Value(), |
|
903 CESMRContactMenuHandler::EValueTypeURL ); |
|
904 break; |
|
905 } |
|
906 case CESMRRichTextLink::ETypeAttachment: |
|
907 { |
|
908 // Set this as command observer. |
|
909 // Commands from contact menu handler are |
|
910 // processed in ProcessCommandL and forwarded |
|
911 // as field command events |
|
912 // <cmail> |
|
913 //iCntMenuHdlr->SetCommandObserver( this ); |
|
914 // </cmail> |
|
915 iCntMenuHdlr->SetValueL( aLink.Value(), |
|
916 CESMRContactMenuHandler::EValueTypeAttachment ); |
|
917 break; |
|
918 } |
|
919 default: |
|
920 { |
|
921 break; |
|
922 } |
|
923 } |
|
924 } |
|
925 |
|
926 // ----------------------------------------------------------------------------- |
|
927 // CESMRRichTextViewer::SearchLinksL |
|
928 // ----------------------------------------------------------------------------- |
|
929 // |
|
930 void CESMRRichTextViewer::SearchLinksL(const TDesC& aText ) |
|
931 { |
|
932 FUNC_LOG; |
|
933 // Search for emails, phone numbers and urls |
|
934 TInt searchCases = CFindItemEngine::EFindItemSearchMailAddressBin | |
|
935 CFindItemEngine::EFindItemSearchPhoneNumberBin | |
|
936 CFindItemEngine::EFindItemSearchURLBin; |
|
937 |
|
938 CFindItemEngine* itemEngine = |
|
939 CFindItemEngine::NewL ( aText, |
|
940 ( CFindItemEngine::TFindItemSearchCase ) searchCases ); |
|
941 CleanupStack::PushL (itemEngine ); |
|
942 |
|
943 const CArrayFixFlat<CFindItemEngine::SFoundItem> |
|
944 * foundItems = itemEngine->ItemArray ( ); |
|
945 |
|
946 // For each found item |
|
947 for (TInt i=0; i<foundItems->Count ( ); ++i ) |
|
948 { |
|
949 // iItemType, iStartPos, iLength |
|
950 const CFindItemEngine::SFoundItem& item = foundItems->At (i ); |
|
951 HBufC* valueBuf = aText.Mid (item.iStartPos, item.iLength ).AllocL ( ); |
|
952 CleanupStack::PushL (valueBuf ); |
|
953 |
|
954 CESMRRichTextLink::TType type = (CESMRRichTextLink::TType) -1; |
|
955 switch (item.iItemType ) |
|
956 { |
|
957 case CFindItemEngine::EFindItemSearchMailAddressBin: |
|
958 { |
|
959 type = CESMRRichTextLink::ETypeEmail; |
|
960 break; |
|
961 } |
|
962 case CFindItemEngine::EFindItemSearchPhoneNumberBin: |
|
963 { |
|
964 type = CESMRRichTextLink::ETypePhoneNumber; |
|
965 |
|
966 // Remove unsupported characters from phone number |
|
967 TPtr phonePtr = valueBuf->Des ( ); |
|
968 CommonPhoneParser::ParsePhoneNumber (phonePtr, |
|
969 CommonPhoneParser::EContactCardNumber ); |
|
970 break; |
|
971 } |
|
972 case CFindItemEngine::EFindItemSearchURLBin: |
|
973 { |
|
974 type = CESMRRichTextLink::ETypeURL; |
|
975 break; |
|
976 } |
|
977 default: |
|
978 { |
|
979 break; |
|
980 } |
|
981 } |
|
982 |
|
983 if (valueBuf->Length ( )> 0 && type >= 0 ) |
|
984 { |
|
985 CESMRRichTextLink* link = CESMRRichTextLink::NewL (item.iStartPos, |
|
986 item.iLength, *valueBuf, type, |
|
987 CESMRRichTextLink::ETriggerKeyRight ); |
|
988 CleanupStack::PushL( link ); |
|
989 AddLinkL( link ); |
|
990 CleanupStack::Pop( link ); |
|
991 } |
|
992 |
|
993 CleanupStack::PopAndDestroy (valueBuf ); |
|
994 } |
|
995 |
|
996 // T |
|
997 HandleTextChangedL(); |
|
998 |
|
999 CleanupStack::PopAndDestroy (itemEngine ); |
|
1000 } |
|
1001 |
|
1002 // ----------------------------------------------------------------------------- |
|
1003 // CESMRRichTextViewer::CopyCurrentLinkToClipBoardL |
|
1004 // ----------------------------------------------------------------------------- |
|
1005 EXPORT_C void CESMRRichTextViewer::CopyCurrentLinkToClipBoardL() const |
|
1006 { |
|
1007 FUNC_LOG; |
|
1008 const CESMRRichTextLink* link = GetSelectedLink(); |
|
1009 |
|
1010 if( link ) |
|
1011 { |
|
1012 HBufC* clipBoardText = GetLinkTextL(*link); |
|
1013 |
|
1014 if ( clipBoardText ) |
|
1015 { |
|
1016 CleanupStack::PushL( clipBoardText ); |
|
1017 CClipboard* cb = |
|
1018 CClipboard::NewForWritingLC( CCoeEnv::Static()->FsSession() ); |
|
1019 cb->StreamDictionary().At( KClipboardUidTypePlainText ); |
|
1020 CPlainText* plainText = CPlainText::NewL(); |
|
1021 CleanupStack::PushL( plainText ); |
|
1022 plainText->InsertL( 0 , *clipBoardText); |
|
1023 plainText->CopyToStoreL( cb->Store(), |
|
1024 cb->StreamDictionary(), 0, plainText->DocumentLength()); |
|
1025 CleanupStack::PopAndDestroy( plainText ); |
|
1026 cb->CommitL(); |
|
1027 CleanupStack::PopAndDestroy( cb ); |
|
1028 CleanupStack::PopAndDestroy( clipBoardText ); |
|
1029 } |
|
1030 } |
|
1031 } |
|
1032 |
|
1033 // ----------------------------------------------------------------------------- |
|
1034 // CESMRRichTextViewer::CopyCurrentLinkValueToClipBoardL |
|
1035 // ----------------------------------------------------------------------------- |
|
1036 EXPORT_C void CESMRRichTextViewer::CopyCurrentLinkValueToClipBoardL() const |
|
1037 { |
|
1038 FUNC_LOG; |
|
1039 const CESMRRichTextLink* link = GetSelectedLink(); |
|
1040 |
|
1041 if( link ) |
|
1042 { |
|
1043 TDesC& clipBoardText = link->Value(); |
|
1044 |
|
1045 CClipboard* cb = |
|
1046 CClipboard::NewForWritingLC( CCoeEnv::Static()->FsSession() ); |
|
1047 cb->StreamDictionary().At( KClipboardUidTypePlainText ); |
|
1048 CPlainText* plainText = CPlainText::NewL(); |
|
1049 CleanupStack::PushL( plainText ); |
|
1050 plainText->InsertL( 0 , clipBoardText); |
|
1051 plainText->CopyToStoreL( cb->Store(), |
|
1052 cb->StreamDictionary(), 0, plainText->DocumentLength()); |
|
1053 CleanupStack::PopAndDestroy( plainText ); |
|
1054 cb->CommitL(); |
|
1055 CleanupStack::PopAndDestroy( cb ); |
|
1056 } |
|
1057 } |
|
1058 |
|
1059 |
|
1060 // ----------------------------------------------------------------------------- |
|
1061 // CESMRRichTextViewer::ResetActionMenu |
|
1062 // ----------------------------------------------------------------------------- |
|
1063 EXPORT_C void CESMRRichTextViewer::ResetActionMenuL() const // codescanner::LFunctionCantLeave |
|
1064 { |
|
1065 FUNC_LOG; |
|
1066 if(iCntMenuHdlr) |
|
1067 { |
|
1068 iCntMenuHdlr->Reset(); |
|
1069 } |
|
1070 } |
|
1071 |
|
1072 // ----------------------------------------------------------------------------- |
|
1073 // CESMRRichTextViewer::SetEventObserver |
|
1074 // ----------------------------------------------------------------------------- |
|
1075 // |
|
1076 EXPORT_C void CESMRRichTextViewer::SetEventQueue( |
|
1077 MESMRFieldEventQueue* aEventQueue ) |
|
1078 { |
|
1079 FUNC_LOG; |
|
1080 iEventQueue = aEventQueue; |
|
1081 } |
|
1082 |
|
1083 // ----------------------------------------------------------------------------- |
|
1084 // CESMRRichTextViewer::LinkSelectedL |
|
1085 // ----------------------------------------------------------------------------- |
|
1086 // |
|
1087 EXPORT_C TBool CESMRRichTextViewer::LinkSelectedL() |
|
1088 { |
|
1089 FUNC_LOG; |
|
1090 TBool linkSelected = EFalse; |
|
1091 |
|
1092 const CESMRRichTextLink* link = GetSelectedLink(); |
|
1093 if ( link ) |
|
1094 { |
|
1095 iActionMenuOpen = ETrue; |
|
1096 switch ( link->TriggerKey() ) |
|
1097 { |
|
1098 case CESMRRichTextLink::ETriggerKeyRight: |
|
1099 { |
|
1100 if ( !iLinkObserver || |
|
1101 !iLinkObserver->HandleRichTextLinkSelection(link) ) |
|
1102 { |
|
1103 iCntMenuHdlr->ShowActionMenuL(); |
|
1104 } |
|
1105 linkSelected = ETrue; |
|
1106 break; |
|
1107 } |
|
1108 case CESMRRichTextLink::ETriggerKeyOk: |
|
1109 { |
|
1110 if (iLinkObserver && |
|
1111 iLinkObserver->HandleRichTextLinkSelection (link ) ) |
|
1112 { |
|
1113 linkSelected = ETrue; |
|
1114 } |
|
1115 break; |
|
1116 } |
|
1117 default: |
|
1118 { |
|
1119 break; |
|
1120 } |
|
1121 } |
|
1122 iActionMenuOpen = EFalse; |
|
1123 } |
|
1124 |
|
1125 return linkSelected; |
|
1126 } |
|
1127 |
|
1128 |
|
1129 // ----------------------------------------------------------------------------- |
|
1130 // CESMRRichTextViewer::ProcessCommandL |
|
1131 // ----------------------------------------------------------------------------- |
|
1132 // |
|
1133 void CESMRRichTextViewer::ProcessCommandL( TInt aCommandId ) |
|
1134 { |
|
1135 FUNC_LOG; |
|
1136 if ( iEventQueue ) |
|
1137 { |
|
1138 // Forward commands from contact menu handler as command events. |
|
1139 // Contact menu handler has the command observer for binary |
|
1140 // compatibility reason. |
|
1141 CESMRFieldCommandEvent* event = |
|
1142 CESMRFieldCommandEvent::NewLC( NULL, aCommandId ); |
|
1143 iEventQueue->NotifyEventL( *event ); |
|
1144 CleanupStack::PopAndDestroy( event ); |
|
1145 } |
|
1146 } |
|
1147 |
|
1148 // ----------------------------------------------------------------------------- |
|
1149 // CESMRRichTextViewer::ActivateL |
|
1150 // ----------------------------------------------------------------------------- |
|
1151 // |
|
1152 void CESMRRichTextViewer::ActivateL() |
|
1153 { |
|
1154 FUNC_LOG; |
|
1155 CEikRichTextEditor::ActivateL(); |
|
1156 |
|
1157 // Make sure correct font color is in use. |
|
1158 SetFontColorL( IsFocused() ); |
|
1159 |
|
1160 // CEikEdwin::ActivateL removes selection, re-set highlight |
|
1161 // if focused and there's a selected link. |
|
1162 if ( IsFocused() && GetSelectedLink() ) |
|
1163 { |
|
1164 HighlightLink( *GetSelectedLink() ); |
|
1165 DrawDeferred(); |
|
1166 } |
|
1167 } |
|
1168 |
|
1169 // ----------------------------------------------------------------------------- |
|
1170 // CESMRRichTextViewer::HandlePointerEventL |
|
1171 // ----------------------------------------------------------------------------- |
|
1172 // |
|
1173 void CESMRRichTextViewer::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
1174 { |
|
1175 TBool linkTapped( EFalse ); |
|
1176 CESMRRichTextLink* link = NULL; |
|
1177 // fetch the current line number: |
|
1178 TInt currentLineNumber = TextLayout()->GetLineNumber( CursorPos() ); |
|
1179 // find out tapped position |
|
1180 TPoint touchPoint = aPointerEvent.iPosition; |
|
1181 |
|
1182 TInt tappedPos = TextView()->XyPosToDocPosL( touchPoint ); |
|
1183 for (TInt i = 0; i<iLinkList.Count(); i++) |
|
1184 { |
|
1185 link = iLinkList[ i ]; |
|
1186 TInt linkStart = link->StartPos(); |
|
1187 TInt linkEnd = link->StartPos() + link->Length() - 1; |
|
1188 if ( tappedPos >= linkStart && tappedPos <= linkEnd ) |
|
1189 { |
|
1190 // link tapped |
|
1191 linkTapped = ETrue; |
|
1192 iCurrentLinkIndex = i; |
|
1193 break; |
|
1194 } |
|
1195 } |
|
1196 |
|
1197 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
1198 { |
|
1199 if ( linkTapped ) |
|
1200 { |
|
1201 // tactile feedback |
|
1202 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
1203 if ( feedback ) |
|
1204 { |
|
1205 feedback->InstantFeedback( this, ETouchFeedbackBasic ); |
|
1206 } |
|
1207 |
|
1208 TPointerEvent pointerEvent = aPointerEvent; |
|
1209 pointerEvent.iParentPosition = pointerEvent.iPosition |
|
1210 + DrawableWindow()->AbsPosition(); |
|
1211 iLongTapDetector->PointerEventL( pointerEvent ); |
|
1212 HighlightLink( *link ); |
|
1213 if ( Parent() ) |
|
1214 { |
|
1215 Parent()->DrawDeferred(); |
|
1216 } |
|
1217 else |
|
1218 { |
|
1219 DrawDeferred(); |
|
1220 } |
|
1221 } |
|
1222 } |
|
1223 else |
|
1224 { |
|
1225 TPointerEvent pointerEvent = aPointerEvent; |
|
1226 pointerEvent.iParentPosition = pointerEvent.iPosition |
|
1227 + DrawableWindow()->AbsPosition(); |
|
1228 iLongTapDetector->PointerEventL( pointerEvent ); |
|
1229 |
|
1230 if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
1231 { |
|
1232 if ( linkTapped && !iActionMenuOpen ) |
|
1233 { |
|
1234 // tapped highlighted field, execute action |
|
1235 LinkSelectedL(); |
|
1236 } |
|
1237 } |
|
1238 } |
|
1239 } |
|
1240 |
|
1241 // ----------------------------------------------------------------------------- |
|
1242 // CESMRRichTextViewer::HandleLongTapEventL |
|
1243 // ----------------------------------------------------------------------------- |
|
1244 // |
|
1245 void CESMRRichTextViewer::HandleLongTapEventL( const TPoint& /*aPenEventLocation*/, |
|
1246 const TPoint& /*aPenEventScreenLocation*/ ) |
|
1247 { |
|
1248 if ( !iActionMenuOpen ) |
|
1249 { |
|
1250 LinkSelectedL(); |
|
1251 } |
|
1252 } |
|
1253 // EOF |
|
1254 |