emailuis/emailui/src/ncsattachmentfield.cpp
changeset 2 5253a20d2a1e
parent 0 8466d47a6819
child 19 b13141f05c3d
--- a/emailuis/emailui/src/ncsattachmentfield.cpp	Thu Jan 07 12:38:38 2010 +0200
+++ b/emailuis/emailui/src/ncsattachmentfield.cpp	Mon Jan 18 20:08:26 2010 +0200
@@ -22,6 +22,7 @@
 #include <AknsUtils.h>
 #include <AknsSkinInstance.h>
 #include <FreestyleEmailUi.rsg>
+#include <touchfeedback.h>
 
 #include "FreestyleEmailUiLayoutData.h"
 #include "FreestyleEmailUiAppui.h"
@@ -30,6 +31,7 @@
 #include "ncsattachmentfield.h"
 #include "ncsutility.h"
 #include "ncsheadercontainer.h"
+#include "FSEmail.pan"
 
 
 CNcsAttachmentField* CNcsAttachmentField::NewL(
@@ -39,9 +41,9 @@
     {
     FUNC_LOG;
     CNcsAttachmentField* self =
-        new ( ELeave ) CNcsAttachmentField( aSizeObserver, aParentControl );
+        new ( ELeave ) CNcsAttachmentField( aLabelTextId, aSizeObserver, aParentControl );
     CleanupStack::PushL( self );
-    self->ConstructL( aLabelTextId );
+    self->ConstructL();
     CleanupStack::Pop( self );
     return self;
     }
@@ -49,48 +51,34 @@
 CNcsAttachmentField::~CNcsAttachmentField()
     {
     FUNC_LOG;
-    delete iAttachmentLabel;
+    iAttachmentLabels.ResetAndDestroy();
 
-    delete iAttachmentName;
-    delete iAttachmentSizeDesc;
+    delete iAttachmentNames;
+    delete iAttachmentSizes;
 
     delete iAttachmentBitmap;
     delete iAttachmentMask;
-
-    delete iActionMenuBitmap;
-    delete iActionMenuMask;
     }
 
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::CNcsAttachmentField()
 // -----------------------------------------------------------------------------
 //
-CNcsAttachmentField::CNcsAttachmentField( MNcsFieldSizeObserver* aSizeObserver,
+CNcsAttachmentField::CNcsAttachmentField( TInt aLabelTextId, 
+        MNcsFieldSizeObserver* aSizeObserver,
         CNcsHeaderContainer* aParentControl ):
     MNcsControl( aSizeObserver ),
-    iParentControl( aParentControl )
+    iParentControl( aParentControl ),
+    iLabelTextId ( aLabelTextId ),
+    iFocusedLabelIndex( KNoAttachmentLabelFocused )
     {
     FUNC_LOG;
     }
 
-void CNcsAttachmentField::ConstructL( TInt aLabelTextId )
+void CNcsAttachmentField::ConstructL()
     {
-    FUNC_LOG;
-    // create title label
-	HBufC* textBuf = StringLoader::LoadLC( aLabelTextId );
-
-	// create attachment label
-    iAttachmentLabel = new ( ELeave ) CNcsLabel( *this, NULL );
-    iAttachmentLabel->SetTextL( textBuf->Des() );
-
-	CleanupStack::PopAndDestroy( textBuf );
-
-    // <cmail> Platform layout change
+    FUNC_LOG;	
 	CreateIconsL();
-	// </cmail> Platform layout change
-	
-	UpdateFontSize();
-    UpdateColors();
     }
 
 // -----------------------------------------------------------------------------
@@ -143,7 +131,6 @@
     return 0;
     }
 
-// <cmail> Platform layout change
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::Reposition()
 // -----------------------------------------------------------------------------
@@ -151,17 +138,8 @@
 void CNcsAttachmentField::Reposition(TPoint& aPt, TInt /*aWidth*/ )
     {
     FUNC_LOG;
-    /*
-	TSize sz( aWidth, MinimumHeight() );
-	if ( Rect() != TRect( aPt, sz ) )
-	    {
-		SetExtent( aPt, sz );
-	    }
-    aPt.iY += Size().iHeight;
-    */
     SetPosition( aPt );
     }
-// </cmail> Platform layout change
 
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::GetLabelText()
@@ -173,7 +151,6 @@
 	return KNullDesC;
     }
 
-// <cmail> Platform layout change
 // ---------------------------------------------------------------------------
 // CNcsAttachmentField::LayoutLineCount
 // ---------------------------------------------------------------------------
@@ -181,9 +158,8 @@
 TInt CNcsAttachmentField::LayoutLineCount() const
     {
     FUNC_LOG;
-    return ( IsVisible() ? 1 : 0 );
+    return ( IsVisible() ? iAttachmentLabelCount : 0 );
     }
