commonuis/CommonUi/src/FindItemDialog.cpp
branchRCL_3
changeset 23 3d340a0166ff
parent 10 9f56a4e1b8ab
child 38 c52421ed5f07
equal deleted inserted replaced
18:0aa5fbdfbc30 23:3d340a0166ff
    93 #include <txtfrmat.h>  // for TCharFormat
    93 #include <txtfrmat.h>  // for TCharFormat
    94 
    94 
    95 #include <aknnavilabel.h> // for changing the lable of navipane
    95 #include <aknnavilabel.h> // for changing the lable of navipane
    96 
    96 
    97 #include <AknTasHook.h> // for testability hooks
    97 #include <AknTasHook.h> // for testability hooks
       
    98 #include <touchfeedback.h>
    98 _LIT( KResFileName, "z:\\resource\\finditemui.rsc" );
    99 _LIT( KResFileName, "z:\\resource\\finditemui.rsc" );
    99 
   100 
   100 // Panic
   101 // Panic
   101 _LIT( KFindItemPanic, "FindItemDialog" );
   102 _LIT( KFindItemPanic, "FindItemDialog" );
   102 // Space for WML Browser's parameter
   103 // Space for WML Browser's parameter
   234     // phonebook to know it can exit    
   235     // phonebook to know it can exit    
   235     return ETrue;
   236     return ETrue;
   236     }    
   237     }    
   237 
   238 
   238 NONSHARABLE_CLASS(CItemFinderExtension) : public CBase
   239 NONSHARABLE_CLASS(CItemFinderExtension) : public CBase
   239 	{
   240     {
   240 public: 
   241 public: 
   241 	~CItemFinderExtension(); 
   242     ~CItemFinderExtension(); 
   242 	static CItemFinderExtension* NewL(); 
   243     static CItemFinderExtension* NewL(); 
   243 	
   244 
   244 	//new function
   245     //new function
   245 public:
   246 public:
   246 	PBAiwNotify* CallBack();
   247     PBAiwNotify* CallBack();
   247 	
   248 
   248 private: 
   249 private: 
   249 	CItemFinderExtension(); 
   250     CItemFinderExtension(); 
   250 	void ConstructL();	
   251     void ConstructL();	
   251 	
   252 
   252 public:
   253 public:
   253 	PBAiwNotify iCallBack;
   254     PBAiwNotify iCallBack;
   254 	};
   255     };
   255 
   256 
   256 CItemFinderExtension::~CItemFinderExtension()
   257 CItemFinderExtension::~CItemFinderExtension()
   257 	{
   258     {
   258 	
   259     }
   259 	}
       
   260 
   260 
   261 CItemFinderExtension* CItemFinderExtension::NewL()
   261 CItemFinderExtension* CItemFinderExtension::NewL()
   262 	{
   262     {
   263 	CItemFinderExtension* self = new ( ELeave )CItemFinderExtension;
   263     CItemFinderExtension* self = new ( ELeave )CItemFinderExtension;
   264 	CleanupStack::PushL(self);
   264     CleanupStack::PushL(self);
   265 	self->ConstructL();
   265     self->ConstructL();
   266 	CleanupStack::Pop();
   266     CleanupStack::Pop();
   267 	return self;
   267     return self;
   268 	}
   268     }
   269 
   269 
   270 PBAiwNotify* CItemFinderExtension::CallBack()
   270 PBAiwNotify* CItemFinderExtension::CallBack()
   271 	{
   271     {
   272 	return &iCallBack;
   272     return &iCallBack;
   273 	}
   273     }
   274 
   274 
   275 CItemFinderExtension::CItemFinderExtension()
   275 CItemFinderExtension::CItemFinderExtension()
   276 	{
   276     {
   277 	
   277 
   278 	}
   278     }
   279 
   279 
   280 void CItemFinderExtension::ConstructL()
   280 void CItemFinderExtension::ConstructL()
   281 	{
   281     {
   282 	
   282 
   283 	}
   283     }
   284 
   284 
   285 
   285 
   286 
   286 
   287 // ================= MEMBER FUNCTIONS =======================
   287 // ================= MEMBER FUNCTIONS =======================
   288 
   288 
   455         FeatureManager::FeatureSupported( KFeatureIdEmailUi );
   455         FeatureManager::FeatureSupported( KFeatureIdEmailUi );
   456 
   456 
   457     iFindItemVoIPExtension = CFindItemVoIPExtension::NewL();
   457     iFindItemVoIPExtension = CFindItemVoIPExtension::NewL();
   458     
   458     
   459     iExtension = CItemFinderExtension::NewL();
   459     iExtension = CItemFinderExtension::NewL();
   460     }
   460     iFeedback = MTouchFeedback::Instance();
   461 
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CFindItemDialog::HandlePointerEventL
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 void CFindItemDialog::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   468     {
       
   469     if ( !iSingleClick )
       
   470         {
       
   471         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   472             {
       
   473             this->PointerEvent( NULL, aPointerEvent );
       
   474             }
       
   475         }
       
   476     else
       
   477         {
       
   478         DoHandlePointerEventL( aPointerEvent );
       
   479         if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   480             {
       
   481             iEdwin->ClearSelectionL();
       
   482             iEdwin->DrawDeferred();
       
   483             }
       
   484         }
       
   485     }
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // CFindItemDialog::DoHandlePointerEventL
       
   489 // -----------------------------------------------------------------------------
       
   490 //
       
   491 void CFindItemDialog::DoHandlePointerEventL ( const TPointerEvent& aPointerEvent )
       
   492     {
       
   493     if ( aPointerEvent.iType == TPointerEvent::EButton1Up ||
       
   494              aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   495         {
       
   496         TPoint tapPoint( aPointerEvent.iPosition - iTappingOffset );
       
   497         TInt pos = 0;
       
   498         TInt len = iEdwin->TextLayout()->PosRangeInBand( pos );
       
   499         CFindItemEngine::SFoundItem item;
       
   500         TRect rect;
       
   501         TInt i = 0;
       
   502         while ( i < iController->ItemCount() ) // Check visible rects
       
   503             {
       
   504             if ( !iController->Item( i, item ) ) // Get item.
       
   505                 {
       
   506                 break; // Error: invalid item.
       
   507                 }
       
   508             TInt end = item.iStartPos + item.iLength - 1;
       
   509             if ( end < pos )
       
   510                 {
       
   511                 i++;
       
   512                 continue; // item not visible.
       
   513                 }
       
   514             TInt start = item.iStartPos;
       
   515             if ( start >= ( pos + len ) )
       
   516                 {
       
   517                 break; // item not visible.
       
   518                 }
       
   519             TInt lastLine = iEdwin->TextLayout()->GetLineNumber( end );
       
   520             TInt nextLine = 0;
       
   521             TInt lastPos = start;
       
   522             do // Check all rects of one item.
       
   523                 {
       
   524                 TInt error = KErrNone;
       
   525                 TRAP( error, rect =
       
   526                         iEdwin->TextLayout()->GetLineRectL( start, end ) );
       
   527                 if ( error == KErrNone )
       
   528                     {
       
   529                     if ( rect.Contains( tapPoint ) ) // Item rect tapped.
       
   530                         {
       
   531                         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   532                             {
       
   533                             TRAP( error, iController->TappedItemL( i ) );
       
   534                             // Change selection
       
   535                             if ( error != KErrNone )
       
   536                                 {
       
   537                                 return; // Error: no selection made.
       
   538                                 }
       
   539                             if ( iFeedback )
       
   540                                 {
       
   541                                 iFeedback->InstantFeedback( ETouchFeedbackBasicButton );	
       
   542                                 }
       
   543                             iLastTappedItem = TPoint ( item.iStartPos, item.iLength
       
   544                                 + item.iStartPos );
       
   545                             return; // Hit, no further handling.
       
   546                             }
       
   547                         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   548                             {
       
   549                             if ( iLastTappedItem == TPoint ( item.iStartPos,
       
   550                                 item.iLength + item.iStartPos ) )
       
   551                                 {
       
   552                                 iIsSensitiveMenu = ETrue;
       
   553                                 iMenuBar->SetMenuType( CEikMenuBar::EMenuContext );
       
   554                                 TRAP_IGNORE( CAknDialog::DisplayMenuL() );
       
   555                                 }
       
   556                             return; // Hit, no further handling.
       
   557                             }
       
   558                         }
       
   559                     }
       
   560                 else
       
   561                     {
       
   562                     return; // Error: no rect.
       
   563                     }
       
   564                 TPoint midPoint( rect.iBr.iX,
       
   565                         ( rect.iBr.iY + rect.iTl.iY ) / 2 );
       
   566                 TRAP( error, lastPos =
       
   567                         iEdwin->TextLayout()->XyPosToDocPosL( midPoint ) );
       
   568                 if ( error != KErrNone )
       
   569                     {
       
   570                     return; // Error: no last pos.
       
   571                     }
       
   572                 start = lastPos + 1;
       
   573                 nextLine = iEdwin->TextLayout()->GetLineNumber( lastPos );
       
   574                 } while ( nextLine != lastLine );
       
   575             i++;
       
   576             }
       
   577         }
       
   578     return;   // No hit, no further handling.
       
   579     }
   462 
   580 
   463 // -----------------------------------------------------------------------------
   581 // -----------------------------------------------------------------------------
   464 // CFindItemDialog::DoCopyToClipboardL
   582 // CFindItemDialog::DoCopyToClipboardL
   465 //  Copies the selected item to EPOC clipboard
   583 //  Copies the selected item to EPOC clipboard
   466 // -----------------------------------------------------------------------------
   584 // -----------------------------------------------------------------------------
   824 
   942 
   825     CleanupStack::PopAndDestroy( 4 );   // magBuffer, db, sess, item
   943     CleanupStack::PopAndDestroy( 4 );   // magBuffer, db, sess, item
   826     }
   944     }
   827 
   945 
   828 // -----------------------------------------------------------------------------
   946 // -----------------------------------------------------------------------------
       
   947 // CFindItemDialog::EnableSingleClick
       
   948 // -----------------------------------------------------------------------------
       
   949 //
       
   950 EXPORT_C void CFindItemDialog::EnableSingleClick ( TBool aEnable )
       
   951     {
       
   952     iSingleClick = aEnable;
       
   953     }
       
   954 
   829 // CFindItemDialog::ProcessCommandL
   955 // CFindItemDialog::ProcessCommandL
   830 //  Prosesses menu commands
   956 //  Prosesses menu commands
   831 // -----------------------------------------------------------------------------
   957 // -----------------------------------------------------------------------------
   832 //
   958 //
   833 EXPORT_C void CFindItemDialog::ProcessCommandL( TInt aCommandId )
   959 EXPORT_C void CFindItemDialog::ProcessCommandL( TInt aCommandId )
   834     {
   960     {
       
   961     TBool selectionVisibility ( ETrue );
       
   962     if ( iSingleClick && iEdwin && iEdwin->TextView() )
       
   963         {
       
   964         selectionVisibility = iEdwin->TextView()->SelectionVisible();
       
   965         iEdwin->TextView()->SetSelectionVisibilityL( EFalse );
       
   966 
       
   967         CFindItemEngine::SFoundItem item;
       
   968         TBool founditem = iController->Item( item );
       
   969         if ( founditem )
       
   970             {
       
   971             iEdwin->SetSelectionL( item.iStartPos, item.iStartPos + item.iLength );
       
   972             }
       
   973         else
       
   974             {
       
   975             iEdwin->SetSelectionL( iLastTappedItem.iX, iLastTappedItem.iY );
       
   976             }
       
   977         }
       
   978 
   835     CAknDialog::ProcessCommandL( aCommandId );
   979     CAknDialog::ProcessCommandL( aCommandId );
   836     switch (aCommandId)
   980     switch (aCommandId)
   837         {
   981         {
   838         // General cmds
   982         // General cmds
   839         case EFindItemCmdNextItem:
   983         case EFindItemCmdNextItem:
   888            mtmFilter->AppendL(KSenduiMtmPostcardUid);// hide postcard
  1032            mtmFilter->AppendL(KSenduiMtmPostcardUid);// hide postcard
   889            // Hide MMs
  1033            // Hide MMs
   890            #ifndef RD_UNIFIED_EDITOR
  1034            #ifndef RD_UNIFIED_EDITOR
   891            if( !iMMSFeatureSupported )
  1035            if( !iMMSFeatureSupported )
   892                {
  1036                {
   893            	   mtmFilter->AppendL(KSenduiMtmMmsUid);
  1037                mtmFilter->AppendL(KSenduiMtmMmsUid);
   894                }
  1038                }
   895            #endif
  1039            #endif
   896            
  1040            
   897            // Hide Sms
  1041            // Hide Sms
   898            if ( iSearchCase == CFindItemEngine::EFindItemSearchMailAddressBin ||
  1042            if ( iSearchCase == CFindItemEngine::EFindItemSearchMailAddressBin ||
   913                ( iSearchCase == CFindItemEngine::EFindItemSearchPhoneNumberBin ||
  1057                ( iSearchCase == CFindItemEngine::EFindItemSearchPhoneNumberBin ||
   914                ( iFindItemVoIPExtension->IsVoIPSupported() && founditem &&
  1058                ( iFindItemVoIPExtension->IsVoIPSupported() && founditem &&
   915                    item.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin &&
  1059                    item.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin &&
   916                    iSearchCase == KSearchTelInternetNumber ) ) )
  1060                    iSearchCase == KSearchTelInternetNumber ) ) )
   917                {
  1061                {
   918        	       mtmFilter->AppendL(KSenduiMtmSmtpUid);
  1062                mtmFilter->AppendL(KSenduiMtmSmtpUid);
   919                mtmFilter->AppendL(KSenduiMtmImap4Uid);
  1063                mtmFilter->AppendL(KSenduiMtmImap4Uid);
   920                mtmFilter->AppendL(KSenduiMtmPop3Uid);
  1064                mtmFilter->AppendL(KSenduiMtmPop3Uid);
   921                mtmFilter->AppendL(KSenduiMtmSyncMLEmailUid);
  1065                mtmFilter->AppendL(KSenduiMtmSyncMLEmailUid);
   922                }
  1066                }
   923            // Hide Audio
  1067            // Hide Audio
   941            }
  1085            }
   942         case EFindItemCmdGoToUrl:
  1086         case EFindItemCmdGoToUrl:
   943             {
  1087             {
   944             if ( LaunchGenericUriL() )
  1088             if ( LaunchGenericUriL() )
   945                 {
  1089                 {
       
  1090                 if ( iSingleClick && iEdwin && iEdwin->TextView() )
       
  1091                     {
       
  1092                     iEdwin->TextView()->SetSelectionVisibilityL( selectionVisibility );
       
  1093                     iEdwin->ClearSelectionL();
       
  1094                     iEdwin->DrawDeferred();
       
  1095                     }
   946                 return;
  1096                 return;
   947                 }
  1097                 }
   948             break;
  1098             break;
   949             }
  1099             }
   950         case EFindItemCmdAddToBookmark:
  1100         case EFindItemCmdAddToBookmark:
  1012                 }
  1162                 }
  1013 #endif // RD_VIRTUAL_PHONEBOOK
  1163 #endif // RD_VIRTUAL_PHONEBOOK
  1014             break;
  1164             break;
  1015             }
  1165             }
  1016         }
  1166         }
       
  1167     if ( iSingleClick && iEdwin && iEdwin->TextView() )
       
  1168         {
       
  1169         iEdwin->TextView()->SetSelectionVisibilityL( selectionVisibility );
       
  1170         if ( aCommandId != EFindItemCmdNextItem && aCommandId != EFindItemCmdPrevItem )
       
  1171             {
       
  1172             iEdwin->ClearSelectionL();
       
  1173             }
       
  1174         iEdwin->DrawDeferred();
       
  1175         }
  1017     }
  1176     }
  1018 
  1177 
  1019 // -----------------------------------------------------------------------------
  1178 // -----------------------------------------------------------------------------
  1020 // CFindItemDialog::DynInitMenuPaneL
  1179 // CFindItemDialog::DynInitMenuPaneL
  1021 //  Initializes items on the menu
  1180 //  Initializes items on the menu
  1029         {
  1188         {
  1030         return;
  1189         return;
  1031         }
  1190         }
  1032 
  1191 
  1033     CFindItemEngine::SFoundItem item;
  1192     CFindItemEngine::SFoundItem item;
  1034     TBool founditem = iController->Item( item );
  1193     TBool foundItem = iController->Item( item );
  1035 
  1194     if ( iSingleClick )
       
  1195         {
       
  1196         // foundItem remains as ETrue, if item found by controller is exactly
       
  1197         // same as highlighted selection
       
  1198         foundItem = foundItem && ( item.iLength == iEdwin->SelectionLength()
       
  1199                 && item.iStartPos == Min( iEdwin->Selection().iCursorPos,
       
  1200                 iEdwin->Selection().iAnchorPos ) );
       
  1201         }
       
  1202         
  1036     if ( aMenuId == R_FINDITEM_CALLUI_AIW_SUBMENU )
  1203     if ( aMenuId == R_FINDITEM_CALLUI_AIW_SUBMENU )
  1037         {
  1204         {
  1038         if ( iFindItemVoIPExtension->IsVoIPSupported() &&
  1205         if ( iFindItemVoIPExtension->IsVoIPSupported() &&
  1039             ( iSearchCase ==
  1206             ( iSearchCase ==
  1040                 CFindItemEngine::EFindItemSearchMailAddressBin ||
  1207                 CFindItemEngine::EFindItemSearchMailAddressBin ||
  1041             ( iSearchCase == KSearchTelInternetNumber &&
  1208             ( iSearchCase == KSearchTelInternetNumber &&
  1042             founditem && item.iItemType ==
  1209             foundItem && item.iItemType ==
  1043                 CFindItemEngine::EFindItemSearchMailAddressBin ) ) )
  1210                 CFindItemEngine::EFindItemSearchMailAddressBin ) ) )
  1044             {
  1211             {
  1045             CAiwGenericParamList* inList = CAiwGenericParamList::NewLC();
  1212             CAiwGenericParamList* inList = CAiwGenericParamList::NewLC();
  1046 
  1213 
  1047             // SIP Address
  1214             // SIP Address
  1121            ;
  1288            ;
  1122            }
  1289            }
  1123 
  1290 
  1124         aMenuPane->AddMenuItemsL( resource, EAknFormMaxDefault - 1, ETrue );
  1291         aMenuPane->AddMenuItemsL( resource, EAknFormMaxDefault - 1, ETrue );
  1125 
  1292 
       
  1293         if ( iSingleClick && !foundItem )
       
  1294             {
       
  1295             switch ( resource )
       
  1296                 {
       
  1297                 case (R_FINDITEM_MAIL_ADDRESS_MENU):
       
  1298                     {
       
  1299                     aMenuPane->SetItemDimmed ( EFindItemCmdCopy, ETrue );
       
  1300                     aMenuPane->SetItemDimmed ( EFindItemSubMenuSend, ETrue );
       
  1301                     aMenuPane->SetItemDimmed ( EFindItemCmdCreateContactCard, ETrue );
       
  1302                     break;
       
  1303                     }
       
  1304 
       
  1305                 case (R_FINDITEM_URL_ADDRESS_MENU):
       
  1306                     {
       
  1307                     aMenuPane->SetItemDimmed ( EFindItemCmdGoToUrl, ETrue );
       
  1308                     aMenuPane->SetItemDimmed ( EFindItemCmdAddToBookmark, ETrue );
       
  1309                     aMenuPane->SetItemDimmed ( EFindItemCmdCreateContactCard, ETrue );
       
  1310                     aMenuPane->SetItemDimmed ( EFindItemCmdCopy, ETrue );
       
  1311                     break;
       
  1312                     }
       
  1313 
       
  1314                 case (R_FINDITEM_PHONENUMBER_MENU): // fall through
       
  1315                 case (R_FINDITEM_TELINTERNETNUMBER_MENU):
       
  1316                     {
       
  1317                     aMenuPane->SetItemDimmed ( EFindItemCmdCall, ETrue );
       
  1318                     aMenuPane->SetItemDimmed ( EFindItemCmdCopy, ETrue );
       
  1319                     aMenuPane->SetItemDimmed ( EFindItemSubMenuSend, ETrue );
       
  1320                     aMenuPane->SetItemDimmed ( EFindItemCmdCreateContactCard, ETrue );
       
  1321                     break;
       
  1322                     }
       
  1323 
       
  1324                 default:
       
  1325                     {
       
  1326                     break;
       
  1327                     }
       
  1328                 }
       
  1329             }
       
  1330 
  1126         if ( iSearchCase == KSearchTelInternetNumber &&
  1331         if ( iSearchCase == KSearchTelInternetNumber &&
  1127             iFindItemVoIPExtension->VoIPProfilesExistL() ||
  1332             iFindItemVoIPExtension->VoIPProfilesExistL() ||
  1128             iSearchCase == KSearchTelInternetNumber &&
  1333             iSearchCase == KSearchTelInternetNumber &&
  1129             !iFindItemVoIPExtension->VoIPProfilesExistL() &&
  1334             !iFindItemVoIPExtension->VoIPProfilesExistL() &&
  1130             founditem &&
  1335             foundItem &&
  1131             item.iItemType ==
  1336             item.iItemType ==
  1132                 CFindItemEngine::EFindItemSearchPhoneNumberBin ||
  1337                 CFindItemEngine::EFindItemSearchPhoneNumberBin ||
  1133             iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin &&
  1338             iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin &&
  1134             iFindItemVoIPExtension->VoIPProfilesExistL() )
  1339             iFindItemVoIPExtension->VoIPProfilesExistL() )
  1135             {
  1340             {
  1147             }
  1352             }
  1148         else if (
  1353         else if (
  1149             iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin &&
  1354             iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin &&
  1150             !iHideCallMenu )
  1355             !iHideCallMenu )
  1151             {
  1356             {
  1152             aMenuPane->SetItemDimmed( EFindItemCmdCall, ETrue );
  1357             if ( !iSingleClick || foundItem )
  1153             aMenuPane->AddMenuItemsL(
  1358                 {
  1154                 R_FINDITEM_CALLUI_AIW_ITEM,
  1359                 aMenuPane->SetItemDimmed( EFindItemCmdCall, ETrue );
  1155                 EFindItemCmdCall );
  1360                 aMenuPane->AddMenuItemsL(
       
  1361                     R_FINDITEM_CALLUI_AIW_ITEM,
       
  1362                     EFindItemCmdCall );
       
  1363                 }
  1156             }
  1364             }
  1157 
  1365 
  1158         aMenuPane->DeleteMenuItem( EAknFormCmdEdit );
  1366         aMenuPane->DeleteMenuItem( EAknFormCmdEdit );
  1159         aMenuPane->DeleteMenuItem( EAknFormCmdAdd );
  1367         aMenuPane->DeleteMenuItem( EAknFormCmdAdd );
  1160         aMenuPane->DeleteMenuItem( EAknFormCmdSave );
  1368         aMenuPane->DeleteMenuItem( EAknFormCmdSave );
  1161         aMenuPane->DeleteMenuItem( EAknFormCmdLabel );
  1369         aMenuPane->DeleteMenuItem( EAknFormCmdLabel );
  1162         aMenuPane->DeleteMenuItem( EAknFormCmdDelete );
  1370         aMenuPane->DeleteMenuItem( EAknFormCmdDelete );
  1163 
  1371 
  1164 #ifndef RD_VIRTUAL_PHONEBOOK
  1372 #ifndef RD_VIRTUAL_PHONEBOOK
  1165         iPbkDataSave->AddMenuItemsL(
  1373         if ( !iSingleClick || foundItem )
  1166             aMenuPane,
  1374             {
  1167             EFindItemCmdCreateContactCard );
  1375             iPbkDataSave->AddMenuItemsL(
       
  1376                 aMenuPane,
       
  1377                 EFindItemCmdCreateContactCard );
       
  1378             }
  1168 #else
  1379 #else
  1169         aMenuPane->SetItemDimmed( EFindItemCmdCreateContactCard, ETrue );
  1380         if ( !iSingleClick || foundItem )
  1170         aMenuPane->AddMenuItemsL(
  1381             {
  1171             R_FINDITEM_CONTACTS_AIW_ITEM,
  1382             aMenuPane->SetItemDimmed( EFindItemCmdCreateContactCard, ETrue );
  1172             EFindItemCmdCreateContactCard );
  1383             aMenuPane->AddMenuItemsL(
       
  1384                 R_FINDITEM_CONTACTS_AIW_ITEM,
       
  1385                 EFindItemCmdCreateContactCard );
       
  1386             }
  1173 #endif // !RD_VIRTUAL_PHONEBOOK
  1387 #endif // !RD_VIRTUAL_PHONEBOOK
  1174 
  1388 
  1175         // Delete next/prev item items from menu if a last/next
  1389         // Delete next/prev item items from menu if a last/next
  1176         // item is currently selected (or if sensitive menu)
  1390         // item is currently selected (or if sensitive menu)
  1177         if ( iController->FirstItem() || iIsSensitiveMenu )
  1391         if ( iController->FirstItem() || iIsSensitiveMenu )
  1236     TBool founditem = EFalse;
  1450     TBool founditem = EFalse;
  1237 
  1451 
  1238     switch ( code )
  1452     switch ( code )
  1239         {
  1453         {
  1240         case EKeyRightArrow:
  1454         case EKeyRightArrow:
       
  1455             if ( iSingleClick && !CurrentItemHasHighlight() )
       
  1456                 {
       
  1457                 HighlightCurrentItem();
       
  1458                 break;
       
  1459                 }
  1241             iController->NextItemL();
  1460             iController->NextItemL();
  1242             break;
  1461             break;
  1243         case EKeyDownArrow:
  1462         case EKeyDownArrow:
  1244             iController->MoveDownL();
  1463             if ( iSingleClick && !CurrentItemHasHighlight() )
       
  1464                 {
       
  1465                 HighlightCurrentItem();
       
  1466                 break;
       
  1467                 }
       
  1468             iController->MoveDownL();   
  1245             break;
  1469             break;
  1246         case EKeyLeftArrow:
  1470         case EKeyLeftArrow:
  1247             iController->PrevItemL();
  1471             if ( iSingleClick && !CurrentItemHasHighlight() )
       
  1472                 {
       
  1473                 HighlightCurrentItem();
       
  1474                 break;
       
  1475                 }
       
  1476             iController->PrevItemL();	
  1248             break;
  1477             break;
  1249         case EKeyUpArrow:
  1478         case EKeyUpArrow:
       
  1479             if ( iSingleClick && !CurrentItemHasHighlight() )
       
  1480                 {
       
  1481                 HighlightCurrentItem();
       
  1482                 break;
       
  1483                 }
  1250             iController->MoveUpL();
  1484             iController->MoveUpL();
  1251             break;
  1485             break;
  1252         case EKeyOK:
  1486         case EKeyOK:
  1253         case EKeyEnter:
  1487         case EKeyEnter:
       
  1488             if ( iSingleClick && !CurrentItemHasHighlight() )
       
  1489                 {
       
  1490                 HighlightCurrentItem();
       
  1491                 break;
       
  1492                 }
  1254             iIsSensitiveMenu = ETrue;
  1493             iIsSensitiveMenu = ETrue;
  1255             iMenuBar->SetMenuType(CEikMenuBar::EMenuContext);
  1494             iMenuBar->SetMenuType(CEikMenuBar::EMenuContext);
  1256             CAknDialog::DisplayMenuL();
  1495             CAknDialog::DisplayMenuL();
  1257             break;
  1496             break;
  1258         case EKeyPhoneSend:
  1497         case EKeyPhoneSend:
  1259             if ( !iDialData )
  1498             if ( iSingleClick && !CurrentItemHasHighlight() )
  1260                 {
  1499                 {
       
  1500                 HighlightCurrentItem();
  1261                 break;
  1501                 break;
  1262                 }
  1502                 }
  1263 
  1503 
       
  1504             if ( !iDialData )
       
  1505                 {
       
  1506                 break;
       
  1507                 }
  1264             CFindItemEngine::SFoundItem item;
  1508             CFindItemEngine::SFoundItem item;
  1265             founditem = iController->Item( item );
  1509             founditem = iController->Item( item );
  1266 
  1510 
  1267             if ( iSearchCase ==
  1511             if ( iSearchCase ==
  1268                     CFindItemEngine::EFindItemSearchPhoneNumberBin ||
  1512                     CFindItemEngine::EFindItemSearchPhoneNumberBin ||
  1386     
  1630     
  1387     // change the color of the text according to the skin color
  1631     // change the color of the text according to the skin color
  1388     TRgb color;
  1632     TRgb color;
  1389     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  1633     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  1390     TInt error = AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, 
  1634     TInt error = AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, 
  1391     												EAknsCIQsnTextColorsCG6 );
  1635         EAknsCIQsnTextColorsCG6 );
  1392     if(error==KErrNone)
  1636     if(error==KErrNone)
  1393     	{
  1637         {
  1394       	TCharFormat charFormat;
  1638         TCharFormat charFormat;
  1395     	TCharFormatMask charFormatMask;
  1639         TCharFormatMask charFormatMask;
  1396     	charFormatMask.SetAttrib(EAttColor);
  1640         charFormatMask.SetAttrib(EAttColor);
  1397     	charFormat.iFontPresentation.iTextColor = color; 
  1641         charFormat.iFontPresentation.iTextColor = color; 
  1398     
  1642 
  1399     	CRichText * richText = NULL;
  1643         CRichText * richText = NULL;
  1400     	richText = iEdwin->RichText();
  1644         richText = iEdwin->RichText();
  1401     	if( NULL!=richText )
  1645         if( NULL!=richText )
  1402     		{
  1646             {
  1403     		TInt length = richText->DocumentLength();
  1647             TInt length = richText->DocumentLength();
  1404     		length++;
  1648             length++;
  1405     		// apply the color to text
  1649             // apply the color to text
  1406     		TRAP_IGNORE(richText->ApplyCharFormatL( charFormat, charFormatMask, 0, length ));
  1650             TRAP_IGNORE(richText->ApplyCharFormatL( charFormat,
  1407     		}
  1651                 charFormatMask, 0, length ));
       
  1652             }
  1408        	}
  1653        	}
  1409     if ( anyFound )
  1654     if ( anyFound )
  1410         {
  1655         {
  1411         // Insert paragraphs inside the text if needed, i.e. if text is
  1656         // Insert paragraphs inside the text if needed, i.e. if text is
  1412         // bandformatted and there's not enough paragraphs already. The
  1657         // bandformatted and there's not enough paragraphs already. The
  1553         aItem1, point1, CLayoutData::EFWholeTBoxesOnly ) );
  1798         aItem1, point1, CLayoutData::EFWholeTBoxesOnly ) );
  1554     if ( error != KErrNone )
  1799     if ( error != KErrNone )
  1555         {
  1800         {
  1556         return EFalse;
  1801         return EFalse;
  1557         }
  1802         }
  1558     TBool pos2 = EFalse;        
  1803     TBool pos2 = EFalse;
  1559     TPoint point2;
  1804     TPoint point2;
  1560     TRAP( error, pos2 = iEdwin->TextLayout()->DocPosToXyPosL( 
  1805     TRAP( error, pos2 = iEdwin->TextLayout()->DocPosToXyPosL( 
  1561         aItem2, point2, CLayoutData::EFWholeTBoxesOnly ) );
  1806         aItem2, point2, CLayoutData::EFWholeTBoxesOnly ) );
  1562     if ( error != KErrNone )
  1807     if ( error != KErrNone )
  1563         {
  1808         {
  1679             }
  1924             }
  1680 
  1925 
  1681         UpdateScrollIndicatorL();
  1926         UpdateScrollIndicatorL();
  1682 
  1927 
  1683         iEdwin->TextView()->SetSelectionVisibilityL( ETrue );
  1928         iEdwin->TextView()->SetSelectionVisibilityL( ETrue );
  1684         iEdwin->SetSelectionL( item.iStartPos, item.iLength + item.iStartPos );
  1929         if ( !iSingleClick )
       
  1930             {
       
  1931             iEdwin->SetSelectionL( item.iStartPos, item.iLength + item.iStartPos );
       
  1932             }
  1685         }
  1933         }
  1686     else
  1934     else
  1687         {// Let's show a information note if no items were found
  1935         {// Let's show a information note if no items were found
  1688         HBufC* infoNote =
  1936         HBufC* infoNote =
  1689             iEikonEnv->AllocReadResourceLC(
  1937             iEikonEnv->AllocReadResourceLC(
  1805     TBuf<16> naviText;
  2053     TBuf<16> naviText;
  1806     naviText.Format(
  2054     naviText.Format(
  1807         KPosIndicator, iController->Position() + 1, iController->ItemCount() );
  2055         KPosIndicator, iController->Position() + 1, iController->ItemCount() );
  1808 
  2056 
  1809     if(NULL == iNaviDecorator)
  2057     if(NULL == iNaviDecorator)
  1810     	{
  2058         {
  1811     	iNaviDecorator = iNaviPane->CreateNavigationLabelL( naviText );
  2059         iNaviDecorator = iNaviPane->CreateNavigationLabelL( naviText );
  1812        	iNaviDecorator->SetNaviDecoratorObserver( this );  
  2060         iNaviDecorator->SetNaviDecoratorObserver( this );
  1813        	iNaviDecorator->MakeScrollButtonVisible( ETrue );
  2061         iNaviDecorator->MakeScrollButtonVisible( ETrue );
  1814        	}
  2062         }
  1815     else
  2063     else
  1816     	{
  2064         {
  1817     	// Change the label on Nave pane control...
  2065         // Change the label on Nave pane control...
  1818     	CAknNaviLabel * label =( CAknNaviLabel* )iNaviDecorator->DecoratedControl();
  2066         CAknNaviLabel * label =( CAknNaviLabel* )iNaviDecorator->DecoratedControl();
  1819     	label->SetTextL(naviText);
  2067         label->SetTextL(naviText);
  1820     	}
  2068         }
  1821 
  2069 
  1822     // Dimm arrows if needed
  2070     // Dimm arrows if needed
  1823     if ( iController->LastItem() )
  2071     if ( iController->LastItem() )
  1824         {
  2072         {
  1825         iNaviDecorator->SetScrollButtonDimmed(
  2073         iNaviDecorator->SetScrollButtonDimmed(
  1934 // -----------------------------------------------------------------------------
  2182 // -----------------------------------------------------------------------------
  1935 void CFindItemDialog::HandleResourceChange( TInt aType )
  2183 void CFindItemDialog::HandleResourceChange( TInt aType )
  1936     {
  2184     {
  1937 	//Update Horizantal Scroll bar color if skin changes
  2185 	//Update Horizantal Scroll bar color if skin changes
  1938     if( aType == KAknsMessageSkinChange)
  2186     if( aType == KAknsMessageSkinChange)
  1939     	{
  2187         {
  1940     	CAknScrollBar *scrollBar = iSBFrame->VerticalScrollBar();
  2188         CAknScrollBar *scrollBar = iSBFrame->VerticalScrollBar();
  1941     	scrollBar->HandleResourceChange(aType);
  2189         scrollBar->HandleResourceChange(aType);
  1942     	}
  2190         }
  1943     CAknDialog::HandleResourceChange( aType );
  2191     CAknDialog::HandleResourceChange( aType );
  1944     }
  2192     }
  1945 
  2193 
  1946 // -----------------------------------------------------------------------------
  2194 // -----------------------------------------------------------------------------
  1947 // CFindItemDialog::SizeChanged
  2195 // CFindItemDialog::SizeChanged
  1976         TInt length = iEdwin->TextLayout()->PosRangeInBand( pos );
  2224         TInt length = iEdwin->TextLayout()->PosRangeInBand( pos );
  1977         if( item.iStartPos >= pos + length )
  2225         if( item.iStartPos >= pos + length )
  1978             {
  2226             {
  1979             TRAP_IGNORE( iEdwin->MoveDisplayL( TCursorPosition::EFPageDown ) );
  2227             TRAP_IGNORE( iEdwin->MoveDisplayL( TCursorPosition::EFPageDown ) );
  1980             }
  2228             }
  1981     	}
  2229         }
  1982 
  2230 
  1983     TRAP_IGNORE( UpdateScrollIndicatorL() );
  2231     TRAP_IGNORE( UpdateScrollIndicatorL() );
  1984     }
  2232     }
  1985 
  2233 
  1986 // ----------------------------------------------------------------------------
  2234 // ----------------------------------------------------------------------------
  2033     const TPointerEvent& aPointerEvent )
  2281     const TPointerEvent& aPointerEvent )
  2034     {
  2282     {
  2035     if ( AknLayoutUtils::PenEnabled() &&
  2283     if ( AknLayoutUtils::PenEnabled() &&
  2036         aPointerEvent.iType == TPointerEvent::EButton1Down )
  2284         aPointerEvent.iType == TPointerEvent::EButton1Down )
  2037         {
  2285         {
  2038         TPoint tapPoint( aPointerEvent.iPosition - iTappingOffset );        
  2286         TPoint tapPoint( aPointerEvent.iPosition - iTappingOffset );
  2039         TInt pos = 0;
  2287         TInt pos = 0;
  2040         TInt len = iEdwin->TextLayout()->PosRangeInBand( pos );
  2288         TInt len = iEdwin->TextLayout()->PosRangeInBand( pos );
  2041         CFindItemEngine::SFoundItem item;
  2289         CFindItemEngine::SFoundItem item;
  2042         TRect rect;
  2290         TRect rect;
  2043         TInt i = 0;
  2291         TInt i = 0;
  2045             {
  2293             {
  2046             if ( !iController->Item( i, item ) ) // Get item.
  2294             if ( !iController->Item( i, item ) ) // Get item.
  2047                 {
  2295                 {
  2048                 break; // Error: invalid item.
  2296                 break; // Error: invalid item.
  2049                 };
  2297                 };
  2050             TInt end = item.iStartPos + item.iLength - 1;                            
  2298             TInt end = item.iStartPos + item.iLength - 1;
  2051             if ( end < pos )
  2299             if ( end < pos )
  2052                 {
  2300                 {
  2053                 i++;
  2301                 i++;
  2054                 continue; // item not visible.                
  2302                 continue; // item not visible.
  2055                 };                                            
  2303                 };
  2056             TInt start = item.iStartPos;
  2304             TInt start = item.iStartPos;
  2057             if ( start >= ( pos + len ) )
  2305             if ( start >= ( pos + len ) )
  2058                 {
  2306                 {
  2059                 break; // item not visible.
  2307                 break; // item not visible.
  2060                 }
  2308                 }
  2061             TInt lastLine = iEdwin->TextLayout()->GetLineNumber( end );
  2309             TInt lastLine = iEdwin->TextLayout()->GetLineNumber( end );
  2062             TInt nextLine = 0;
  2310             TInt nextLine = 0;
  2063             TInt lastPos = start;
  2311             TInt lastPos = start;
  2064             do // Check all rects of one item.
  2312             do // Check all rects of one item.
  2065                 {     
  2313                 {
  2066                 TInt error = KErrNone;                   
  2314                 TInt error = KErrNone;
  2067                 TRAP( error, rect = iEdwin->TextLayout()->GetLineRectL( start, end ) );
  2315                 TRAP( error, rect = iEdwin->TextLayout()->GetLineRectL( start, end ) );
  2068                 if ( error == KErrNone )
  2316                 if ( error == KErrNone )
  2069                     {
  2317                     {
  2070                     if ( rect.Contains( tapPoint ) ) // Item rect tapped.
  2318                     if ( rect.Contains( tapPoint ) ) // Item rect tapped.
  2071                         {                                    
  2319                         {
  2072                         TRAP( error, iController->TappedItemL( i ) ); // Change selection
  2320                         TRAP( error, iController->TappedItemL( i ) ); // Change selection
  2073                         if ( error != KErrNone )
  2321                         if ( error != KErrNone )
  2074                             {
  2322                             {
  2075                             return false; // Error: no selection made.
  2323                             return false; // Error: no selection made.
  2076                             }
  2324                             }
  2081                         }
  2329                         }
  2082                     }                 
  2330                     }                 
  2083                 else
  2331                 else
  2084                     {
  2332                     {
  2085                     return false; // Error: no rect.
  2333                     return false; // Error: no rect.
  2086                     }                                                    
  2334                     }
  2087                 TPoint midPoint( rect.iBr.iX, ( rect.iBr.iY + rect.iTl.iY) / 2 );
  2335                 TPoint midPoint( rect.iBr.iX, ( rect.iBr.iY + rect.iTl.iY) / 2 );
  2088                 TRAP( error, lastPos = iEdwin->TextLayout()->XyPosToDocPosL( midPoint ) );            
  2336                 TRAP( error, lastPos = iEdwin->TextLayout()->XyPosToDocPosL( midPoint ) );
  2089                 if ( error != KErrNone )
  2337                 if ( error != KErrNone )
  2090                     {
  2338                     {
  2091                     return false; // Error: no last pos.
  2339                     return false; // Error: no last pos.
  2092                     }
  2340                     }
  2093                 start = lastPos + 1;
  2341                 start = lastPos + 1;
  2094                 nextLine = iEdwin->TextLayout()->GetLineNumber( lastPos );                       
  2342                 nextLine = iEdwin->TextLayout()->GetLineNumber( lastPos );
  2095                 } while ( nextLine != lastLine ); 
  2343                 } while ( nextLine != lastLine ); 
  2096             i++;
  2344             i++;
  2097             }
  2345             }
  2098         }
  2346         }
  2099     return false;   // No hit, no further handling.
  2347     return false;   // No hit, no further handling.
  2154             iController->NextItemL();
  2402             iController->NextItemL();
  2155             break;
  2403             break;
  2156         default:
  2404         default:
  2157             break;
  2405             break;
  2158         }    
  2406         }    
  2159     }   
  2407     }
       
  2408 
       
  2409 // ----------------------------------------------------------------------------
       
  2410 // CFindItemDialog::CurrentItemHasHighlight
       
  2411 // ----------------------------------------------------------------------------
       
  2412 //
       
  2413 TBool CFindItemDialog::CurrentItemHasHighlight()
       
  2414     {
       
  2415     CFindItemEngine::SFoundItem item;
       
  2416     TBool foundItem = iController->Item( item );
       
  2417 
       
  2418     // foundItem remains as ETrue, if item found by controller is exactly
       
  2419     // same as highlighted selection
       
  2420     
       
  2421     TCursorSelection selection( iEdwin->Selection() );
       
  2422     TInt selectionLength = iEdwin->SelectionLength();
       
  2423 
       
  2424     foundItem = foundItem && ( ( item.iLength == selectionLength ) && ( item.iStartPos == Min( selection.iCursorPos, selection.iAnchorPos ) ) );
       
  2425 
       
  2426     foundItem = foundItem && ( iEdwin && iEdwin->TextView()
       
  2427         && iEdwin->TextView()->SelectionVisible() );
       
  2428 
       
  2429     return foundItem;
       
  2430     }
       
  2431 
       
  2432 // ----------------------------------------------------------------------------
       
  2433 // CFindItemDialog::HighlightCurrentItem
       
  2434 // ----------------------------------------------------------------------------
       
  2435 //
       
  2436 void CFindItemDialog::HighlightCurrentItem()
       
  2437     {
       
  2438     CFindItemEngine::SFoundItem item;
       
  2439     TBool found = iController->Item( item );
       
  2440 
       
  2441     if ( found && iEdwin && iEdwin->TextView() )
       
  2442         {
       
  2443         iEdwin->TextView()->SetSelectionVisibilityL( ETrue );
       
  2444         iEdwin->SetSelectionL( item.iStartPos, item.iStartPos + item.iLength );
       
  2445         }
       
  2446     }
       
  2447 
  2160 
  2448 
  2161 //
  2449 //
  2162 // CONTAINER CLASS
  2450 // CONTAINER CLASS
  2163 //
  2451 //
  2164 
  2452 
  2240         // change the color of the text according to the skin color
  2528         // change the color of the text according to the skin color
  2241         // this is needed if finditemdialog is active and theme is changed.
  2529         // this is needed if finditemdialog is active and theme is changed.
  2242         TRgb color;
  2530         TRgb color;
  2243         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  2531         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  2244         TInt error = AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, 
  2532         TInt error = AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, 
  2245         												EAknsCIQsnTextColorsCG6 );
  2533             EAknsCIQsnTextColorsCG6 );
  2246         if(error==KErrNone)
  2534         if(error==KErrNone)
  2247         	{
  2535             {
  2248            	TCharFormat charFormat;
  2536             TCharFormat charFormat;
  2249         	TCharFormatMask charFormatMask;
  2537             TCharFormatMask charFormatMask;
  2250         	charFormatMask.SetAttrib(EAttColor);
  2538             charFormatMask.SetAttrib(EAttColor);
  2251         	charFormat.iFontPresentation.iTextColor = color; 
  2539             charFormat.iFontPresentation.iTextColor = color; 
  2252      
  2540 
  2253         	CRichText * richText = NULL;
  2541             CRichText * richText = NULL;
  2254         	richText = iEditor->RichText();
  2542             richText = iEditor->RichText();
  2255         	if( NULL!=richText )
  2543             if( NULL!=richText )
  2256         		{
  2544                 {
  2257         		TInt length = richText->DocumentLength();
  2545                 TInt length = richText->DocumentLength();
  2258         		length++;
  2546                 length++;
  2259         		// apply the color to the text
  2547                 // apply the color to the text
  2260         		TRAP_IGNORE(richText->ApplyCharFormatL( charFormat, charFormatMask, 0, length ));
  2548                 TRAP_IGNORE(richText->ApplyCharFormatL( charFormat, charFormatMask, 0, length ));
  2261         		}
  2549                 }
  2262            	}
  2550             }
  2263         }
  2551         }
  2264     }
  2552     }
  2265 
  2553 
  2266 // -----------------------------------------------------------------------------
  2554 // -----------------------------------------------------------------------------
  2267 // CRichTextEditorContainer::HandleResourceChange
  2555 // CRichTextEditorContainer::HandleResourceChange