217 // --------------------------------------------------------------------------- |
217 // --------------------------------------------------------------------------- |
218 // constructor/destructor |
218 // constructor/destructor |
219 // --------------------------------------------------------------------------- |
219 // --------------------------------------------------------------------------- |
220 // |
220 // |
221 CNcsAifEditor::CNcsAifEditor( |
221 CNcsAifEditor::CNcsAifEditor( |
222 MNcsFieldSizeObserver* aSizeObserver ) |
222 MNcsFieldSizeObserver* aSizeObserver, const TDesC& aCaptionText ) |
223 : CNcsEditor( aSizeObserver, ETrue, ENcsEditorAddress ), iAddressPopupList( NULL ), |
223 : CNcsEditor( aSizeObserver, ETrue, ENcsEditorAddress, aCaptionText ), iAddressPopupList( NULL ), |
224 iAddLeftover( ETrue ) |
224 iAddLeftover( ETrue ) |
225 { |
225 { |
226 FUNC_LOG; |
226 FUNC_LOG; |
227 SetEdwinObserver( this ); |
227 SetEdwinObserver( this ); |
228 } |
228 } |
373 // causes problems for the FEP in some special cases. |
373 // causes problems for the FEP in some special cases. |
374 HandleTextUpdateDeferred(); |
374 HandleTextUpdateDeferred(); |
375 } |
375 } |
376 else if ( aEventType == MEikEdwinObserver::EEventNavigation ) |
376 else if ( aEventType == MEikEdwinObserver::EEventNavigation ) |
377 { |
377 { |
|
378 iTextSelection = Selection(); |
378 HandleNavigationEventL(); |
379 HandleNavigationEventL(); |
379 } |
380 } |
380 } |
381 } |
381 |
382 |
382 // ----------------------------------------------------------------------------- |
383 // ----------------------------------------------------------------------------- |
394 // Moving to a new line is a special case. |
395 // Moving to a new line is a special case. |
395 // We need to offer the key to the editor control first so it can |
396 // We need to offer the key to the editor control first so it can |
396 // move the cursor for us. Then we check if it's in an entry. |
397 // move the cursor for us. Then we check if it's in an entry. |
397 if ( aKeyEvent.iCode == EKeyUpArrow || aKeyEvent.iCode == EKeyDownArrow ) |
398 if ( aKeyEvent.iCode == EKeyUpArrow || aKeyEvent.iCode == EKeyDownArrow ) |
398 { |
399 { |
399 // make sure there is really some text inputted |
400 CompleteEntryL(); |
400 TInt cursorPos( CursorPos() ); |
|
401 |
|
402 TCursorSelection selection = NonEntryTextAtPos( cursorPos ); |
|
403 |
|
404 TInt length( selection.Length() ); |
|
405 |
|
406 HBufC* text = HBufC::NewLC( length ); |
|
407 TPtr ptr = text->Des(); |
|
408 |
|
409 if( selection.LowerPos() >= 0 ) |
|
410 { |
|
411 Text()->Extract( ptr, selection.LowerPos(), length ); |
|
412 ptr.Trim(); |
|
413 |
|
414 // complete the entry |
|
415 if( ptr.Length() > 0 ) |
|
416 { |
|
417 Text()->InsertL( selection.HigherPos(), KCharAddressDelimeterSemiColon ); |
|
418 HandleTextChangedL(); |
|
419 HandleTextUpdateL( TCursorSelection(selection.LowerPos(), selection.HigherPos() + 1) ); |
|
420 } |
|
421 } |
|
422 |
|
423 CleanupStack::PopAndDestroy( text ); |
|
424 |
401 |
425 response = CNcsEditor::OfferKeyEventL( aKeyEvent,aType ); |
402 response = CNcsEditor::OfferKeyEventL( aKeyEvent,aType ); |
426 if ( response == EKeyWasConsumed ) |
403 if ( response == EKeyWasConsumed ) |
427 { |
404 { |
428 // We're moving to a new line. |
405 // We're moving to a new line. |
1061 |
1038 |
1062 for ( TInt i = iArray.Count() - 1 ; i >= 0 ; --i ) |
1039 for ( TInt i = iArray.Count() - 1 ; i >= 0 ; --i ) |
1063 { |
1040 { |
1064 TInt matchesInText; |
1041 TInt matchesInText; |
1065 TInt matchesInArray; |
1042 TInt matchesInArray; |
1066 TInt arrayItemCurPos( iArray[i]->LowerPos() ); |
1043 TInt arrayItemLowPos( iArray[i]->LowerPos() ); |
1067 |
1044 TInt arrayItemHighPos( iArray[i]->HigherPos()); |
|
1045 |
1068 GetMatchingEntryCountsL( iArray[i], matchesInText, matchesInArray ); |
1046 GetMatchingEntryCountsL( iArray[i], matchesInText, matchesInArray ); |
1069 |
1047 |
1070 // Entry is removed if: |
1048 // Entry is removed if: |
1071 // a) there's no matches for it in the text, or |
1049 // a) there's no matches for it in the text, or |
1072 // b) there're less matches for it in the text than in array (i.e., |
1050 // b) there're less matches for it in the text than in array (i.e., |
1073 // a duplicate ("foo(at)foo.org; foo(at)foo.org") has just been removed) |
1051 // a duplicate ("foo(at)foo.org; foo(at)foo.org") has just been removed) |
1074 // In b) case the correct duplicate is the one that is in current |
1052 // In b) case the correct duplicate is the one that is in current |
1075 // cursor position (or one off due to possible whitespace). |
1053 // cursor position (or one off due to possible whitespace). |
1076 if ( 0 == matchesInText || |
1054 if ( 0 == matchesInText || |
1077 ( matchesInText < matchesInArray && |
1055 ( matchesInText < matchesInArray ) && |
1078 ( currentCursorPos == arrayItemCurPos || |
1056 ( currentCursorPos >= arrayItemLowPos && |
1079 (1 + currentCursorPos) == arrayItemCurPos ) ) ) |
1057 currentCursorPos <= arrayItemHighPos )) |
1080 { |
1058 { |
1081 delete iArray[i]; |
1059 delete iArray[i]; |
1082 iArray.Remove(i); |
1060 iArray.Remove(i); |
1083 removedEntryIndex = i; |
1061 removedEntryIndex = i; |
|
1062 if ( iTextSelection.iAnchorPos != iTextSelection.iCursorPos && |
|
1063 iTextSelection.HigherPos() < arrayItemHighPos ) |
|
1064 { |
|
1065 iPartialRemove = ETrue; |
|
1066 } |
1084 } |
1067 } |
1085 } |
1068 } |
1086 |
1069 |
1087 if ( KNoEntryRemoved != removedEntryIndex ) |
1070 if ( KNoEntryRemoved != removedEntryIndex ) |
1088 { |
1071 { |
1268 { |
1251 { |
1269 FUNC_LOG; |
1252 FUNC_LOG; |
1270 const TInt entryCount = iArray.Count(); |
1253 const TInt entryCount = iArray.Count(); |
1271 for ( TInt ii = entryCount - 1; ii >= 0; --ii ) |
1254 for ( TInt ii = entryCount - 1; ii >= 0; --ii ) |
1272 { |
1255 { |
1273 TBool duplicateFound = EFalse; |
1256 if ( ii > 0 ) |
1274 for ( TInt jj = ii - 1; jj >= 0; --jj ) |
1257 { |
1275 { |
1258 TBool duplicateFound = EFalse; |
1276 if ( iArray[ii]->IsSameDN( *iArray[jj] ) ) |
1259 for ( TInt jj = ii - 1; jj >= 0; --jj ) |
1277 { |
1260 { |
1278 duplicateFound = ETrue; |
1261 if ( iArray[ii]->IsSameDN( *iArray[jj] ) ) |
1279 iArray[jj]->SetDupL( ETrue ); |
1262 { |
1280 } |
1263 duplicateFound = ETrue; |
1281 } |
1264 iArray[jj]->SetDupL( ETrue ); |
1282 iArray[ii]->SetDupL( duplicateFound ); |
1265 } |
|
1266 } |
|
1267 iArray[ii]->SetDupL( duplicateFound ); |
|
1268 } |
1283 } |
1269 } |
1284 } |
1270 } |
1285 |
1271 |
1286 // --------------------------------------------------------------------------- |
1272 // --------------------------------------------------------------------------- |
1287 // Makes a deferred call to HandleTextUpdateL |
1273 // Makes a deferred call to HandleTextUpdateL |
1330 { |
1316 { |
1331 iAddressPopupList->ClosePopupContactListL(); |
1317 iAddressPopupList->ClosePopupContactListL(); |
1332 |
1318 |
1333 // add line feed after new entry |
1319 // add line feed after new entry |
1334 TInt cursorPos( CursorPos() ); |
1320 TInt cursorPos( CursorPos() ); |
1335 Text()->InsertL( cursorPos, TChar(CEditableText::ELineBreak) ); |
1321 if ( !iPartialRemove ) |
|
1322 { |
|
1323 Text()->InsertL( cursorPos, TChar(CEditableText::ELineBreak) ); |
|
1324 } |
1336 HandleTextChangedL(); |
1325 HandleTextChangedL(); |
1337 SetCursorPosL( cursorPos + 1, EFalse ); |
1326 SetCursorPosL( cursorPos + 1, EFalse ); |
|
1327 iPartialRemove = EFalse; |
1338 } |
1328 } |
1339 else |
1329 else |
1340 { |
1330 { |
1341 UpdateAddressAutoCompletionL( textSelection ); |
1331 UpdateAddressAutoCompletionL( textSelection ); |
1342 } |
1332 } |
1602 ++aNrOfMatchesInEntryArray; |
1592 ++aNrOfMatchesInEntryArray; |
1603 } |
1593 } |
1604 } |
1594 } |
1605 } |
1595 } |
1606 |
1596 |
|
1597 // ----------------------------------------------------------------------------- |
|
1598 // CNcsAifEditor::HandlePointerEventL() |
|
1599 // Handles pointer events |
|
1600 // ----------------------------------------------------------------------------- |
|
1601 // |
|
1602 void CNcsAifEditor::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
|
1603 { |
|
1604 FUNC_LOG; |
|
1605 |
|
1606 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
1607 { |
|
1608 CTextLayout* textLayout = TextLayout(); |
|
1609 TInt cursorPos = CursorPos(); |
|
1610 TPoint touchPoint( aPointerEvent.iPosition ); |
|
1611 |
|
1612 //adjust touch point to mach editor coordinates |
|
1613 touchPoint.iX -= Position().iX; |
|
1614 |
|
1615 TInt pointerLineNbr = textLayout->GetLineNumber( textLayout->XyPosToDocPosL( touchPoint )); |
|
1616 TInt cursorLineNbr = textLayout->GetLineNumber( cursorPos ); |
|
1617 |
|
1618 |
|
1619 if ( pointerLineNbr != cursorLineNbr ) |
|
1620 { |
|
1621 CompleteEntryL(); |
|
1622 |
|
1623 // We're moving to a new line. |
|
1624 CNcsAifEntry* entry = NULL; |
|
1625 entry = GetEntryAt( CursorPos() ); |
|
1626 if ( entry ) |
|
1627 { |
|
1628 SetSelectionL( entry->iCursorPos, entry->iAnchorPos ); |
|
1629 } |
|
1630 } |
|
1631 } |
|
1632 |
|
1633 CEikEdwin::HandlePointerEventL( aPointerEvent ); |
|
1634 } |
|
1635 |
|
1636 |
|
1637 // ----------------------------------------------------------------------------- |
|
1638 // CNcsAifEditor::CompleteEntryL() |
|
1639 // Adds semicolol to the of the entry |
|
1640 // ----------------------------------------------------------------------------- |
|
1641 // |
|
1642 void CNcsAifEditor::CompleteEntryL() |
|
1643 { |
|
1644 // make sure there is really some text inputted |
|
1645 TInt cursorPos( CursorPos() ); |
|
1646 |
|
1647 TCursorSelection selection = NonEntryTextAtPos( cursorPos ); |
|
1648 |
|
1649 TInt length( selection.Length() ); |
|
1650 |
|
1651 HBufC* text = HBufC::NewLC( length ); |
|
1652 TPtr ptr = text->Des(); |
|
1653 |
|
1654 if( selection.LowerPos() >= 0 ) |
|
1655 { |
|
1656 Text()->Extract( ptr, selection.LowerPos(), length ); |
|
1657 ptr.Trim(); |
|
1658 |
|
1659 // complete the entry |
|
1660 if( ptr.Length() > 0 ) |
|
1661 { |
|
1662 Text()->InsertL( selection.HigherPos(), KCharAddressDelimeterSemiColon ); |
|
1663 HandleTextChangedL(); |
|
1664 HandleTextUpdateL( TCursorSelection(selection.LowerPos(), selection.HigherPos() + 1) ); |
|
1665 } |
|
1666 } |
|
1667 |
|
1668 CleanupStack::PopAndDestroy( text ); |
|
1669 } |
1607 // End of File |
1670 // End of File |
1608 |
1671 |