commonuis/CommonUi/src/FindItemMenu.cpp
branchRCL_3
changeset 15 08e69e956a8c
parent 4 8ca85d2f0db7
child 16 71dd06cfe933
--- a/commonuis/CommonUi/src/FindItemMenu.cpp	Mon Mar 15 12:41:34 2010 +0200
+++ b/commonuis/CommonUi/src/FindItemMenu.cpp	Wed Mar 31 21:59:52 2010 +0300
@@ -356,6 +356,21 @@
             *iFindItemUrlItemString );
         }
     }
+	
+// -----------------------------------------------------------------------------
+// HasSelection
+//  Returns ETrue if editor has highlighted text
+// -----------------------------------------------------------------------------
+//
+TBool CFindItemMenu::HasSelection() const
+    {
+    TBool retval ( EFalse );
+    if ( iAutomaticFind )
+        {
+        retval = iAutomaticFind->HasSelection();
+        }
+    return retval;
+    }
 
 // -----------------------------------------------------------------------------
 // AddMenuItemL
@@ -541,15 +556,41 @@
     TBuf<KMaxMenuTextLength> tempBuf;
 
     // Adds menu items depending the selected item
-    switch ( itemType )
+    if ( HasSelection() )
         {
-        case CItemFinder::EPhoneNumber:
+        switch ( itemType )
             {
+            case CItemFinder::EPhoneNumber:
+                {
 #ifdef RD_VOIP_REL_2_2
-            if ( FeatureManager::FeatureSupported(KFeatureIdCommonVoip ) )
-                {
-                // show call menu if allowed
-                if ( !( iMenuItemFlags & CFindItemMenu::ECallItem ) )
+                if ( FeatureManager::FeatureSupported(KFeatureIdCommonVoip ) )
+                    {
+                    // show call menu if allowed
+                    if ( !( iMenuItemFlags & CFindItemMenu::ECallItem ) )
+                        {
+                        // Call
+                        iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_CALL );
+                        AddMenuItemL(
+                            *iMenuPane,
+                            EFindItemCmdCall,
+                            ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
+                            0,
+                            tempBuf );
+                        }
+                     // if context menu, we will show call item anyway
+                     else if ( iIsContextMenu )
+                        {
+                        // Call
+                        iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_CALL );
+                        AddMenuItemL(
+                            *iMenuPane,
+                            EFindItemCmdCall,
+                            EFindItemContextMenuPlaceHolder,
+                            0,
+                            tempBuf );
+                        }
+                    }
+                else
                     {
                     // Call
                     iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_CALL );
@@ -560,21 +601,8 @@
                         0,
                         tempBuf );
                     }
-                 // if context menu, we will show call item anyway
-                 else if ( iIsContextMenu )
-                    {
-                    // Call
-                    iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_CALL );
-                    AddMenuItemL(
-                        *iMenuPane,
-                        EFindItemCmdCall,
-                        EFindItemContextMenuPlaceHolder,
-                        0,
-                        tempBuf );
-                    }
-                }
-            else
-                {
+                index = EFindItemCmdCall;
+#else
                 // Call
                 iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_CALL );
                 AddMenuItemL(
@@ -583,141 +611,132 @@
                     ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
                     0,
                     tempBuf );
-                }
-            index = EFindItemCmdCall;
-#else
-            // Call
-            iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_CALL );
-            AddMenuItemL(
-                *iMenuPane,
-                EFindItemCmdCall,
-                ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
-                0,
-                tempBuf );
-            index = EFindItemCmdCall;
+                index = EFindItemCmdCall;
 #endif // RD_VOIP_REL_2_2