-// </cmail> Platform layout change
 
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::Draw()
@@ -195,57 +171,46 @@
     CWindowGc& gc = SystemGc();
 
     // Draw text box
-    // <cmail> Drawing removed </cmail>
-
     if ( IsFocused() )
     	{
-    	// highlight for label when focused
-	    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
-	    TRgb imageColor;
-	    if( AknsUtils::GetCachedColor( skin, imageColor,
-	    		KAknsIIDFsHighlightColors, EAknsCIFsHighlightColorsCG4 ) != KErrNone )
-	        {
-		    if( AknsUtils::GetCachedColor( skin, imageColor,
-		    		KAknsIIDQsnHighlightColors, EAknsCIQsnHighlightColorsCG2 ) != KErrNone )
-		    	{
-		        imageColor = KRgbBlue;
-		    	}
-	        }
-	    
-	    gc.SetPenStyle( CGraphicsContext::ENullPen );
-	    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
-	    gc.SetBrushColor( imageColor );
+    	TBool highlighedFound( EFalse );
+    	for ( TInt i( 0 ); !highlighedFound && i<iAttachmentLabelCount; ++i )
+    	    {
+    	    if ( iAttachmentLabels[i]->IsFocused() )
+    	        {
+    	        highlighedFound = ETrue;
+    	        // highlight for label when focused
+    	        MAknsSkinInstance* skin = AknsUtils::SkinInstance();
+    	        TRgb imageColor;
+    	        if( KErrNone != AknsUtils::GetCachedColor( 
+                        skin, imageColor,
+                        KAknsIIDFsHighlightColors, 
+                        EAknsCIFsHighlightColorsCG4 ) &&
+                    KErrNone != AknsUtils::GetCachedColor(
+                        skin, imageColor,
+                        KAknsIIDQsnHighlightColors,
+                        EAknsCIQsnHighlightColorsCG2 ) )
+    	            {
+    	            imageColor = KRgbBlue;
+    	            }
 	    
-	    TRect highlightRect( iAttachmentLabel->Rect() );
+    	        gc.SetPenStyle( CGraphicsContext::ENullPen );
+    	        gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
+    	        gc.SetBrushColor( imageColor );
 
-	    TInt sizeTextInPixels = iAttachmentLabel->Font()->TextWidthInPixels( 
-									*iAttachmentLabel->Text() );
-	    
-        highlightRect.SetWidth( sizeTextInPixels );
-        highlightRect.Grow( 0, 1 );
-	    
-	    if( AknLayoutUtils::LayoutMirrored() )
-	    	{
-	    	highlightRect.Move( Rect().Size().iWidth - 
-								highlightRect.Size().iWidth - 
-								highlightRect.iTl.iX - 2, 0 );
-	    	}
-	    
-	    gc.DrawRect( highlightRect );
+    	        TRect highlightRect( 
+    	                iAttachmentLabels[i]->TextHitAreaRect() );
+    	        highlightRect.Grow( 0, 1 );
+    	        gc.DrawRect( highlightRect );
+    	        }
+    	    }
     	}
     
     // Draw icons
     gc.SetBrushStyle( CGraphicsContext::ENullBrush );
-    // <cmail> Platform layout change
-
     gc.BitBltMasked( iAttachmentIconPos, iAttachmentBitmap, 
-    		iAttachmentBitmap->SizeInPixels(), iAttachmentMask, ETrue );
-
-    if( IsFocused() )
-    	{
-        gc.BitBltMasked( iActionMenuIconPos, iActionMenuBitmap, 
-        		iActionMenuBitmap->SizeInPixels(), iActionMenuMask, ETrue );
-    	}
+    		         iAttachmentBitmap->SizeInPixels(), 
+    		         iAttachmentMask, ETrue );
     }
 
 // -----------------------------------------------------------------------------
@@ -255,14 +220,12 @@
 void CNcsAttachmentField::SizeChanged()
     {
     FUNC_LOG;
- 
     LayoutControls();
-    // </cmail> Platform laytout change
 	UpdateFontSize();
 	UpdateColors();
-    // The attachment text needs to be updated when label size changes because it
+    // The attachment texts needs to be updated when label size changes because it
 	// may now get truncated differently.
-	TRAP_IGNORE( UpdateAttachmentTextL() );
+	TRAP_IGNORE( UpdateAttachmentTextsL() );
     }
 
 // -----------------------------------------------------------------------------
@@ -272,11 +235,8 @@
 void CNcsAttachmentField::PositionChanged()
     {
     FUNC_LOG;
-    // <cmail> Platform layout change
     LayoutControls();
     UpdateColors();
-   
-    // </cmail> Platform layout change
     }
 
 // -----------------------------------------------------------------------------