-            // Write
-            iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_MESSAGE_SUB );
-            AddMenuItemL(
-                *iMenuPane,
-                EFindItemSubMenuSend,
-                index,
-               0,//R_FINDITEM_NUMBER_MESSAGE_SUBMENU,
-                tempBuf );
-            index = EFindItemSubMenuSend;
-
-            break;
-            }
-        case CItemFinder::EUrlAddress:
-            {
-            iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_GOTO_URL );
-
-            // check if not rstp    
-            if ( iAutomaticFind->CurrentItemExt().iItemDescriptor->FindF( KRtspUrlAddress ) == KErrNotFound )
-                {
-                AddMenuItemL(
-                    *iMenuPane,
-                    EFindItemCmdGoToUrl,
-                    ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
-                    0,
-                    tempBuf);
-                index = EFindItemCmdGoToUrl;
-
-                if ( !iIsContextMenu )
-                    {
-                    // Add bookmark
-                    iCoeEnv->ReadResourceL(
-                        tempBuf, R_FINDITEMMENU_ADD_BOOKMARK );
-                    AddMenuItemL(
-                        *iMenuPane,
-                        EFindItemCmdAddToBookmark,
-                        index,
-                        0,
-                        tempBuf );
-                    index = EFindItemCmdAddToBookmark;
-                    }
-                }
-            else
-                {
-                AddMenuItemL(
-                    *iMenuPane,
-                    EFindItemCmdGoToRstp,
-                    ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
-                    0,
-                    tempBuf );
-                index = EFindItemCmdGoToRstp;
-
-                if ( !iIsContextMenu )
-                    {
-                    iCoeEnv->ReadResourceL(
-                        tempBuf, R_FINDITEMMENU_ADD_TO_GALLERY );
-                    AddMenuItemL(
-                        *iMenuPane,
-                        EFindItemCmdAddToGallery,
-                        index,
-                        0,
-                        tempBuf );
-                    index = EFindItemCmdAddToGallery;
-                    }
-                }
-            break;
-            }
-        case CItemFinder::EEmailAddress:
-            {
-            // Checks VoIP profile count and local variation
-            if ( iIsContextMenu && iFindItemVoIPExtension->VoIPProfilesExistL() )
-                {
-                //Call
-                iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_CALL );
-                AddMenuItemL(
-                    *iMenuPane,
-                    EFindItemCmdCall,
-                    EFindItemContextMenuPlaceHolder,
-                    0,
-                    tempBuf );
-                index = EFindItemCmdCall; // Replaces the call ui menu when email
-                                          // field is selected.
-                }
-
-            // Write
-            if( iEmailOverSmsFeatureSupported || iMMSFeatureSupported ||
-                iEmailUiFeatureSupported ) // Sometimes submenu can be empty.
-                {
+                // Write
                 iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_MESSAGE_SUB );
                 AddMenuItemL(
                     *iMenuPane,
                     EFindItemSubMenuSend,
-                    ( ( iIsContextMenu &&
-                        !iFindItemVoIPExtension->VoIPProfilesExistL() ) ?
-                            EFindItemContextMenuPlaceHolder : index ),
-                    0,//R_FINDITEM_EMAIL_MESSAGE_SUBMENU,
+                    index,
+                   0,//R_FINDITEM_NUMBER_MESSAGE_SUBMENU,
                     tempBuf );
                 index = EFindItemSubMenuSend;
+    
+                break;
                 }
-            break;
-            }
-        case CItemFinder::EUriScheme:
-            {
-            // Use
-            iCoeEnv->ReadResourceL( tempBuf, R_QTN_OPTIONS_SCHEME_USE );
-            AddMenuItemL(
-                *iMenuPane,
-                EFindItemCmdUse,
-                ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
-                0,
-                tempBuf );
-            index = EFindItemCmdUse;
-            break;
-            }
-        default:
-            {
-            // Something else, probably nothing selected or new type which we
-            // don't support.
-            break;
+            case CItemFinder::EUrlAddress:
+                {
+                iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_GOTO_URL );
+    
+                // check if not rstp    
+                if ( iAutomaticFind->CurrentItemExt().iItemDescriptor->FindF( KRtspUrlAddress ) == KErrNotFound )
+                    {
+                    AddMenuItemL(
+                        *iMenuPane,
+                        EFindItemCmdGoToUrl,
+                        ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
+                        0,
+                        tempBuf);
+                    index = EFindItemCmdGoToUrl;
+    
+                    if ( !iIsContextMenu )
+                        {
+                        // Add bookmark
+                        iCoeEnv->ReadResourceL(
+                            tempBuf, R_FINDITEMMENU_ADD_BOOKMARK );
+                        AddMenuItemL(
+                            *iMenuPane,
+                            EFindItemCmdAddToBookmark,
+                            index,
+                            0,
+                            tempBuf );
+                        index = EFindItemCmdAddToBookmark;
+                        }
+                    }
+                else
+                    {
+                    AddMenuItemL(
+                        *iMenuPane,
+                        EFindItemCmdGoToRstp,
+                        ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
+                        0,
+                        tempBuf );
+                    index = EFindItemCmdGoToRstp;
+    
+                    if ( !iIsContextMenu )
+                        {
+                        iCoeEnv->ReadResourceL(
+                            tempBuf, R_FINDITEMMENU_ADD_TO_GALLERY );
+                        AddMenuItemL(
+                            *iMenuPane,
+                            EFindItemCmdAddToGallery,
+                            index,
+                            0,
+                            tempBuf );
+                        index = EFindItemCmdAddToGallery;
+                        }
+                    }
+                break;
+                }
+            case CItemFinder::EEmailAddress:
+                {
+                // Checks VoIP profile count and local variation
+                if ( iIsContextMenu && iFindItemVoIPExtension->VoIPProfilesExistL() )
+                    {
+                    //Call
+                    iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_CALL );
+                    AddMenuItemL(
+                        *iMenuPane,
+                        EFindItemCmdCall,
+                        EFindItemContextMenuPlaceHolder,
+                        0,
+                        tempBuf );
+                    index = EFindItemCmdCall; // Replaces the call ui menu when email
+                                              // field is selected.
+                    }
+    
+                // Write
+                if( iEmailOverSmsFeatureSupported || iMMSFeatureSupported ||
+                    iEmailUiFeatureSupported ) // Sometimes submenu can be empty.
+                    {
+                    iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_MESSAGE_SUB );
+                    AddMenuItemL(
+                        *iMenuPane,
+                        EFindItemSubMenuSend,
+                        ( ( iIsContextMenu &&
+                            !iFindItemVoIPExtension->VoIPProfilesExistL() ) ?
+                                EFindItemContextMenuPlaceHolder : index ),
+                        0,//R_FINDITEM_EMAIL_MESSAGE_SUBMENU,
+                        tempBuf );
+                    index = EFindItemSubMenuSend;
+                    }
+                break;
+                }
+            case CItemFinder::EUriScheme:
+                {
+                // Use
+                iCoeEnv->ReadResourceL( tempBuf, R_QTN_OPTIONS_SCHEME_USE );
+                AddMenuItemL(
+                    *iMenuPane,
+                    EFindItemCmdUse,
+                    ( iIsContextMenu ? EFindItemContextMenuPlaceHolder : index ),
+                    0,
+                    tempBuf );
+                index = EFindItemCmdUse;
+                break;
+                }
+            default:
+                {
+                // Something else, probably nothing selected or new type which we
+                // don't support.
+                break;
+                }
             }
         }