@@ -286,12 +246,6 @@
 TInt CNcsAttachmentField::MinimumHeight() const
     {
     FUNC_LOG;
-    // <cmail> Platform laytout change
-    /*
-    TNcsMeasures m = NcsUtility::Measures();
-    return m.iAifHeight + m.iAttachmentExtraHeightBottom;*/
-    //return NcsUtility::MinimumHeaderSize( Rect(), 1 ).iHeight;
-    // </cmail> Platform laytout change
     return 0;
     }
 
@@ -316,7 +270,7 @@
     }
 
 // -----------------------------------------------------------------------------
-// CNcsAttachmentField::SetContainerWindowL() const
+// CNcsAttachmentField::SetContainerWindowL()
 // -----------------------------------------------------------------------------
 //
 void CNcsAttachmentField::SetContainerWindowL( const CCoeControl& aContainer )
@@ -324,129 +278,162 @@
     FUNC_LOG;
 	CCoeControl::SetContainerWindowL( aContainer );
 
-	// Create the component array
-    InitComponentArrayL();
-	CCoeControlArray& controls = Components();
-	controls.SetControlsOwnedExternally( ETrue );
-	controls.AppendLC( iAttachmentLabel );
-    CleanupStack::Pop( iAttachmentLabel );
-
-    // set label properties
-	UpdateFontSize();
-
-    // Setup text alignment according the mirrored/normal layout.
-    if ( AknLayoutUtils::LayoutMirrored() )
-        {
-        iAttachmentLabel->SetAlignment( EHRightVCenter );
-        }
-    else
-        {
-        iAttachmentLabel->SetAlignment( EHLeftVCenter );
-        }
+	UpdateComponentArrayL();
 	}
 
 // -----------------------------------------------------------------------------
-// CNcsAttachmentField::SetTextL()
+// CNcsAttachmentField::UpdateComponentArrayL()
 // -----------------------------------------------------------------------------
 //
-void CNcsAttachmentField::SetTextL( const TDesC& aText )
+void CNcsAttachmentField::UpdateComponentArrayL()
     {
     FUNC_LOG;
-    delete iAttachmentName;
-    iAttachmentName = NULL;
-    delete iAttachmentSizeDesc;
-    iAttachmentSizeDesc = NULL;
-
-    iAttachmentLabel->SetTextL( aText );
-    }
-
-// -----------------------------------------------------------------------------
-// CNcsAttachmentField::SetTextL()
-// -----------------------------------------------------------------------------
-//
-void CNcsAttachmentField::SetTextL( const TDesC& aAttachmentName, const TDesC& aAttachmentSizeDesc )
-    {
-    FUNC_LOG;
-    delete iAttachmentName;
-    iAttachmentName = NULL;
-    delete iAttachmentSizeDesc;
-    iAttachmentSizeDesc = NULL;
-
-    iAttachmentName = aAttachmentName.AllocL();
-    iAttachmentSizeDesc = aAttachmentSizeDesc.AllocL();
-    UpdateAttachmentTextL();
+    InitComponentArrayL();
+    CCoeControlArray& controls = Components();
+    TInt controlsCount( controls.Count() );
+    controls.SetControlsOwnedExternally( ETrue );
+    
+    // Create the new component array items if needed
+    if ( iAttachmentLabelCount > controlsCount )
+        {
+        // append controls for new attachment labels after the existing ones
+        for ( TInt i( controlsCount ); i<iAttachmentLabelCount; ++i )
+            {
+            controls.AppendLC( iAttachmentLabels[i] );
+            CleanupStack::Pop( iAttachmentLabels[i] );
+        
+            UpdateFontSize( iAttachmentLabels[i] );
+        
+            // Align according to mirrored layout variation
+            iAttachmentLabels[i]->SetAlignment( AknLayoutUtils::LayoutMirrored() ?
+                    EHRightVCenter : EHLeftVCenter );
+            }
+        }
+    // Remove unnecessary component array items from the end
+    else if ( iAttachmentLabelCount < controlsCount )
+        {
+        for ( TInt i( controlsCount-1 ); i>=iAttachmentLabelCount ; --i )
+            {
+            controls.Remove( iAttachmentLabels[i] );
+            }
+        }
     }
 
 // -----------------------------------------------------------------------------
-// CNcsAttachmentField::UpdateAttachmentTextL()
+// CNcsAttachmentField::SetTextsLD()
 // -----------------------------------------------------------------------------
 //
-void CNcsAttachmentField::UpdateAttachmentTextL()
+void CNcsAttachmentField::SetTextsLD( 
+    CDesCArray* aAttachmentNames, CDesCArray* aAttachmentSizes )
     {
     FUNC_LOG;
-    if ( iAttachmentName && iAttachmentSizeDesc )
+    delete iAttachmentNames; 
+    iAttachmentNames = NULL;
+    iAttachmentNames = aAttachmentNames;
+    delete iAttachmentSizes;
+    iAttachmentSizes = NULL;
+    iAttachmentSizes = aAttachmentSizes;
+
+    if ( iAttachmentNames )
         {
-        // create decorated size text including the preceeding space character
-        HBufC* decoratedSize = StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_LIST_SIZE, 
-                                                     *iAttachmentSizeDesc );
-        HBufC* decoratedSizeWithSpace = HBufC::NewL( decoratedSize->Length() + 
-                                                     KSpace().Length() +
-                                                     KBidiRleStartChar().Length() +
-                                                     KBidiPdfChar().Length() );
-        decoratedSizeWithSpace->Des().Append( KSpace );
-        if ( AknLayoutUtils::LayoutMirrored() )
+        __ASSERT_DEBUG( iAttachmentNames && 
+                        iAttachmentSizes && 
+                        iAttachmentNames->Count() == iAttachmentSizes->Count(), 
+                        Panic( ENcsBasicUi ) );
+ 
+        TInt attachmentLabelCountBeforeUpdate( iAttachmentLabelCount );
+    
+        UpdateAttachmentTextsL();
+    
+        // set the focused attachment label
+        if ( iAttachmentLabelCount == 0 )
             {
-            // Put size part into embedded right-to-left block to ensure correct rendering
-            // even when name part is written from left-to-right.
-            decoratedSizeWithSpace->Des().Append( KBidiRleStartChar );
-            decoratedSizeWithSpace->Des().Append( *decoratedSize );
-            decoratedSizeWithSpace->Des().Append( KBidiPdfChar );
+            // No attachments
+            iFocusedLabelIndex = KNoAttachmentLabelFocused;
             }
-        else
+        else if ( iFocusedLabelIndex >= iAttachmentLabelCount ||
+                  attachmentLabelCountBeforeUpdate < iAttachmentLabelCount )
             {
-            decoratedSizeWithSpace->Des().Append( *decoratedSize );
+            // Set the focused index to last, we get here either if the last
+            // attachment label in list was removed or a new one was added.
+            // In either case focused should be the new last attachment label.
+            iFocusedLabelIndex = iAttachmentLabelCount-1;
             }
-        CleanupStack::PopAndDestroy( decoratedSize );
-        CleanupStack::PushL( decoratedSizeWithSpace );
-
-        // clip attachment name to fit the field so that size information has enough space too.
-        const CFont& font = *iAttachmentLabel->Font();
+        // In any other case, don't re-set the focused label index
+        }
+    else // no attachments 
+        {
+        iAttachmentLabelCount = 0;
+        iFocusedLabelIndex = KNoAttachmentLabelFocused;
+        }
+    
+    UpdateComponentArrayL();
+    LayoutControls();
+    iSizeObserver->UpdateFieldSizeL();
+    }
 
-        TInt labelWidth = iAttachmentLabel->Size().iWidth;
-        TInt sizeTextInPixels = font.TextWidthInPixels( *decoratedSizeWithSpace );
-        TInt pixelsLeftForAttachmentName = labelWidth - sizeTextInPixels;
+// -----------------------------------------------------------------------------
+// CNcsAttachmentField::FocusedAttachmentLabelIndex()
+// -----------------------------------------------------------------------------
+//
+TInt CNcsAttachmentField::FocusedAttachmentLabelIndex()
+    {
+    FUNC_LOG;
+    return iFocusedLabelIndex;
+    }
 