+    
     // Call
-    if (
+    if ( HasSelection() && (
         ( itemType == CItemFinder::ENoneSelected ) &&
         (
             (
@@ -733,7 +752,7 @@
         ||
             ( itemType == CItemFinder::EEmailAddress &&
             iFindItemVoIPExtension->VoIPProfilesExistL() &&
-            !iIsContextMenu )
+            !iIsContextMenu ) )
         )
         {
 #ifdef RD_VOIP_REL_2_2
@@ -823,10 +842,10 @@
               CleanupStack::PopAndDestroy( ); 
               }
 
-        if( (!iAutomaticFind || len != 0) && 
+        if( HasSelection() && ( (!iAutomaticFind || len != 0) && 
             highlight &&        
             ( itemType != CItemFinder::ENoneSelected || 
-            iSenderHighlighted ) )
+            iSenderHighlighted ) ) )
             {
             iCoeEnv->ReadResourceL( tempBuf, R_FINDITEMMENU_COPY );
             AddMenuItemL(
@@ -841,14 +860,14 @@
         }
 
      // Add to contacts
-     if ( ( itemType != CItemFinder::EUriScheme ) &&
+     if ( HasSelection() && ( ( itemType != CItemFinder::EUriScheme ) &&
         !( itemType == CItemFinder::EUrlAddress &&
         iIsContextMenu ) &&
         ( ( ( ( !iIsSenderKnown &&
         iSenderDescriptor->Length() ) ||
         iCallbackNumber ) &&
         itemType == CItemFinder::ENoneSelected ) ||
-        itemType != CItemFinder::ENoneSelected ) )
+        itemType != CItemFinder::ENoneSelected ) ) )
         {
         AddMenuItemL(
             *iMenuPane,
@@ -1680,11 +1699,16 @@
     {       
     HBufC* item = 0;
     TInt len = 0;
-    if ( iAutomaticFind && iAutomaticFind->CurrentItemExt().iItemType != CItemFinder::ENoneSelected )
+    if ( iAutomaticFind && iAutomaticFind->CurrentSelection().Length() > 0 )
         {
         item = iAutomaticFind->CurrentSelection().AllocLC();                        
         len = item->Length();
         }
+    else if ( iAutomaticFind && iAutomaticFind->CurrentItemExt().iItemDescriptor )
+        {
+        item = iAutomaticFind->CurrentItemExt().iItemDescriptor->AllocLC();
+        len = item->Length();
+        }
     else if( iSenderHighlighted )
         {
         item = iSenderDisplayText->AllocLC();
@@ -1835,7 +1859,7 @@
             User::Leave(err);                
             }
         }
-    return KErrNone;
+    return ETrue;
     }    
 
 //  End of File