-        HBufC* attachmentText = NULL; // will contain the complete text
-        // safe check if the size information is too wide for some reason.
-        if ( pixelsLeftForAttachmentName < 0 )
+// -----------------------------------------------------------------------------
+// CNcsAttachmentField::UpdateAttachmentTextsL()
+// -----------------------------------------------------------------------------
+//
+void CNcsAttachmentField::UpdateAttachmentTextsL()
+    {
+    FUNC_LOG;
+    // create new array of labels. 
+    iAttachmentLabelCount = 0;
+    TInt count = iAttachmentNames->MdcaCount();
+    TInt existingLabelCount = iAttachmentLabels.Count();
+    TInt i( 0 );    
+    
+    // First, set the new texts using existing attachment labels objects
+    for ( ; i<count; ++i )
+        {
+        if ( i==existingLabelCount )
             {
-            attachmentText = HBufC::NewLC( iAttachmentName->Length() + decoratedSizeWithSpace->Length() );
-            attachmentText->Des().Append( *iAttachmentName );
-            attachmentText->Des().Append( *decoratedSizeWithSpace );
-            TPtr attachmentTextBufferModDes = attachmentText->Des();
-            AknTextUtils::ClipToFit( attachmentTextBufferModDes, font, labelWidth );
+            // no more re-usable label objects in their array.. break this 
+            // loop and continue with the next one (that creates new labels)
+            break;
             }
-        else
-            { // normal case
-            HBufC* attacmentNameBuffer = iAttachmentName->AllocLC();
-            TPtr attachmentNameBufferModDes = attacmentNameBuffer->Des();
-            AknTextUtils::ClipToFit( attachmentNameBufferModDes, font, pixelsLeftForAttachmentName );
-
-            attachmentText = HBufC::NewL( attacmentNameBuffer->Length() + decoratedSizeWithSpace->Length() );
-            attachmentText->Des().Append( *attacmentNameBuffer );
-            attachmentText->Des().Append( *decoratedSizeWithSpace );
-            CleanupStack::PopAndDestroy( attacmentNameBuffer );
-            CleanupStack::PushL( attachmentText );
+        UpdateSingleAttachmentLabelTextL( iAttachmentLabels[i], i );
+        ++iAttachmentLabelCount;
+        }
+    
+    // Create new attachment labels if needed
+    if ( i<count )
+        {
+        // stringloader used to get the initial (dummy) attachment text..
+        HBufC* textBuf = StringLoader::LoadLC( iLabelTextId );
+        
+        for ( ; i<count; ++i )
+            {
+            // create and initialize (fonts & colors) new label
+            CNcsLabel* label = new ( ELeave ) CNcsLabel( *this, NULL );
+            CleanupStack::PushL( label );
+            label->SetTextL( *textBuf );
+            UpdateFontSize( label );
+            UpdateColors( label );
+            UpdateSingleAttachmentLabelTextL( label, i );
+     
+            // append then new label to attachment label array
+            iAttachmentLabels.AppendL( label );
+            CleanupStack::Pop( label );
+            ++iAttachmentLabelCount;
             }
-
-        iAttachmentLabel->SetTextL( *attachmentText );
-
-        CleanupStack::PopAndDestroy( attachmentText );
-        CleanupStack::PopAndDestroy( decoratedSizeWithSpace );
+        CleanupStack::PopAndDestroy( textBuf );
         }
     }
 
-// <cmail> Platform layout change
+
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::ResizeIcons()
 // -----------------------------------------------------------------------------
@@ -454,20 +441,16 @@
 void CNcsAttachmentField::ResizeIcons()
     {
     FUNC_LOG;
-    const TSize frontIconSize( NcsUtility::HeaderDetailIconRect( Rect(), 1, NcsUtility::EIconFront ).Size() );
+    const TSize frontIconSize( NcsUtility::HeaderDetailIconRect( 
+            Rect(), 1, NcsUtility::EIconFront ).Size() );
     if ( frontIconSize != iAttachmentBitmap->SizeInPixels() )
         {
-        AknIconUtils::SetSize( iAttachmentBitmap, frontIconSize, EAspectRatioPreservedAndUnusedSpaceRemoved );
-        AknIconUtils::SetSize( iAttachmentMask, frontIconSize, EAspectRatioPreservedAndUnusedSpaceRemoved );
-        }
-    const TSize backIconSize( NcsUtility::HeaderDetailIconRect( Rect(), 1, NcsUtility::EIconBack ).Size() );
-    if ( backIconSize != iActionMenuBitmap->SizeInPixels() )
-        {
-        AknIconUtils::SetSize( iActionMenuBitmap, backIconSize, EAspectRatioNotPreserved  );
-        AknIconUtils::SetSize( iActionMenuMask, backIconSize, EAspectRatioNotPreserved  );
+        AknIconUtils::SetSize( iAttachmentBitmap, frontIconSize, 
+                               EAspectRatioPreservedAndUnusedSpaceRemoved );
+        AknIconUtils::SetSize( iAttachmentMask, frontIconSize, 
+                               EAspectRatioPreservedAndUnusedSpaceRemoved );
         }
     }
-// </cmail> Platform layout change
 
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::FocusChanged()
@@ -477,9 +460,11 @@
 	{
     FUNC_LOG;
 	if ( IsFocused() )
-		{
-		iAttachmentLabel->SetFocus( ETrue );
-
+	    {
+	    for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
+	        {
+	        iAttachmentLabels[i]->SetFocus( i==iFocusedLabelIndex );
+	        }
         // make sure that control is visible on screen
 		if ( Rect().iTl.iY < 0 )
 			{
@@ -510,10 +495,12 @@
 		}
 	else
 		{
-		iAttachmentLabel->SetFocus( EFalse );
+		for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
+		    {
+		    iAttachmentLabels[i]->SetFocus( EFalse );
+		    }
 		}
-
-    iAttachmentLabel->SetUnderlining( IsFocused() );
+	
     UpdateColors();
     
 	if ( aDrawNow )
@@ -532,58 +519,61 @@
 //
 void CNcsAttachmentField::UpdateColors()
     {
-    // <cmail> Platform layout change
-    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
-    TRgb textColor = KRgbBlack;
-
-    if( IsFocused() )
-    	{
-        AknsUtils::GetCachedColor(
-            skin,
-            textColor,
-            KAknsIIDQsnTextColors,
-            EAknsCIQsnTextColorsCG24 );
-    	}
-    else
-    	{
-		AknsUtils::GetCachedColor(
-			skin,
-			textColor,
-			KAknsIIDQsnTextColors,
-			EAknsCIQsnTextColorsCG6 );
-    	}
-    TRAP_IGNORE( iAttachmentLabel->OverrideColorL( 
-            EColorLabelText, textColor ) );
-
-    textColor = KRgbBlack;
-
-    TInt err = AknsUtils::GetCachedColor(
-        skin,
-        textColor,
-        KAknsIIDQsnHighlightColors,
-        EAknsCIQsnHighlightColorsCG3 );
-
-    TRAP_IGNORE( iAttachmentLabel->OverrideColorL(
-        EColorLabelTextEmphasis, textColor ) );
-
-    textColor = KRgbBlack;
-
-    err = AknsUtils::GetCachedColor(
-        skin,
-        textColor,
-        KAknsIIDQsnHighlightColors,
-        EAknsCIQsnHighlightColorsCG2 );
-
-    TRAP_IGNORE( iAttachmentLabel->OverrideColorL(
-        EColorLabelHighlightFullEmphasis, textColor ) );
-    // </cmail> Platform layout change
+    FUNC_LOG;
+    for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
+        {
+        UpdateColors( iAttachmentLabels[i] );
+        // currently all attachments are underlined
+        iAttachmentLabels[i]->SetUnderlining( ETrue );
+        }
+    
     CFreestyleEmailUiAppUi* appUi =
         static_cast<CFreestyleEmailUiAppUi*>( ControlEnv()->AppUi() );
     iBorderColor = appUi->LayoutHandler()->ComposerFieldBorderColor();
     iBgColor = appUi->LayoutHandler()->ComposerFieldBackgroundColor();
     }
 
-// <cmail> Platform layout change
+// -----------------------------------------------------------------------------
+// CNcsAttachmentField::UpdateColors()
+// -----------------------------------------------------------------------------
+//
+void CNcsAttachmentField::UpdateColors( CNcsLabel* aLabel )
+    {
+    FUNC_LOG;    
+    if ( aLabel )
+        {
+        MAknsSkinInstance* skin = AknsUtils::SkinInstance();
+        TRgb labelTextColor = KRgbBlack;
+        TRgb labelEmphasisColor = KRgbBlack;
+        TRgb labelHighlightFullEmphasisColor = KRgbBlack;
+    
+        AknsUtils::GetCachedColor(
+            skin,
+            labelTextColor,
+            KAknsIIDQsnTextColors,
+            aLabel->IsFocused() ? 
+                EAknsCIQsnTextColorsCG24 : EAknsCIQsnTextColorsCG6 );
+        AknsUtils::GetCachedColor(
+            skin,
+            labelEmphasisColor,
+            KAknsIIDQsnHighlightColors,
+            EAknsCIQsnHighlightColorsCG3 );
+        AknsUtils::GetCachedColor(
+            skin,
+            labelHighlightFullEmphasisColor,
+            KAknsIIDQsnHighlightColors,
+            EAknsCIQsnHighlightColorsCG2 );
+        
+        TRAP_IGNORE( aLabel->OverrideColorL( 
+            EColorLabelText, labelTextColor ) );
+        TRAP_IGNORE( aLabel->OverrideColorL(
+            EColorLabelTextEmphasis, labelEmphasisColor ) );
+        TRAP_IGNORE( aLabel->OverrideColorL(
+            EColorLabelHighlightFullEmphasis, 
+            labelHighlightFullEmphasisColor ) );
+        }
+    }
+
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::UpdateFontSize()
 // -----------------------------------------------------------------------------
@@ -591,38 +581,29 @@
 void CNcsAttachmentField::UpdateFontSize()
 	{
     FUNC_LOG;
-    /*if ( iLabelFont )
+    if ( iAttachmentLabelCount )
         {
-        ControlEnv()->ScreenDevice()->ReleaseFont( iLabelFont );
-        iLabelFont = NULL;
+        // same font used for all labels, so just get the first one's
+        iEditorFont = NcsUtility::GetLayoutFont( 
+            iAttachmentLabels[0]->Rect(), NcsUtility::ENcsHeaderDetailFont );            
         }
-
-    if ( iEditorFont )
+    for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
         {
-        ControlEnv()->ScreenDevice()->ReleaseFont( iEditorFont );
-        iEditorFont = NULL;
+        iAttachmentLabels[i]->SetFont( iEditorFont );
         }
+	}
 
-    // set label properties
-	TNcsMeasures m = NcsUtility::Measures();
-	if ( !iLabelFont )
-	    {
-	    TRAP_IGNORE( iLabelFont = NcsUtility::GetNearestFontL(EAknLogicalFontPrimarySmallFont,
-	    	m.iLabelFontHeightPx) );
-	    }
-
-	iTitleLabel->SetFont( iLabelFont );
-
-	if ( !iEditorFont )
-		{
-		TRAP_IGNORE( iEditorFont = NcsUtility::GetNearestFontL(EAknLogicalFontPrimarySmallFont,
-			m.iEditorFontHeightPx) );
-		}
-
-	iAttachmentLabel->SetFont( iEditorFont );*/
-    iEditorFont = NcsUtility::GetLayoutFont( iAttachmentLabel->Rect(), NcsUtility::ENcsHeaderDetailFont );
-	iAttachmentLabel->SetFont( iEditorFont );
-	}
+// -----------------------------------------------------------------------------
+// CNcsAttachmentField::UpdateFontSize()
+// -----------------------------------------------------------------------------
+//
+void CNcsAttachmentField::UpdateFontSize( CNcsLabel* aLabel )
+    {
+    FUNC_LOG;
+    iEditorFont = NcsUtility::GetLayoutFont( 
+            aLabel->Rect(), NcsUtility::ENcsHeaderDetailFont );
+    aLabel->SetFont( iEditorFont );
+    }
 
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::LayoutControls()
@@ -632,8 +613,15 @@
     {
     FUNC_LOG;
     const TRect rect( Rect() );
-    NcsUtility::LayoutDetailLabel( iAttachmentLabel, rect );
-    UpdateIconPositions( rect );
+    for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
+        {
+        NcsUtility::LayoutDetailLabel( iAttachmentLabels[i], rect, i );
+        if ( i == 0 )
+            {
+            // icons need to be updated for first round only
+            UpdateIconPositions( rect );
+            }
+        }
     }
 
 // -----------------------------------------------------------------------------
@@ -643,10 +631,9 @@
 void CNcsAttachmentField::UpdateIconPositions( const TRect& aRect )
     {
     FUNC_LOG;
-    iAttachmentIconPos = NcsUtility::HeaderDetailIconRect( aRect, 1, NcsUtility::EIconFront ).iTl;
-    iActionMenuIconPos = NcsUtility::HeaderDetailIconRect( aRect, 1, NcsUtility::EIconBack ).iTl;
+    iAttachmentIconPos = NcsUtility::HeaderDetailIconRect( 
+            aRect, 1, NcsUtility::EIconFront ).iTl;
     }
-// </cmail> Platform layout change
 
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::HandleResourceChange()
@@ -661,14 +648,69 @@
         {
         UpdateFontSize();
         UpdateColors();
-        // <cmail> Platform layout change
         CreateIcons();
-        // </cmail> Platform layout change
         DrawDeferred();
         }
     }
 
-// <cmail> Platform layout change
+// -----------------------------------------------------------------------------
+// CNcsAttachmentField::HandlePointerEventL()
+// -----------------------------------------------------------------------------
+//
+void CNcsAttachmentField::HandlePointerEventL( 
+        const TPointerEvent& aPointerEvent )
+    {
+    FUNC_LOG;
+    CCoeControl::HandlePointerEventL( aPointerEvent );
+    
+    if ( Rect().Contains( aPointerEvent.iPosition ) &&
+         aPointerEvent.iType == TPointerEvent::EButton1Down )
+        {
+        TBool focusedAttachmentLabelIndexChanged( EFalse );
+        TInt i( 0 );
+        for ( ; i<iAttachmentLabelCount; ++i )
+            {
+            if ( iAttachmentLabels[i]->TextHitAreaRect().Contains( 
+                    aPointerEvent.iPosition ) )
+                {
+                // tactile feedback
+                MTouchFeedback* feedback = MTouchFeedback::Instance();
+                if ( feedback )
+                    {
+                    feedback->InstantFeedback( this, ETouchFeedbackBasic );
+                    }
+                
+                if ( iFocusedLabelIndex != i )
+                    {
+                    focusedAttachmentLabelIndexChanged = ETrue;
+                    iFocusedLabelIndex =  i;
+                    }
+                break;
+                }
+            }
+
+        if ( i == iAttachmentLabelCount )
+            {
+            // Pointer event happened outside any of the labels. 
+            // Invalidate focused label index.. this will cause the next
+            // for loop to set all label focuses to EFalse.
+            iFocusedLabelIndex = KNoAttachmentLabelFocused;
+            focusedAttachmentLabelIndexChanged = ETrue;
+            }
+
+        if ( focusedAttachmentLabelIndexChanged )
+            {
+            // only redraw if focused attachment label changed
+            for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
+                {
+                iAttachmentLabels[i]->SetFocus( i==iFocusedLabelIndex );
+                }
+            UpdateColors();
+            DrawNow();
+            }
+        }
+    }
+
 // -----------------------------------------------------------------------------
 // CNcsAttachmentField::CreateIcons()
 // -----------------------------------------------------------------------------
@@ -687,17 +729,91 @@
 void CNcsAttachmentField::CreateIconsL()
     {
     FUNC_LOG;
-    CFreestyleEmailUiAppUi* fsAppUi = static_cast<CFreestyleEmailUiAppUi*>( ControlEnv()->AppUi() );
+    CFreestyleEmailUiAppUi* fsAppUi = 
+        static_cast<CFreestyleEmailUiAppUi*>( ControlEnv()->AppUi() );
     delete iAttachmentBitmap; 
     iAttachmentBitmap = NULL;
     delete iAttachmentMask; 
     iAttachmentMask = NULL;
-    fsAppUi->FsTextureManager()->ProvideBitmapL( EAttachmentIcon, iAttachmentBitmap, iAttachmentMask );
-    delete iActionMenuBitmap; 
-    iActionMenuBitmap = NULL;
-    delete iActionMenuMask; 
-    iActionMenuMask = NULL;
-    fsAppUi->FsTextureManager()->ProvideBitmapL( EListControlMenuIcon, iActionMenuBitmap, iActionMenuMask );
+    fsAppUi->FsTextureManager()->ProvideBitmapL( 
+            EAttachmentIcon, iAttachmentBitmap, iAttachmentMask );
     ResizeIcons();
     }
-// </cmail> Platform layout change
+
+// -----------------------------------------------------------------------------
+// CNcsAttachmentField::UpdateSingleAttachmentLabelTextL()
+// -----------------------------------------------------------------------------
+//
+void CNcsAttachmentField::UpdateSingleAttachmentLabelTextL( 
+        CNcsLabel* aLabel, TInt aIndex )
+    {
+    FUNC_LOG;  
+    // create decorated size text including the preceeding space character
+    HBufC* decoratedSize = StringLoader::LoadLC( 
+        R_FSE_VIEWER_ATTACHMENTS_LIST_SIZE, 
+        iAttachmentSizes->MdcaPoint( aIndex ) );
+    HBufC* decoratedSizeWithSpace = HBufC::NewL( 
+        decoratedSize->Length() + 
+        KSpace().Length() +
+        KBidiRleStartChar().Length() +
+        KBidiPdfChar().Length() );
+    decoratedSizeWithSpace->Des().Append( KSpace );
+    if ( AknLayoutUtils::LayoutMirrored() )
+        {
+        // Put size part into embedded right-to-left block to ensure 
+        // correct rendering even when name part is written from 
+        // left-to-right.
+        decoratedSizeWithSpace->Des().Append( KBidiRleStartChar );
+        decoratedSizeWithSpace->Des().Append( *decoratedSize );
+        decoratedSizeWithSpace->Des().Append( KBidiPdfChar );
+        }
+    else
+        {
+        decoratedSizeWithSpace->Des().Append( *decoratedSize );
+        }
+    CleanupStack::PopAndDestroy( decoratedSize );
+    CleanupStack::PushL( decoratedSizeWithSpace );
+    
+    // clip attachment name to fit the field so that size information has
+    // enough space too.
+    const CFont& font = *aLabel->Font();
+
+    TInt labelWidth = aLabel->Size().iWidth;
+    TInt sizeTextInPixels = 
+        font.TextWidthInPixels( *decoratedSizeWithSpace );
+    TInt pixelsLeftForAttachmentName = labelWidth - sizeTextInPixels;
+
+    HBufC* attachmentText = NULL; // will contain the complete text
+    // safe check if the size information is too wide for some reason.
+    if ( pixelsLeftForAttachmentName < 0 )
+        {
+        attachmentText = HBufC::NewLC( 
+                iAttachmentNames->MdcaPoint( aIndex ).Length() 
+                + decoratedSizeWithSpace->Length() );
+        attachmentText->Des().Append( iAttachmentNames->MdcaPoint( aIndex ) );
+        attachmentText->Des().Append( *decoratedSizeWithSpace );
+        TPtr attachmentTextBufferModDes = attachmentText->Des();
+        AknTextUtils::ClipToFit( attachmentTextBufferModDes, 
+                                 font, labelWidth );
+        }
+    else
+        { // normal case
+        HBufC* attacmentNameBuffer = 
+            iAttachmentNames->MdcaPoint( aIndex ).AllocLC();
+        TPtr attachmentNameBufferModDes = attacmentNameBuffer->Des();
+        AknTextUtils::ClipToFit( attachmentNameBufferModDes, 
+                                 font, pixelsLeftForAttachmentName );
+
+        attachmentText = HBufC::NewL( 
+                attacmentNameBuffer->Length() 
+                + decoratedSizeWithSpace->Length() );
+        attachmentText->Des().Append( *attacmentNameBuffer );
+        attachmentText->Des().Append( *decoratedSizeWithSpace );
+        CleanupStack::PopAndDestroy( attacmentNameBuffer );
+        CleanupStack::PushL( attachmentText );
+        }
+    aLabel->SetTextL( *attachmentText );
+    CleanupStack::PopAndDestroy( attachmentText );
+    CleanupStack::PopAndDestroy( decoratedSizeWithSpace );
+    }
+