emailuis/emailui/src/FreestyleEmailUiMailViewerRichText.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: FreestyleEmailUi mail viewer rich text implementation
       
    15 * Version    : %version: e003sa37#49 %
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include "emailtrace.h"
       
    22 #include <AknUtils.h>
       
    23 #include <freestyleemailui.mbg>
       
    24 #include <FreestyleEmailUi.rsg>
       
    25 #include <StringLoader.h>
       
    26 #include <AknBidiTextUtils.h>
       
    27 //<cmail>
       
    28 #include "fstextviewer.h"
       
    29 #include "fsrichtext.h"
       
    30 #include "cfsmailmessagepart.h"
       
    31 #include "cfsmailclient.h"
       
    32 #include "cfsmailcommon.h"
       
    33 //</cmail>
       
    34 #include <txtfrmat.h>
       
    35 // <cmail> SF
       
    36 #include <alf/alftextvisual.h>
       
    37 // </cmail>
       
    38 //<cmail> Platform layout changes
       
    39 #include <aknlayoutscalable_apps.cdl.h>
       
    40 #include <layoutmetadata.cdl.h>
       
    41 //</cmail> Platform layout changes
       
    42 
       
    43 // for fonts
       
    44 #include <AknFontAccess.h>
       
    45 #include <AknLayoutFont.h>
       
    46 
       
    47 // <cmail> separator line   
       
    48 #include <w32std.h>
       
    49 #include <coecntrl.h>
       
    50 // </cmail> separator line  
       
    51 
       
    52 // INTERNAL INCLUDES
       
    53 #include "FreestyleEmailUiMailViewerRichText.h"
       
    54 #include "FreestyleEmailUiAppui.h"
       
    55 #include "FreestyleEmailUiConstants.h"
       
    56 #include "FreestyleEmailUiLiterals.h"
       
    57 #include "FreestyleEmailUiFileSystemInfo.h"
       
    58 #include "FreestyleEmailUi.hrh"
       
    59 #include "FreestyleEmailUiTextureManager.h"
       
    60 #include "FreestyleEmailUiUtilities.h"
       
    61 #include "FreestyleEmailUiLayoutHandler.h"
       
    62 #include "FreestyleEmailUiMailViewerConstants.h"
       
    63 #include "ncsconstants.h" // for KSentLineDateAndTimeSeparatorText
       
    64 
       
    65 
       
    66 // CONST VALUES
       
    67 static const TInt KHotspotHighlightOn = 1;
       
    68 // Max hotspot count is a maximum number of hotspots allowed to be placed into
       
    69 // fs_generic text viewer component.
       
    70 static const TInt KMaxHotspotCount = 300;
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CFSEmailUiMailViewerRichText::NewL
       
    74 // -----------------------------------------------------------------------------
       
    75 CFSEmailUiMailViewerRichText* CFSEmailUiMailViewerRichText::NewL(
       
    76         CFreestyleEmailUiAppUi& aAppUi )
       
    77     {
       
    78     FUNC_LOG;
       
    79     CFSEmailUiMailViewerRichText* self =
       
    80         CFSEmailUiMailViewerRichText::NewLC( aAppUi );
       
    81     CleanupStack::Pop( self );
       
    82     return self;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CFSEmailUiMailViewerRichText::NewLC
       
    87 // -----------------------------------------------------------------------------
       
    88 CFSEmailUiMailViewerRichText* CFSEmailUiMailViewerRichText::NewLC(
       
    89         CFreestyleEmailUiAppUi& aAppUi )
       
    90 	{
       
    91     FUNC_LOG;
       
    92     CFSEmailUiMailViewerRichText* self =
       
    93         new (ELeave) CFSEmailUiMailViewerRichText( aAppUi );
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL();
       
    96     return self;
       
    97 	}
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CFSEmailUiMailViewerRichText::ConstructL
       
   101 // -----------------------------------------------------------------------------
       
   102 void CFSEmailUiMailViewerRichText::ConstructL()
       
   103     {
       
   104     FUNC_LOG;
       
   105 
       
   106     CEikonEnv* env = CEikonEnv::Static();
       
   107     iViewerRichText = CFsRichText::NewL( env->SystemParaFormatLayerL(),
       
   108         env->SystemCharFormatLayerL() );
       
   109 
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CFSEmailUiMailViewerRichText::CFSEmailUiMailViewerRichText
       
   114 // -----------------------------------------------------------------------------
       
   115 CFSEmailUiMailViewerRichText::CFSEmailUiMailViewerRichText(
       
   116         CFreestyleEmailUiAppUi& aAppUi )
       
   117 	: iAppUi( aAppUi )
       
   118 	{
       
   119     FUNC_LOG;
       
   120 	}
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CFSEmailUiMailViewerRichText::~CFSEmailUiMailViewerRichText
       
   124 // -----------------------------------------------------------------------------
       
   125 CFSEmailUiMailViewerRichText::~CFSEmailUiMailViewerRichText()
       
   126 	{
       
   127     FUNC_LOG;
       
   128 	delete iViewerRichText;
       
   129 
       
   130 	iFontsArray.ResetAndDestroy();
       
   131 
       
   132 	iViewerHeadingHotSpotData.Reset();
       
   133 	iBodyTextHotSpotData.Reset();
       
   134 	}
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CFSEmailUiMailViewerRichText::SetHotspotByIndexL
       
   138 // -----------------------------------------------------------------------------
       
   139 // <cmail>
       
   140 void CFSEmailUiMailViewerRichText::SetHotspotByIndexL( TInt aIndex )
       
   141     {
       
   142     FUNC_LOG;
       
   143     /*TInt headingHotspotCount = iViewerHeadingHotSpotData.Count();
       
   144     TInt bodyHotspotCount = iBodyTextHotSpotData.Count();
       
   145 
       
   146     if ( iTextViewer )
       
   147         {
       
   148         if ( aIndex < headingHotspotCount )
       
   149             {
       
   150             iTextViewer->FocusLineL( iViewerHeadingHotSpotData[aIndex].iHotspotLine , EFalse );
       
   151             iTextViewer->SetCurrentHotspotByOrderL( aIndex );
       
   152             }
       
   153         else if ( (aIndex - headingHotspotCount) < bodyHotspotCount )
       
   154             {
       
   155             iTextViewer->FocusLineL( iViewerHeadingHotSpotData[headingHotspotCount - 1].iHotspotLine , ETrue );
       
   156             iTextViewer->SetCurrentHotspotByOrderL( headingHotspotCount - 1 );
       
   157             }
       
   158         }*/
       
   159     // Remove the if/elseif contents above and replace them with the commented line below, once it becomes available in fs_generic
       
   160     iTextViewer->SetCurrentHotspotByOrderL( aIndex, ETrue );
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CFSEmailUiMailViewerRichText::CurrentHotspotIndexL
       
   165 // -----------------------------------------------------------------------------
       
   166 TInt CFSEmailUiMailViewerRichText::CurrentHotspotIndexL()
       
   167     {
       
   168     FUNC_LOG;
       
   169     /*TInt hotspotIndex(0);
       
   170 
       
   171     if ( iTextViewer )
       
   172         {
       
   173         TInt start(0);
       
   174         TInt end(0);
       
   175         TInt headingHotspotCount = iViewerHeadingHotSpotData.Count();
       
   176         TInt bodyHotspotCount = iBodyTextHotSpotData.Count();
       
   177         TBool foundHotspot = EFalse;
       
   178 
       
   179         iTextViewer->GetCurrentHotspotL( start, end );
       
   180 
       
   181         if ( headingHotspotCount > 0 )
       
   182             {
       
   183             TInt headingHotspotEnd = iViewerHeadingHotSpotData[ headingHotspotCount-1 ].iEnd;
       
   184             if ( start < headingHotspotEnd )
       
   185                 {
       
   186                 for ( TInt i = 0; i < headingHotspotCount; ++i)
       
   187                     {
       
   188                     if ( iViewerHeadingHotSpotData[i].iStart == start )
       
   189                         {
       
   190                         foundHotspot = ETrue;
       
   191                         hotspotIndex = i;
       
   192                         break;
       
   193                         }
       
   194                     }
       
   195                 }
       
   196             }
       
   197 
       
   198         if ( !foundHotspot )
       
   199             {
       
   200             for ( TInt i = 0; i < bodyHotspotCount; ++i)
       
   201                 {
       
   202                 if ( iBodyTextHotSpotData[i].iStartPos + iHeaderLength == start )
       
   203                     {
       
   204                     hotspotIndex = i + headingHotspotCount;
       
   205                     break;
       
   206                     }
       
   207                 }
       
   208             }
       
   209         }
       
   210 
       
   211     return hotspotIndex;*/
       
   212     
       
   213     return iTextViewer->GetCurrentHotspotByOrder();    
       
   214     }
       
   215 // </cmail>
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CFSEmailUiMailViewerRichText::EmailStatusIconLine
       
   219 // -----------------------------------------------------------------------------
       
   220 TInt CFSEmailUiMailViewerRichText::EmailStatusIconLine()
       
   221     {
       
   222     FUNC_LOG;
       
   223     return iEmailStatusIconLine;
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CFSEmailUiMailViewerRichText::FollowupIconLine
       
   228 // -----------------------------------------------------------------------------
       
   229 TInt CFSEmailUiMailViewerRichText::FollowupIconLine()
       
   230     {
       
   231     FUNC_LOG;
       
   232     return iFollowupIconLine;
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CFSEmailUiMailViewerRichText::RefreshRichTextL
       
   237 // -----------------------------------------------------------------------------
       
   238 void CFSEmailUiMailViewerRichText::RefreshRichTextL( CFsTextViewer& aTextViewer,
       
   239                                                      CFSMailMessage& aMessage,
       
   240                                                      CFSMailBox& aMailBox )
       
   241 	{
       
   242     FUNC_LOG;
       
   243 
       
   244     Reset();
       
   245     
       
   246     // Save new pointers
       
   247 	iTextViewer = &aTextViewer;
       
   248 	iMessage = &aMessage;
       
   249 	iMailBox = &aMailBox;
       
   250 	
       
   251 	// Reconstruct the whole rich text
       
   252 	// line by line according to information found from current message
       
   253 	AppendFromLineL( *iMessage, iHeaderLineInfo );
       
   254 	AppendRecipientLinesL( *iMessage, iHeaderLineInfo, EViewerRecipientTypeTo );
       
   255 	AppendRecipientLinesL( *iMessage, iHeaderLineInfo, EViewerRecipientTypeCc );
       
   256 	
       
   257 	// show bcc field only if opened from sent folder
       
   258 	TFSMailMsgId currentMessageFolderId = iMessage->GetFolderId();
       
   259 	CFSMailFolder* currentFolder = NULL;
       
   260 	
       
   261     TRAP_IGNORE( currentFolder = iAppUi.GetMailClient()->GetFolderByUidL( 
       
   262             iMessage->GetMailBoxId(), currentMessageFolderId ) );
       
   263             
       
   264 	CleanupStack::PushL( currentFolder );
       
   265 	if ( currentFolder && currentFolder->GetFolderType() == EFSSentFolder )
       
   266 		{ 
       
   267 	    AppendRecipientLinesL( *iMessage, iHeaderLineInfo, EViewerRecipientTypeBcc );
       
   268 		}
       
   269     CleanupStack::PopAndDestroy( currentFolder );
       
   270     
       
   271 	AppendSentLineL( *iMessage, iHeaderLineInfo );
       
   272 
       
   273 	AppendSubjectLinesL( *iMessage, iHeaderLineInfo );
       
   274     AppendHtmlTextLineL( *iMessage, iHeaderLineInfo );
       
   275 	AppendAttachmentLinesL( *iMessage, iHeaderLineInfo );
       
   276 
       
   277 	// Append little bit of vertical space before the header area ends.
       
   278     InsertTransparentSpacingIconL( EBottomMostSpace );
       
   279 
       
   280     // <cmail> separator line  		
       
   281 	AppendSeparatorLineL();   
       
   282     // </cmail> separator line
       
   283 
       
   284     // Add the upmost space also just before the body text.
       
   285     InsertTransparentSpacingIconL( ETopMostSpace );
       
   286 
       
   287     // Save the total header lenght in characters
       
   288     iHeaderLength = iViewerRichText->DocumentLength();
       
   289     
       
   290     // Add body text
       
   291 	AppendInitialBodytextLinesL( *iMessage );
       
   292 	}
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CFSEmailUiMailViewerRichText::Reset
       
   296 // -----------------------------------------------------------------------------
       
   297 void CFSEmailUiMailViewerRichText::Reset()
       
   298     {
       
   299     FUNC_LOG;
       
   300 
       
   301     // reset all the data
       
   302     iTextViewer = NULL;
       
   303     iMessage = NULL;
       
   304     iMailBox = NULL;
       
   305     
       
   306     iViewerRichText->Reset();
       
   307     iViewerHeadingHotSpotData.Reset();
       
   308     iBodyTextHotSpotData.Reset();
       
   309     iStatusLayout = NULL;
       
   310     iStatusVisual = NULL;
       
   311 
       
   312     iHeaderLength = 0;
       
   313     iHeaderLineInfo.iHeaderLineCount = 0;
       
   314     iHeaderLineInfo.iToLineCount = 0;
       
   315     iHeaderLineInfo.iCcLineCount = 0;
       
   316     iHeaderLineInfo.iSubjectLineCount = 0;
       
   317 
       
   318     iAttachmentHotSpotIndex = KErrNotFound;
       
   319     iViewHtmlHotSpotIndex = KErrNotFound;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CFSEmailUiMailViewerRichText::RichText
       
   324 // -----------------------------------------------------------------------------
       
   325 CFsRichText& CFSEmailUiMailViewerRichText::RichText()
       
   326 	{
       
   327     FUNC_LOG;
       
   328 	return *iViewerRichText;
       
   329 	}
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CFSEmailUiMailViewerRichText::SentTextLine
       
   333 // -----------------------------------------------------------------------------
       
   334 TInt CFSEmailUiMailViewerRichText::SentTextLine() const
       
   335     {
       
   336     FUNC_LOG;
       
   337     return iSentTextLine;
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CFSEmailUiMailViewerRichText::SubjectTextLine
       
   342 // -----------------------------------------------------------------------------
       
   343 TInt CFSEmailUiMailViewerRichText::SubjectTextLine() const
       
   344 	{
       
   345     FUNC_LOG;
       
   346 	return iSubjectTextLine;
       
   347 	}
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CFSEmailUiMailViewerRichText::AttachmentTextLine
       
   351 // -----------------------------------------------------------------------------
       
   352 TInt CFSEmailUiMailViewerRichText::AttachmentTextLine() const
       
   353 	{
       
   354     FUNC_LOG;
       
   355 	TInt line = KErrNotFound;
       
   356 	if ( iAttachmentHotSpotIndex >= 0 &&
       
   357 	     iAttachmentHotSpotIndex < iViewerHeadingHotSpotData.Count() )
       
   358 	    {
       
   359 	    line = iViewerHeadingHotSpotData[ iAttachmentHotSpotIndex ].iHotspotLine;
       
   360 	    }
       
   361 	return line;
       
   362 	}
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CFSEmailUiMailViewerRichText::ViewHtmlTextLine
       
   366 // -----------------------------------------------------------------------------
       
   367 TInt CFSEmailUiMailViewerRichText::ViewHtmlTextLine() const
       
   368     {
       
   369     FUNC_LOG;
       
   370     TInt line = KErrNotFound;
       
   371     if ( iViewHtmlHotSpotIndex >= 0 &&
       
   372          iViewHtmlHotSpotIndex < iViewerHeadingHotSpotData.Count() )
       
   373         {
       
   374         line = iViewerHeadingHotSpotData[ iViewHtmlHotSpotIndex ].iHotspotLine;
       
   375         }
       
   376     return line;
       
   377     }
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CFSEmailUiMailViewerRichText::HeaderLengthInCharacters
       
   381 // -----------------------------------------------------------------------------
       
   382 TInt CFSEmailUiMailViewerRichText::HeaderLengthInCharacters() const
       
   383 	{
       
   384     FUNC_LOG;
       
   385 	return iHeaderLength;
       
   386 	}
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CFSEmailUiMailViewerRichText::UpdateIconL
       
   390 // -----------------------------------------------------------------------------
       
   391 void CFSEmailUiMailViewerRichText::UpdateIconL( TViewerIconType aViewerIconType )
       
   392 	{
       
   393     FUNC_LOG;
       
   394 	TInt place = 0;
       
   395 
       
   396 // <cmail> icons changed
       
   397 
       
   398 	CFbsBitmap* imageImage = NULL;
       
   399 	CFbsBitmap* mask = NULL;
       
   400 	TSize newIconSize = iAppUi.LayoutHandler()->ViewerIconSize();
       
   401 	TFileName iconFile;
       
   402 	TFsEmailUiUtility::GetFullIconFileNameL( iconFile );
       
   403 	// Load right icon according to type
       
   404 	// Email status and follow up icons have their fixed places.
       
   405 	// Spacing and indentation icons are always appended to the end of the rich text and
       
   406 	// they are always transparent.
       
   407 	switch ( aViewerIconType )
       
   408 		{
       
   409 	    case EViewerEmailStatus:
       
   410 	        {
       
   411 	        TFSEmailUiTextures textureId = TFsEmailUiUtility::GetMsgIconTextureId( iMessage );
       
   412 	        iAppUi.FsTextureManager()->ProvideBitmapL( textureId, imageImage, mask );
       
   413 	        place = iEmailStatusIconPlace;
       
   414 	        }
       
   415             break;
       
   416 	    case EViewerIconFollowUp:
       
   417 	        {
       
   418 	        AknsUtils::CreateColorIconL(
       
   419                 AknsUtils::SkinInstance(),
       
   420                 KAknsIIDNone,
       
   421                 KAknsIIDQsnIconColors,
       
   422                 EAknsCIQsnIconColorsCG7,
       
   423                 imageImage,
       
   424                 mask,
       
   425                 iconFile,
       
   426                 EMbmFreestyleemailuiQgn_indi_navi_follow_up,
       
   427                 EMbmFreestyleemailuiQgn_indi_navi_follow_up_mask,
       
   428                 KRgbBlack );
       
   429 	        AknIconUtils::DisableCompression( imageImage );
       
   430 	        AknIconUtils::DisableCompression( mask );
       
   431 	        place = iFollowupIconPlace;
       
   432 	        }
       
   433 	        break;
       
   434 	    case EViewerIconFollowUpComplete:
       
   435 	        {
       
   436 	        AknsUtils::CreateColorIconL(
       
   437                 AknsUtils::SkinInstance(),
       
   438                 KAknsIIDNone,
       
   439                 KAknsIIDQsnIconColors,
       
   440                 EAknsCIQsnIconColorsCG7,
       
   441                 imageImage,
       
   442                 mask,
       
   443                 iconFile,
       
   444                 EMbmFreestyleemailuiQgn_indi_navi_follow_up_complete,
       
   445                 EMbmFreestyleemailuiQgn_indi_navi_follow_up_complete_mask,
       
   446                 KRgbBlack );
       
   447 	        AknIconUtils::DisableCompression( imageImage );
       
   448 	        AknIconUtils::DisableCompression( mask );
       
   449 	        place = iFollowupIconPlace;
       
   450 	        }
       
   451 	        break;
       
   452 	    case EViewerIconFollowUpNone:
       
   453 	        {
       
   454 	        AknIconUtils::CreateIconL( imageImage, mask, iconFile,
       
   455 	                EMbmFreestyleemailuiQgn_graf_cmail_blank,
       
   456 	                EMbmFreestyleemailuiQgn_graf_cmail_blank_mask );
       
   457 	        AknIconUtils::DisableCompression( imageImage );
       
   458 	        AknIconUtils::DisableCompression( mask );
       
   459 	        place = iFollowupIconPlace;
       
   460 	        }
       
   461 	        break;
       
   462 	    case EViewerAttachment:
       
   463 	        {
       
   464 	        AknIconUtils::CreateIconL( imageImage, mask, iconFile,
       
   465 	                EMbmFreestyleemailuiQgn_indi_cmail_attachment,
       
   466 	                EMbmFreestyleemailuiQgn_indi_cmail_attachment_mask );
       
   467 	        AknIconUtils::DisableCompression( imageImage );
       
   468 	        AknIconUtils::DisableCompression( mask );
       
   469 	        place = iAttachmentIconPlace;
       
   470 	        // Make the attachment icon a bit smaller than other icons. Shrink only the height:
       
   471 	        // when aspect ratio is preserved, the shrinked image will be centered within the standard width icon.
       
   472 	        // <cmail> Platform layout change
       
   473 	        //newIconSize.iHeight = newIconSize.iHeight * 3 / 4;
       
   474             // </cmail> Platform layout change
       
   475 	        }
       
   476 	        break;
       
   477 	    case EViewerIconIndentation:
       
   478 	        {
       
   479 	        AknIconUtils::CreateIconL( imageImage, mask, iconFile,
       
   480 	                EMbmFreestyleemailuiQgn_graf_cmail_blank,
       
   481 	                EMbmFreestyleemailuiQgn_graf_cmail_blank_mask );
       
   482 	        AknIconUtils::DisableCompression( imageImage );
       
   483 	        AknIconUtils::DisableCompression( mask );
       
   484 	        place = iViewerRichText->DocumentLength();
       
   485 	        }
       
   486 	        break;
       
   487 	    case EViewerIconSpacing:
       
   488 	        {
       
   489 	        AknIconUtils::CreateIconL( imageImage, mask, iconFile,
       
   490 	                EMbmFreestyleemailuiQgn_graf_cmail_blank,
       
   491 	                EMbmFreestyleemailuiQgn_graf_cmail_blank_mask );
       
   492 	        AknIconUtils::DisableCompression( imageImage );
       
   493 	        AknIconUtils::DisableCompression( mask );
       
   494 	        place = iViewerRichText->DocumentLength();
       
   495 	        // for spacing icon iCurrentSpacingIconSize need to be calculated beforehand
       
   496 	        // and set properly
       
   497 	        newIconSize = iCurrentSpacingIconSize;
       
   498 	        }
       
   499 	        break;
       
   500 	    // <cmail> separator line   
       
   501 	    case EViewerIconSeparatorLine:
       
   502 	        {
       
   503             TRgb colorToFetch = iAppUi.LayoutHandler()->SeparatorLineColor();  	        
       
   504             TSize lineSize = iAppUi.LayoutHandler()->SeparatorGraphicSizeInThisResolution();           
       
   505             TInt KMyTempHigh = lineSize.iHeight;
       
   506             // Graphic elments width is too large for these rich text classes
       
   507             // and thus we have to calculate proper width by ourself.
       
   508             TInt KMyTempWidth =  SeparatorLineWidth();    
       
   509  	        
       
   510 	        // create a bitmap to be used off-screen
       
   511 	        CFbsBitmap* offScreenBitmap = new (ELeave) CFbsBitmap();
       
   512 	        User::LeaveIfError(offScreenBitmap->Create(TSize(KMyTempWidth,KMyTempHigh), 
       
   513 	                iAppUi.DisplayMode()));
       
   514 	        CleanupStack::PushL(offScreenBitmap);
       
   515 	        
       
   516 	        mask = new (ELeave) CFbsBitmap(); 
       
   517             CleanupStack::PushL(mask);	        
       
   518 
       
   519 	        // create an off-screen device and context
       
   520 	        CGraphicsContext* bitmapContext=NULL;
       
   521 	        CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(offScreenBitmap);
       
   522 	        CleanupStack::PushL(bitmapDevice);
       
   523 	        User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
       
   524 	        CleanupStack::PushL(bitmapContext);
       
   525 
       
   526 	        TRect rect(0,0,KMyTempWidth,KMyTempHigh);
       
   527 	        bitmapContext->SetBrushColor(colorToFetch);
       
   528 	        bitmapContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   529 	        bitmapContext->SetPenColor(colorToFetch);	        
       
   530 	        bitmapContext->DrawRect(rect); 
       
   531 
       
   532 	        imageImage = offScreenBitmap;
       
   533             AknIconUtils::DisableCompression( imageImage );
       
   534             place = iViewerRichText->DocumentLength();	        
       
   535             newIconSize = TSize( KMyTempWidth,KMyTempHigh);
       
   536             // cleanup
       
   537             CleanupStack::PopAndDestroy(2);        
       
   538             CleanupStack::Pop(2);            
       
   539 	        }
       
   540 	        break;
       
   541 	    // </cmail> separator line  	        
       
   542 	    default:
       
   543 	        {
       
   544 	        User::Leave( KErrNotSupported );
       
   545 	        }
       
   546             break;
       
   547 		}
       
   548 // </cmail>
       
   549 
       
   550 	AknIconUtils::SetSize( imageImage, newIconSize, EAspectRatioPreserved );
       
   551 	AknIconUtils::SetSize( mask, newIconSize, EAspectRatioPreserved );
       
   552 
       
   553 	// Create picture object, which takes ownership of bitmaps
       
   554     CleanupStack::PushL( imageImage );
       
   555     CleanupStack::PushL( mask );
       
   556 	CMyPicture* picture = new ( ELeave ) CMyPicture( newIconSize, *imageImage, *mask );
       
   557     CleanupStack::Pop( mask );
       
   558 	CleanupStack::Pop( imageImage );
       
   559 
       
   560 	CleanupStack::PushL( picture );
       
   561 
       
   562 	// remove old picture if there is one.
       
   563 	if ( place < iViewerRichText->DocumentLength() )
       
   564 		{
       
   565 		iViewerRichText->DeleteL( place, 1 );
       
   566 		}
       
   567 
       
   568     // Insert header object to the right spot
       
   569     TPictureHeader header;
       
   570     header.iPicture = TSwizzle<CPicture>( picture );
       
   571 	CleanupStack::Pop( picture ); // The following call will always take the ownership of the picture pointed in the header. Not only when succesful.
       
   572 	iViewerRichText->InsertL( place, header );
       
   573 	}
       
   574 
       
   575 // -----------------------------------------------------------------------------
       
   576 // CFSEmailUiMailViewerRichText::FindCurrentHeaderHotSpotL
       
   577 // -----------------------------------------------------------------------------
       
   578 TBool CFSEmailUiMailViewerRichText::FindCurrentHeaderHotSpotL( SViewerHeadingHotSpotData& aCurrentHotSpot ) const
       
   579 	{
       
   580     FUNC_LOG;
       
   581 	TBool foundHotSpot = EFalse;
       
   582 	TInt start(0);
       
   583 	TInt end(0);
       
   584 	if ( iTextViewer )
       
   585 		{
       
   586 		iTextViewer->GetCurrentHotspotL( start, end );
       
   587 		TInt headingHotSpotCount = iViewerHeadingHotSpotData.Count();
       
   588 		if ( headingHotSpotCount > 0 )
       
   589 			{
       
   590 			TInt headingHotspotEnd = iViewerHeadingHotSpotData[ headingHotSpotCount-1 ].iEnd;
       
   591 			if ( start < headingHotspotEnd )
       
   592 				{
       
   593 				for ( TInt i = 0 ; i < headingHotSpotCount ; i++ )
       
   594 					{
       
   595 					if ( iViewerHeadingHotSpotData[ i ].iStart == start )
       
   596 						{
       
   597 						aCurrentHotSpot = iViewerHeadingHotSpotData[ i ];
       
   598 						foundHotSpot = ETrue;
       
   599 						break;
       
   600 						}
       
   601 					}
       
   602 				}
       
   603 			}
       
   604 		}
       
   605 	return foundHotSpot;
       
   606 	}
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CFSEmailUiMailViewerRichText::FindCurrentBodyHotSpotL
       
   610 // -----------------------------------------------------------------------------
       
   611 TBool CFSEmailUiMailViewerRichText::FindCurrentBodyHotSpotL( CFindItemEngine::SFoundItem& aCurrentHotSpot  ) const
       
   612 	{
       
   613     FUNC_LOG;
       
   614 	TBool foundHotSpot = EFalse;
       
   615 	TInt start(0);
       
   616 	TInt end(0);
       
   617 	if ( iTextViewer )
       
   618 		{
       
   619 		iTextViewer->GetCurrentHotspotL( start, end );
       
   620 		for ( TInt a = 0 ; a < iBodyTextHotSpotData.Count() ; a++ )
       
   621 			{
       
   622 			if ( start == iBodyTextHotSpotData[a].iStartPos + iHeaderLength )
       
   623 				{
       
   624 				aCurrentHotSpot = iBodyTextHotSpotData[a];
       
   625 				foundHotSpot = ETrue;
       
   626 				break;
       
   627 				}
       
   628 			}
       
   629 		}
       
   630 	return foundHotSpot;
       
   631  	}
       
   632 
       
   633 // -----------------------------------------------------------------------------
       
   634 // CFSEmailUiMailViewerRichText::FindCurrentHotSpotL
       
   635 // -----------------------------------------------------------------------------
       
   636 THotspotType CFSEmailUiMailViewerRichText::FindCurrentHotSpotL(
       
   637 									SViewerHeadingHotSpotData& aHeaderHotspot,
       
   638 									CFindItemEngine::SFoundItem& aBodyHotspot ) const
       
   639 	{
       
   640     FUNC_LOG;
       
   641 	THotspotType retVal = ENoHotspot;
       
   642 	if ( FindCurrentHeaderHotSpotL( aHeaderHotspot ) )
       
   643 		{
       
   644 		retVal = EHeaderHotspot;
       
   645 		}
       
   646 	else if ( FindCurrentBodyHotSpotL( aBodyHotspot ) )
       
   647 		{
       
   648 		retVal = EBodyHotspot;
       
   649 		}
       
   650 	return retVal;
       
   651 	}
       
   652 
       
   653 // -----------------------------------------------------------------------------
       
   654 // CFSEmailUiMailViewerRichText::GetHotspotTextLC, heading hotspots
       
   655 // -----------------------------------------------------------------------------
       
   656 HBufC* CFSEmailUiMailViewerRichText::GetHotspotTextLC(
       
   657     const SViewerHeadingHotSpotData& aHotSpot ) const
       
   658     {
       
   659     FUNC_LOG;
       
   660     TInt hotspotTextLength = aHotSpot.iEnd - aHotSpot.iStart;
       
   661     if ( aHotSpot.iEnd == aHotSpot.iStart ) // check for special case
       
   662         {
       
   663         hotspotTextLength = 1;
       
   664         }
       
   665 
       
   666     return GetHotspotTextLC( aHotSpot.iStart, hotspotTextLength );
       
   667     }
       
   668 
       
   669 // -----------------------------------------------------------------------------
       
   670 // CFSEmailUiMailViewerRichText::GetHotspotTextLC, body text hotspots
       
   671 // -----------------------------------------------------------------------------
       
   672 HBufC* CFSEmailUiMailViewerRichText::GetHotspotTextLC(
       
   673     const CFindItemEngine::SFoundItem& /*aHotSpot*/ ) const
       
   674     {
       
   675     FUNC_LOG;
       
   676     HBufC* hotspotText = iTextViewer->GetCurrentHotspotTextL();
       
   677 	CleanupStack::PushL( hotspotText );
       
   678     return hotspotText;
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CFSEmailUiMailViewerRichText::GetEmailAddressLC
       
   683 // -----------------------------------------------------------------------------
       
   684 HBufC* CFSEmailUiMailViewerRichText::GetEmailAddressLC(
       
   685 						const SViewerHeadingHotSpotData& aCurrentHotSpot ) const
       
   686 	{
       
   687     FUNC_LOG;
       
   688 	HBufC* emailAddress = NULL;
       
   689 	if( aCurrentHotSpot.iType == ETypeFromAddressDisplayName )
       
   690 		{
       
   691 		CFSMailAddress* mailAddressObject = iMessage->GetSender();
       
   692 		emailAddress = mailAddressObject->GetEmailAddress().AllocLC();
       
   693 		}
       
   694 	else if( aCurrentHotSpot.iType == ETypeToAddressDisplayName )
       
   695 		{
       
   696 		RPointerArray<CFSMailAddress>& addressArray = iMessage->GetToRecipients();
       
   697 		emailAddress = addressArray[aCurrentHotSpot.iDisplayNameArrayIndex]->GetEmailAddress().AllocLC();
       
   698 		}
       
   699 	else if( aCurrentHotSpot.iType == ETypeCcAddressDisplayName )
       
   700 		{
       
   701 		RPointerArray<CFSMailAddress>& addressArray =  iMessage->GetCCRecipients();
       
   702 		emailAddress = addressArray[aCurrentHotSpot.iDisplayNameArrayIndex]->GetEmailAddress().AllocLC();
       
   703 		}
       
   704 	else if( aCurrentHotSpot.iType == ETypeBccAddressDisplayName )
       
   705 		{
       
   706 		RPointerArray<CFSMailAddress>& addressArray = iMessage->GetBCCRecipients();
       
   707 		emailAddress = addressArray[aCurrentHotSpot.iDisplayNameArrayIndex]->GetEmailAddress().AllocLC();
       
   708 		}
       
   709 	else if( aCurrentHotSpot.iType == ETypeEmailAddress )
       
   710 		{
       
   711 		emailAddress = GetHotspotTextLC( aCurrentHotSpot );
       
   712 		}
       
   713 	else
       
   714 		{
       
   715 		User::Leave( KErrNotSupported );
       
   716 		}
       
   717 	return emailAddress;
       
   718 	}
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CFSEmailUiMailViewerRichText::GetHeaderHotspotEmailAddressLC
       
   722 // -----------------------------------------------------------------------------
       
   723 HBufC* CFSEmailUiMailViewerRichText::GetHeaderHotspotEmailAddressLC(
       
   724 			const SViewerHeadingHotSpotData& aCurrentHeaderHotSpotData ) const
       
   725 	{
       
   726     FUNC_LOG;
       
   727 	return GetEmailAddressLC( aCurrentHeaderHotSpotData );
       
   728 	}
       
   729 
       
   730 
       
   731 
       
   732 // -----------------------------------------------------------------------------
       
   733 // CFSEmailUiMailViewerRichText::AppendRecipientIndetationL
       
   734 // -----------------------------------------------------------------------------
       
   735 void CFSEmailUiMailViewerRichText::AppendRecipientIndetationL()
       
   736 	{
       
   737     FUNC_LOG;
       
   738 	// add transparent indentation icon here, to get right indentation in pixels
       
   739 	UpdateIconL( EViewerIconIndentation );
       
   740 	}
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // CFSEmailUiMailViewerRichText::AppendNewLineL
       
   744 // -----------------------------------------------------------------------------
       
   745 void CFSEmailUiMailViewerRichText::AppendNewLineL()
       
   746     {
       
   747     FUNC_LOG;
       
   748     AppendFormattedTextL( KLineFeed, EViewerFontText );
       
   749     }
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // CFSEmailUiMailViewerRichText::AppendSpaceL
       
   753 // -----------------------------------------------------------------------------
       
   754 void CFSEmailUiMailViewerRichText::AppendSpaceL()
       
   755     {
       
   756     FUNC_LOG;
       
   757     AppendFormattedTextL( KSpace, EViewerFontText );
       
   758     }
       
   759 
       
   760 // -----------------------------------------------------------------------------
       
   761 // CFSEmailUiMailViewerRichText::ClipHeaderInfoToFitLC
       
   762 // -----------------------------------------------------------------------------
       
   763 //<cmail>
       
   764 HBufC* CFSEmailUiMailViewerRichText::ClipHeaderInfoToFitLC( const TDesC& aText, TBool aIsDisplayName )
       
   765 	{
       
   766 	FUNC_LOG;
       
   767 	// Clip to fit in available amouth of pixels
       
   768     const CAknLayoutFont* textNameFont = GetCorrectFontL( EViewerFontHotspotNormal );
       
   769     // <cmail> Platform layout change
       
   770     TInt textWidthInPixels = HeaderIndentedTextAreaWidth( EFalse );
       
   771     // </cmail> Platform layout change
       
   772 	// create new descriptor for the clipped text.
       
   773 	HBufC* textBuffer = aText.AllocLC();
       
   774 	// Drop out unwanted characters from display name such as <> and ""
       
   775 	if ( aIsDisplayName && textBuffer )
       
   776 		{
       
   777 		TFsEmailUiUtility::StripDisplayName( *textBuffer );
       
   778 		textWidthInPixels -= iAppUi.LayoutHandler()->ViewerIconSize().iWidth;
       
   779 		}
       
   780 	TPtr textBufferModDes = textBuffer->Des();
       
   781 	AknTextUtils::ClipToFit( textBufferModDes, *textNameFont, textWidthInPixels );
       
   782 	return textBuffer;
       
   783 	}
       
   784 //</cmail>
       
   785 
       
   786 // -----------------------------------------------------------------------------
       
   787 // CFSEmailUiMailViewerRichText::HeaderIndentedTextAreaWidth
       
   788 // -----------------------------------------------------------------------------
       
   789 TInt CFSEmailUiMailViewerRichText::HeaderIndentedTextAreaWidth( const TBool aAddExtra ) const
       
   790     {
       
   791     FUNC_LOG;
       
   792     // For some reason, the ratioanally calculated text width seems to be a bit
       
   793     // wider than the width where GenericTextViewer does line wrapping. Reserve
       
   794     // some extra pixels to overcome this. Maybe there is some difference in
       
   795     // the ways the text width is calculated?
       
   796     // <cmail> Platform layout change
       
   797     //const TInt KExtraPixels = 10;
       
   798     TInt extraPixels( 10 );
       
   799     if ( aAddExtra )
       
   800         {
       
   801         const CAknLayoutFont* newFont = NULL;
       
   802         TRAP_IGNORE( newFont = GetCorrectFontL( EViewerFontText ) );
       
   803         if ( newFont )
       
   804             {
       
   805             TOpenFontMetrics fontMetrics;
       
   806             newFont->GetFontMetrics( fontMetrics );
       
   807             extraPixels = fontMetrics.MaxWidth();
       
   808             }
       
   809         }
       
   810     // </cmail> Platform layout change
       
   811 
       
   812     TRect screenRect = iTextViewer->GetControl()->DisplayArea();
       
   813 
       
   814     TInt recipientIndenInpixels = iAppUi.LayoutHandler()->ViewerIndentationIconSize().iWidth;
       
   815     TInt scrollBarBreadth = CEikScrollBar::DefaultScrollBarBreadth();
       
   816 
       
   817     // Calculate space left for actual text
       
   818     TInt rightMargin = iAppUi.LayoutHandler()->ViewerRightMarginInPixels() + scrollBarBreadth;
       
   819     TInt leftMargin = iAppUi.LayoutHandler()->ViewerLeftMarginInPixels();
       
   820     TInt textWidthInPixels = screenRect.iBr.iX - recipientIndenInpixels - rightMargin - leftMargin - extraPixels;
       
   821 
       
   822     return textWidthInPixels;
       
   823     }
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CFSEmailUiMailViewerRichText::AppendFromLineL
       
   827 // -----------------------------------------------------------------------------
       
   828 void CFSEmailUiMailViewerRichText::AppendFromLineL( CFSMailMessage& aMessagePtr,
       
   829                                                     SMailMsgHeaderInfo& aHeaderInfo )
       
   830 	{
       
   831     FUNC_LOG;
       
   832 
       
   833 	// Add the upmost space before the header information
       
   834 	InsertTransparentSpacingIconL( ETopMostSpace );
       
   835 
       
   836 	CFSMailAddress* fromAddress = aMessagePtr.GetSender();
       
   837 	if ( fromAddress )
       
   838 		{
       
   839 	 	// Append "from:" text
       
   840 	  	HBufC* fromHeadingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_FROM );
       
   841         AppendFormattedTextL( *fromHeadingText, EViewerFontTitle );
       
   842 		CleanupStack::PopAndDestroy( fromHeadingText );
       
   843 
       
   844 		// Append new line
       
   845 		AppendNewLineL();
       
   846 		aHeaderInfo.iHeaderLineCount++;
       
   847 
       
   848 		AppendRecipientIndetationL();
       
   849 
       
   850 		TDesC* displayName = &fromAddress->GetDisplayName();
       
   851 		TDesC* emailAddrs = &fromAddress->GetEmailAddress();
       
   852 		if ( displayName && displayName->Length() != 0 )
       
   853 			{
       
   854 			HBufC* clippedDisplayName = ClipHeaderInfoToFitLC( *displayName, ETrue );
       
   855 
       
   856 			// Append display name and hotspot
       
   857 			InsertHotspotTextAndFontL( *clippedDisplayName );
       
   858 
       
   859 			// Add hotspot information to rich text and hotspot data to header hotspots array
       
   860 			TInt hotSpotLength = clippedDisplayName->Length();
       
   861 			iViewerRichText->SetHotSpotL( iRichTextDocumentLength, hotSpotLength, KHotspotHighlightOn );
       
   862 			SViewerHeadingHotSpotData hsData;
       
   863 			hsData.iType = ETypeFromAddressDisplayName;
       
   864 			hsData.iStart = iRichTextDocumentLength;
       
   865 			hsData.iEnd = iRichTextDocumentLength + hotSpotLength;
       
   866 			hsData.iDisplayNameArrayIndex = 0;
       
   867 			hsData.iHotspotLine = aHeaderInfo.iHeaderLineCount;
       
   868 			iViewerHeadingHotSpotData.Append( hsData );
       
   869 
       
   870 			CleanupStack::PopAndDestroy( clippedDisplayName );
       
   871 
       
   872 			// Append new line
       
   873 			AppendNewLineL();
       
   874 			aHeaderInfo.iHeaderLineCount++;
       
   875 			}
       
   876 		else if ( emailAddrs && emailAddrs->Length() != 0 )
       
   877 			{
       
   878 			// clip emailAddress to fit in one line.
       
   879 			HBufC* clippedDisplayName = ClipHeaderInfoToFitLC( *displayName, ETrue );
       
   880 
       
   881 			// Append email address	and hotspot
       
   882 			InsertHotspotTextAndFontL( *clippedDisplayName );
       
   883 		 	TInt hotSpotLength = clippedDisplayName->Length();
       
   884 			iViewerRichText->SetHotSpotL(iRichTextDocumentLength, hotSpotLength, KHotspotHighlightOn );
       
   885 			SViewerHeadingHotSpotData hsData;
       
   886 			hsData.iType = ETypeEmailAddress;
       
   887 			hsData.iStart = iRichTextDocumentLength;
       
   888 			hsData.iEnd = iRichTextDocumentLength + hotSpotLength;
       
   889 			hsData.iDisplayNameArrayIndex = 0;
       
   890 			hsData.iHotspotLine = aHeaderInfo.iHeaderLineCount;
       
   891 			iViewerHeadingHotSpotData.Append( hsData );
       
   892 
       
   893 			CleanupStack::PopAndDestroy( clippedDisplayName );
       
   894 
       
   895 			// Append new line
       
   896 			AppendNewLineL();
       
   897 			aHeaderInfo.iHeaderLineCount++;
       
   898 			}
       
   899 		}
       
   900 	}
       
   901 
       
   902 
       
   903 // -----------------------------------------------------------------------------
       
   904 // CFSEmailUiMailViewerRichText::AppendRecipientsL
       
   905 // -----------------------------------------------------------------------------
       
   906 void CFSEmailUiMailViewerRichText::AppendRecipientsL(
       
   907 	const RPointerArray<CFSMailAddress>& aRecipientArray, SMailMsgHeaderInfo& aHeaderInfo,
       
   908 	TViewerRecipientType aRecipientType )
       
   909 	{
       
   910     FUNC_LOG;
       
   911 
       
   912  	TInt showAddresses(0);
       
   913 	TInt recipientCount = aRecipientArray.Count();
       
   914 	TInt maxRecipientCount = iAppUi.LayoutHandler()->ViewerMaxRecipientLineCount();
       
   915 
       
   916 	if ( recipientCount <= maxRecipientCount )
       
   917 		{
       
   918 		// All recipients fit to screen
       
   919 		showAddresses = recipientCount;
       
   920 		}
       
   921 	else
       
   922 		{
       
   923 		// Reserve space for additional recipients count
       
   924 		showAddresses = maxRecipientCount - 1;
       
   925 		}
       
   926 
       
   927 	for ( TInt i = 0; i < showAddresses; i++ )
       
   928 		{
       
   929 		iRichTextDocumentLength = iViewerRichText->DocumentLength();
       
   930 		TDesC* displayName = &( aRecipientArray[i]->GetDisplayName() );
       
   931 		TDesC* emailAddrs = &( aRecipientArray[i]->GetEmailAddress() );
       
   932 		if ( displayName && displayName->Length() != 0 )
       
   933 			{
       
   934 			AppendRecipientIndetationL();
       
   935 
       
   936 			HBufC* clippedDisplayName = ClipHeaderInfoToFitLC( *displayName, ETrue );
       
   937 
       
   938 			// Append display name and set hotspot data
       
   939 			InsertHotspotTextAndFontL( *clippedDisplayName );
       
   940 
       
   941 			iViewerRichText->SetHotSpotL( iRichTextDocumentLength, clippedDisplayName->Length(), KHotspotHighlightOn );
       
   942 			SViewerHeadingHotSpotData hsData;
       
   943 			switch ( aRecipientType )
       
   944 				{
       
   945 				case EViewerRecipientTypeCc:
       
   946 					hsData.iType = ETypeCcAddressDisplayName;
       
   947 					break;
       
   948 				case EViewerRecipientTypeBcc:
       
   949 					hsData.iType = ETypeBccAddressDisplayName;
       
   950 					break;
       
   951 				case EViewerRecipientTypeTo:
       
   952 				default:
       
   953 					hsData.iType = ETypeToAddressDisplayName;
       
   954 					break;
       
   955 				}
       
   956 			hsData.iStart = iRichTextDocumentLength;
       
   957 			hsData.iEnd = iRichTextDocumentLength + clippedDisplayName->Length();
       
   958 			hsData.iDisplayNameArrayIndex = i;
       
   959 			hsData.iHotspotLine = aHeaderInfo.iHeaderLineCount;
       
   960 			iViewerHeadingHotSpotData.Append( hsData );
       
   961 
       
   962 			CleanupStack::PopAndDestroy( clippedDisplayName );
       
   963 
       
   964 			// Append new line
       
   965 			AppendNewLineL();
       
   966 			aHeaderInfo.iHeaderLineCount++;
       
   967 			}
       
   968 		else if ( emailAddrs && emailAddrs->Length() != 0 )
       
   969 			{
       
   970 			AppendRecipientIndetationL();
       
   971 
       
   972 			// clip emailAddress to fit in one line.
       
   973 			HBufC* clippedDisplayName = ClipHeaderInfoToFitLC( *displayName, ETrue );
       
   974 
       
   975 			// Append email address name and set hotspot data
       
   976 			InsertHotspotTextAndFontL( *clippedDisplayName );
       
   977 			iViewerRichText->SetHotSpotL( iRichTextDocumentLength, clippedDisplayName->Length(), KHotspotHighlightOn );
       
   978 			SViewerHeadingHotSpotData hsData;
       
   979 			hsData.iType = ETypeEmailAddress;
       
   980 			hsData.iStart = iRichTextDocumentLength;
       
   981 			hsData.iEnd = iRichTextDocumentLength + clippedDisplayName->Length();
       
   982 			hsData.iHotspotLine = aHeaderInfo.iHeaderLineCount;
       
   983 			iViewerHeadingHotSpotData.Append( hsData );
       
   984 
       
   985 			CleanupStack::PopAndDestroy( clippedDisplayName );
       
   986 
       
   987 			// Append new line
       
   988 			AppendNewLineL();
       
   989 			aHeaderInfo.iHeaderLineCount++;
       
   990 			}
       
   991 		}
       
   992 	if ( recipientCount > showAddresses )
       
   993 		{
       
   994 		InsertTransparentSpacingIconL( EHeaderInfoSpace );
       
   995 
       
   996 		AppendRecipientIndetationL();
       
   997 
       
   998 		HBufC* nMoreRecipientsText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_N_MORE_RECIPIENTS, recipientCount );
       
   999 		// Append n more recipients address name and set hotspot data
       
  1000 		InsertHotspotTextAndFontL( *nMoreRecipientsText );
       
  1001 		iViewerRichText->SetHotSpotL(iRichTextDocumentLength, nMoreRecipientsText->Length(), KHotspotHighlightOn );
       
  1002 		SViewerHeadingHotSpotData hsData;
       
  1003 		switch ( aRecipientType )
       
  1004 			{
       
  1005 			case EViewerRecipientTypeCc:
       
  1006 				hsData.iType = ETypeCcNMoreRecipients;
       
  1007 				break;
       
  1008 			case EViewerRecipientTypeBcc:
       
  1009 				hsData.iType = ETypeBccNMoreRecipients;
       
  1010 				break;
       
  1011 			case EViewerRecipientTypeTo:
       
  1012 			default:
       
  1013 				hsData.iType = ETypeToNMoreRecipients;
       
  1014 				break;
       
  1015 			}
       
  1016 		hsData.iStart = iRichTextDocumentLength;
       
  1017 		hsData.iEnd = iRichTextDocumentLength+nMoreRecipientsText->Length();
       
  1018 		hsData.iHotspotLine = aHeaderInfo.iHeaderLineCount;
       
  1019 		iViewerHeadingHotSpotData.Append( hsData );
       
  1020 		// Append new line
       
  1021 		AppendNewLineL();
       
  1022 		aHeaderInfo.iHeaderLineCount++;
       
  1023 		CleanupStack::PopAndDestroy( nMoreRecipientsText );
       
  1024 		}
       
  1025 	}
       
  1026 
       
  1027 
       
  1028 // -----------------------------------------------------------------------------
       
  1029 // CFSEmailUiMailViewerRichText::AppendRecipientLinesL
       
  1030 // -----------------------------------------------------------------------------
       
  1031 void CFSEmailUiMailViewerRichText::AppendRecipientLinesL( CFSMailMessage& aMessagePtr,
       
  1032         SMailMsgHeaderInfo& aHeaderInfo, TViewerRecipientType aRecipientType )
       
  1033  	{
       
  1034     FUNC_LOG;
       
  1035 
       
  1036  	RPointerArray<CFSMailAddress>* mailAddressArray = NULL;
       
  1037  	HBufC* headingText = NULL;
       
  1038  	switch ( aRecipientType )
       
  1039  		{
       
  1040  		case EViewerRecipientTypeTo:
       
  1041  			{
       
  1042  			mailAddressArray = &aMessagePtr.GetToRecipients(); // ownership is not transfered.
       
  1043  			headingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_TO );
       
  1044  			}
       
  1045  		break;
       
  1046  		case EViewerRecipientTypeCc:
       
  1047  			{
       
  1048  			mailAddressArray = &aMessagePtr.GetCCRecipients(); // ownership is not transfered.
       
  1049  			headingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_CC );
       
  1050  			}
       
  1051  		break;
       
  1052  		case EViewerRecipientTypeBcc:
       
  1053  			{
       
  1054             mailAddressArray = &aMessagePtr.GetBCCRecipients(); // ownership is not transfered.
       
  1055  			headingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_BCC );
       
  1056 			}
       
  1057  		break;
       
  1058  		default:
       
  1059  			{
       
  1060  			// nothing here.
       
  1061  			}
       
  1062  		break;
       
  1063  		}
       
  1064 
       
  1065 	if ( mailAddressArray && mailAddressArray->Count() )
       
  1066 		{
       
  1067 		// Add vertical empty space between last recipient and new heading info text
       
  1068 		InsertTransparentSpacingIconL( EHeaderInfoSpace );
       
  1069 
       
  1070         AppendFormattedTextL( *headingText, EViewerFontTitle );
       
  1071 
       
  1072 		AppendNewLineL();
       
  1073 		aHeaderInfo.iHeaderLineCount++;
       
  1074 
       
  1075 		// Append the recipients
       
  1076 		AppendRecipientsL( *mailAddressArray, aHeaderInfo, aRecipientType );
       
  1077 		}
       
  1078 
       
  1079 	// cleanup if heading text was created
       
  1080 	if ( headingText )
       
  1081 		{
       
  1082 		CleanupStack::PopAndDestroy( headingText );
       
  1083 		}
       
  1084 
       
  1085  	}
       
  1086 
       
  1087 // -----------------------------------------------------------------------------
       
  1088 // CFSEmailUiMailViewerRichText::AppendSentLineL
       
  1089 // -----------------------------------------------------------------------------
       
  1090 void CFSEmailUiMailViewerRichText::AppendSentLineL( CFSMailMessage& aMessagePtr,
       
  1091 														   SMailMsgHeaderInfo& aHeaderInfo )
       
  1092 	{
       
  1093     FUNC_LOG;
       
  1094 
       
  1095 	InsertTransparentSpacingIconL( EHeaderInfoSpace );
       
  1096 
       
  1097 	// Save "Sent ..." text line number for initial focus setting
       
  1098 	iSentTextLine = aHeaderInfo.iHeaderLineCount;
       
  1099 
       
  1100 	HBufC* dateText = TFsEmailUiUtility::DateTextFromMsgLC( &aMessagePtr );
       
  1101 	HBufC* timeText = TFsEmailUiUtility::TimeTextFromMsgLC( &aMessagePtr );
       
  1102 	HBufC* sentHeadingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_SENT );
       
  1103 	HBufC* combinedSentText = sentHeadingText->ReAllocL( sentHeadingText->Length() + KSpace().Length() +
       
  1104 														dateText->Length() +
       
  1105 														KSentLineDateAndTimeSeparatorText().Length() +
       
  1106 														timeText->Length() );
       
  1107 	CleanupStack::Pop( sentHeadingText );
       
  1108 	CleanupStack::PushL( combinedSentText );
       
  1109 	TPtr combinedSentTextPtr = combinedSentText->Des();
       
  1110 	combinedSentTextPtr.Append( KSpace );
       
  1111 	combinedSentTextPtr.Append( *dateText );
       
  1112 	combinedSentTextPtr.Append( KSentLineDateAndTimeSeparatorText );
       
  1113 	combinedSentTextPtr.Append( *timeText );
       
  1114 
       
  1115     AppendFormattedTextL( *combinedSentText, EViewerFontSent );
       
  1116 
       
  1117 	CleanupStack::PopAndDestroy( combinedSentText );
       
  1118 	CleanupStack::PopAndDestroy( timeText );
       
  1119 	CleanupStack::PopAndDestroy( dateText );
       
  1120 
       
  1121 	AppendNewLineL();
       
  1122 	aHeaderInfo.iHeaderLineCount++;
       
  1123 	}
       
  1124 
       
  1125 // -----------------------------------------------------------------------------
       
  1126 // CFSEmailUiMailViewerRichText::AppendSubjectLinesL
       
  1127 // -----------------------------------------------------------------------------
       
  1128 void CFSEmailUiMailViewerRichText::AppendSubjectLinesL( CFSMailMessage& aMessagePtr,
       
  1129 														  SMailMsgHeaderInfo& aHeaderInfo )
       
  1130 	{
       
  1131     FUNC_LOG;
       
  1132 	InsertTransparentSpacingIconL( EHeaderInfoSpace );
       
  1133 
       
  1134 	// "Subject:" text
       
  1135 	HBufC* subjectHeadingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_SUBJECT );
       
  1136     AppendFormattedTextL( *subjectHeadingText, EViewerFontTitle );
       
  1137 	CleanupStack::PopAndDestroy( subjectHeadingText );
       
  1138 
       
  1139 	AppendNewLineL();
       
  1140 	aHeaderInfo.iHeaderLineCount++;
       
  1141 
       
  1142 	// Save "subject:" text line number for initial focus setting
       
  1143 	iSubjectTextLine = aHeaderInfo.iHeaderLineCount;
       
  1144 
       
  1145     TInt subjectLineCount = 0;
       
  1146 
       
  1147     // Get the subject text to modifyable buffer because truncation may be needed.
       
  1148     // Use "no subject" text if not available.
       
  1149     HBufC* subjectBuf = TFsEmailUiUtility::CreateSubjectTextLC( &aMessagePtr );
       
  1150     TPtr subjectPtr = subjectBuf->Des();
       
  1151 
       
  1152     // Wrap and clip to maximum number of lines
       
  1153     TInt subjectWidthInPixels = HeaderIndentedTextAreaWidth();
       
  1154     TInt maxSubjectLines = iAppUi.LayoutHandler()->ViewerMaxSubjectLineCount();
       
  1155     CArrayFixFlat<TPtrC>* wrappedArray = new (ELeave) CArrayFixFlat<TPtrC>( maxSubjectLines );
       
  1156     CleanupStack::PushL( wrappedArray );
       
  1157     CArrayFixFlat<TInt>* lineWidthArray = new (ELeave) CArrayFixFlat<TInt>( maxSubjectLines );
       
  1158     CleanupStack::PushL( lineWidthArray );
       
  1159     for ( TInt i = 0 ; i < maxSubjectLines ; ++i )
       
  1160         {
       
  1161         lineWidthArray->AppendL( subjectWidthInPixels );
       
  1162         }
       
  1163     //<cmail>
       
  1164     const CAknLayoutFont* subjectFont = GetCorrectFontL( EViewerFontText );
       
  1165 
       
  1166     AknTextUtils::WrapToArrayAndClipL( subjectPtr, *lineWidthArray, *subjectFont, *wrappedArray );
       
  1167     //</cmail>
       
  1168     subjectLineCount = wrappedArray->Count();
       
  1169 
       
  1170     TInt i = 1; // indicating current subject line, starting as 1 = first line, 2 = second line
       
  1171     for(  ; i <= subjectLineCount ; i++ )
       
  1172         {
       
  1173         // Rest of the lines have no preceeding icon, just indentation
       
  1174         AppendRecipientIndetationL();
       
  1175 
       
  1176         TPtrC temp = (*wrappedArray)[i-1];
       
  1177         AppendFormattedTextL( temp, EViewerFontText );
       
  1178 
       
  1179         // add line break
       
  1180         AppendNewLineL();
       
  1181         aHeaderInfo.iHeaderLineCount++;
       
  1182         aHeaderInfo.iSubjectLineCount++;
       
  1183         }
       
  1184 
       
  1185     CleanupStack::PopAndDestroy( lineWidthArray );
       
  1186     CleanupStack::PopAndDestroy( wrappedArray );
       
  1187     CleanupStack::PopAndDestroy( subjectBuf );
       
  1188 	}
       
  1189 
       
  1190 
       
  1191 // -----------------------------------------------------------------------------
       
  1192 // CFSEmailUiMailViewerRichText::AppendMessageIconL
       
  1193 // -----------------------------------------------------------------------------
       
  1194 void CFSEmailUiMailViewerRichText::AppendMessageIconL()
       
  1195 	{
       
  1196     FUNC_LOG;
       
  1197 	// append embedded icon.
       
  1198 	iEmailStatusIconPlace = iViewerRichText->DocumentLength();
       
  1199 	iEmailStatusIconLine = iHeaderLineInfo.iHeaderLineCount;
       
  1200 	UpdateIconL( EViewerEmailStatus );
       
  1201 	}
       
  1202 
       
  1203 // -----------------------------------------------------------------------------
       
  1204 // CFSEmailUiMailViewerRichText::AppendFollowUpIconL
       
  1205 // -----------------------------------------------------------------------------
       
  1206 TBool CFSEmailUiMailViewerRichText::AppendFollowUpIconL( CFSMailMessage& aMessagePtr )
       
  1207 	{
       
  1208     FUNC_LOG;
       
  1209 	TBool added = EFalse;
       
  1210 
       
  1211 	if ( TFsEmailUiUtility::IsFollowUpSupported( *iMailBox ) )
       
  1212 	    {
       
  1213 	    iFollowupIconPlace = iViewerRichText->DocumentLength();
       
  1214 	    iFollowupIconLine = iHeaderLineInfo.iHeaderLineCount;
       
  1215 	    if ( aMessagePtr.IsFlagSet( EFSMsgFlag_FollowUpComplete ) )
       
  1216 	        {
       
  1217 	        UpdateIconL( EViewerIconFollowUpComplete );
       
  1218 	        }
       
  1219 	    else if ( aMessagePtr.IsFlagSet( EFSMsgFlag_FollowUp ) )
       
  1220 	        {
       
  1221 	        UpdateIconL( EViewerIconFollowUp );
       
  1222 	        }
       
  1223 	    else
       
  1224 	        {
       
  1225 	        UpdateIconL( EViewerIconFollowUpNone );
       
  1226 	        }
       
  1227 	    added = ETrue;
       
  1228 	    }
       
  1229 
       
  1230 	return added;
       
  1231 	}
       
  1232 
       
  1233 // -----------------------------------------------------------------------------
       
  1234 // CFSEmailUiMailViewerRichText::AppendAttachmentIconL
       
  1235 // -----------------------------------------------------------------------------
       
  1236 void CFSEmailUiMailViewerRichText::AppendAttachmentIconL()
       
  1237     {
       
  1238     FUNC_LOG;
       
  1239     // append embedded icon.
       
  1240     iAttachmentIconPlace = iViewerRichText->DocumentLength();
       
  1241     UpdateIconL( EViewerAttachment );
       
  1242 
       
  1243     InsertSpaceAfterIconL();
       
  1244     }
       
  1245 
       
  1246 // -----------------------------------------------------------------------------
       
  1247 // CFSEmailUiMailViewerRichText::AppendAttachmentLinesL
       
  1248 // Append attachement(s) line to the rich text.
       
  1249 // -----------------------------------------------------------------------------
       
  1250 void CFSEmailUiMailViewerRichText::AppendAttachmentLinesL( CFSMailMessage& aMessagePtr, SMailMsgHeaderInfo& aHeaderInfo )
       
  1251  	{
       
  1252     FUNC_LOG;
       
  1253 	if ( aMessagePtr.IsFlagSet( EFSMsgFlag_Attachments ) )
       
  1254 		{
       
  1255 		// get attachments and count
       
  1256 		RPointerArray<CFSMailMessagePart> attachments;
       
  1257 		CleanupResetAndDestroyClosePushL( attachments );
       
  1258 		aMessagePtr.AttachmentListL( attachments );
       
  1259 		TInt attachmentsCount = attachments.Count();
       
  1260 		HBufC* attachmentText = NULL;
       
  1261 		if ( attachmentsCount == 1 )
       
  1262 			{
       
  1263 			TDesC& attachmentName = attachments[0]->AttachmentNameL();
       
  1264 			TUint attachmentSize = attachments[0]->ContentSize(); // bytes
       
  1265 
       
  1266 			// create size text including the unit and preceeding space character
       
  1267 			HBufC* sizeWithUnit = TFsEmailUiUtility::CreateSizeDescLC( attachmentSize );
       
  1268 			HBufC* sizeText = HBufC::NewL( sizeWithUnit->Length()+1 );
       
  1269 			sizeText->Des().Append( ' ' );
       
  1270 			sizeText->Des().Append( *sizeWithUnit );
       
  1271 			CleanupStack::PopAndDestroy( sizeWithUnit );
       
  1272 			CleanupStack::PushL( sizeText );
       
  1273 
       
  1274 			// clip attachment name to fit in one line so that size information has enough space too.
       
  1275 			 //<cmail>
       
  1276 			const CAknLayoutFont* attachmentFont = GetCorrectFontL( EViewerFontHotspotNormal );
       
  1277 
       
  1278 			TInt attachmentTextWidthInPixels = HeaderIndentedTextAreaWidth();
       
  1279 			TInt sizeTextInPixels = attachmentFont->TextWidthInPixels( *sizeText );
       
  1280 			TInt pixelsLeftForAttachmentName = attachmentTextWidthInPixels - sizeTextInPixels;
       
  1281 
       
  1282 			// safe check if the size information is too wide for some reason.
       
  1283 			if ( pixelsLeftForAttachmentName < 0 )
       
  1284 				{
       
  1285 				attachmentText = HBufC::NewL( attachmentName.Length() + sizeText->Length() );
       
  1286 				attachmentText->Des().Append( attachmentName );
       
  1287 				attachmentText->Des().Append( *sizeText );
       
  1288 				TPtr attachmentTextBufferModDes = attachmentText->Des();
       
  1289 				AknTextUtils::ClipToFit( attachmentTextBufferModDes, *attachmentFont, attachmentTextWidthInPixels );
       
  1290 				}
       
  1291 			else
       
  1292 				{ // normal case
       
  1293 				HBufC* attacmentNameBuffer = attachmentName.AllocLC();
       
  1294 				TPtr attachmentNameBufferModDes = attacmentNameBuffer->Des();
       
  1295 				AknTextUtils::ClipToFit( attachmentNameBufferModDes, *attachmentFont, pixelsLeftForAttachmentName );
       
  1296 
       
  1297 				attachmentText = HBufC::NewL( attacmentNameBuffer->Length() + sizeText->Length() );
       
  1298 				attachmentText->Des().Append( *attacmentNameBuffer );
       
  1299 				attachmentText->Des().Append( *sizeText );
       
  1300 				CleanupStack::PopAndDestroy( attacmentNameBuffer );
       
  1301 				}
       
  1302 			CleanupStack::PopAndDestroy( sizeText );
       
  1303 			}
       
  1304         //</cmail>
       
  1305 		else if ( attachmentsCount > 1 )
       
  1306 			{
       
  1307 			TInt totalSize = 0;
       
  1308 			for( TInt i = 0; i < attachmentsCount ; i++ )
       
  1309 				{
       
  1310 				totalSize += attachments[i]->ContentSize();
       
  1311 				}
       
  1312 			HBufC* sizeText = TFsEmailUiUtility::CreateSizeDescLC( totalSize );
       
  1313 			attachmentText = StringLoader::LoadL( R_FSE_VIEWER_ATTACHMENTS_TEXT_WITH_SIZE,
       
  1314 												  *sizeText, attachmentsCount );
       
  1315 			CleanupStack::PopAndDestroy( sizeText );
       
  1316 			}
       
  1317 
       
  1318 		// Append attachment line to rich text if there was attachments
       
  1319 		if ( attachmentText )
       
  1320 			{
       
  1321 			CleanupStack::PushL( attachmentText );
       
  1322 
       
  1323             InsertTransparentSpacingIconL( EHeaderInfoSpace );
       
  1324 
       
  1325 			AppendAttachmentIconL();
       
  1326 
       
  1327 			InsertHotspotTextAndFontL( *attachmentText );
       
  1328 			iViewerRichText->SetHotSpotL( iRichTextDocumentLength, attachmentText->Length(), KHotspotHighlightOn );
       
  1329 			SViewerHeadingHotSpotData hsData;
       
  1330 			if ( attachmentsCount == 1 )
       
  1331 				{
       
  1332 				hsData.iType = ETypeAttachment;
       
  1333 				}
       
  1334 			else
       
  1335 				{
       
  1336 				hsData.iType = ETypeAttachments;
       
  1337 				}
       
  1338 			hsData.iStart = iRichTextDocumentLength;
       
  1339 			hsData.iEnd = iRichTextDocumentLength + attachmentText->Length();
       
  1340 			hsData.iHotspotLine = aHeaderInfo.iHeaderLineCount;
       
  1341 			iAttachmentHotSpotIndex = iViewerHeadingHotSpotData.Count();
       
  1342 			iViewerHeadingHotSpotData.Append( hsData );
       
  1343 			CleanupStack::PopAndDestroy( attachmentText );
       
  1344 
       
  1345 			// Append new lines
       
  1346 			AppendNewLineL();
       
  1347 			aHeaderInfo.iHeaderLineCount++;
       
  1348 			}
       
  1349 		CleanupStack::PopAndDestroy( &attachments );
       
  1350 		}
       
  1351  	}
       
  1352 
       
  1353 // -----------------------------------------------------------------------------
       
  1354 // CFSEmailUiMailViewerRichText::AppendHtmlTextLineL
       
  1355 // Appends "View as HTML" selection hotspot to the rich text if message has HTML text part
       
  1356 // -----------------------------------------------------------------------------
       
  1357 void CFSEmailUiMailViewerRichText::AppendHtmlTextLineL( CFSMailMessage& aMessagePtr, SMailMsgHeaderInfo& aHeaderInfo )
       
  1358 	{
       
  1359     FUNC_LOG;
       
  1360     
       
  1361     CFSMailMessagePart* htmlBodyPart = aMessagePtr.HtmlBodyPartL();
       
  1362     if ( htmlBodyPart )
       
  1363 		{
       
  1364 	    CleanupStack::PushL( htmlBodyPart );
       
  1365 
       
  1366 	    // Add just a little bit of vertical space before the next lines
       
  1367 	    InsertTransparentSpacingIconL( EHeaderInfoSpace );
       
  1368 
       
  1369 	    // Indent the "View as HTML" link
       
  1370 	    AppendRecipientIndetationL();
       
  1371 
       
  1372 		HBufC* htmlLineText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_HTML );
       
  1373 		HBufC* clippedHtmlLine = ClipHeaderInfoToFitLC( *htmlLineText, EFalse );
       
  1374 
       
  1375 		InsertHotspotTextAndFontL( *clippedHtmlLine );
       
  1376 		iViewerRichText->SetHotSpotL( iRichTextDocumentLength, clippedHtmlLine->Length(), KHotspotHighlightOn );
       
  1377 		SViewerHeadingHotSpotData hsData;
       
  1378 		hsData.iType = ETypeHtml;
       
  1379 		hsData.iStart = iRichTextDocumentLength;
       
  1380 		hsData.iEnd = iRichTextDocumentLength + htmlLineText->Length();
       
  1381 		hsData.iHotspotLine = iHeaderLineInfo.iHeaderLineCount;
       
  1382 		iViewHtmlHotSpotIndex = iViewerHeadingHotSpotData.Count();
       
  1383 		iViewerHeadingHotSpotData.Append( hsData );
       
  1384 
       
  1385 		CleanupStack::PopAndDestroy( clippedHtmlLine );
       
  1386 		CleanupStack::PopAndDestroy( htmlLineText );
       
  1387 	    CleanupStack::PopAndDestroy( htmlBodyPart );
       
  1388 
       
  1389 	    // Append one line feed plus little extra vertical space
       
  1390         AppendNewLineL();
       
  1391         aHeaderInfo.iHeaderLineCount++;
       
  1392 		}
       
  1393 	}
       
  1394 
       
  1395 // -----------------------------------------------------------------------------
       
  1396 // CFSEmailUiMailViewerRichText::AppendInitialBodytextLinesL
       
  1397 // Append body text which is found from the message to the end of the rich text.
       
  1398 // If plain text body part is not found, tries to convert body from html part
       
  1399 // -----------------------------------------------------------------------------
       
  1400 void CFSEmailUiMailViewerRichText::AppendInitialBodytextLinesL( CFSMailMessage& aMessagePtr )
       
  1401 	{
       
  1402     FUNC_LOG;
       
  1403 	CFSMailMessagePart* plainTextBodyPart = aMessagePtr.PlainTextBodyPartL();
       
  1404 
       
  1405 	if ( plainTextBodyPart )
       
  1406 		{
       
  1407 		CleanupStack::PushL( plainTextBodyPart );
       
  1408 
       
  1409 		TInt fetchedSize = plainTextBodyPart->FetchedContentSize();
       
  1410 		if ( fetchedSize > 0 )
       
  1411 			{
       
  1412 			// Limit displayed plain text body size to KPlainTextLimitationInBytes
       
  1413 			// currently set to 150K characters of text that should be more than enough for mobile email
       
  1414 			TInt bufSize = Min( fetchedSize, KPlainTextLimitationInChars );
       
  1415             HBufC* plainTextData16 = HBufC::NewLC( bufSize );
       
  1416 
       
  1417 			TPtr pointer = plainTextData16->Des();
       
  1418 			plainTextBodyPart->GetContentToBufferL( pointer, 0 );
       
  1419 
       
  1420             // Store body length
       
  1421 			iBodyLength = plainTextData16->Length();
       
  1422 
       
  1423 			// append everything we have now
       
  1424             AppendFormattedTextL( *plainTextData16, EViewerFontText );
       
  1425 
       
  1426 			// Append hotspot data for content
       
  1427 			iBodyTextHotSpotData.Reset();
       
  1428 			FindBodyTextHotSpotsL( *plainTextData16 );
       
  1429 			CleanupStack::PopAndDestroy( plainTextData16 );
       
  1430             // Make sure that text viewer is not filled with more than max
       
  1431 			// number of hotspot count
       
  1432 			TInt hotspotCount = iBodyTextHotSpotData.Count();
       
  1433             if ( hotspotCount > KMaxHotspotCount )
       
  1434                 {
       
  1435                 hotspotCount = KMaxHotspotCount;
       
  1436                 }
       
  1437 			for ( TInt i=0; i < hotspotCount; i++ )
       
  1438 				{
       
  1439 				AddBodyHotsSpotWithTextFormatingL( iBodyTextHotSpotData[i] );
       
  1440 				}
       
  1441 			}
       
  1442 		CleanupStack::PopAndDestroy( plainTextBodyPart );
       
  1443 		}
       
  1444     else
       
  1445         {
       
  1446         CFSMailMessagePart* htmlBodyPart = aMessagePtr.HtmlBodyPartL();
       
  1447         if ( htmlBodyPart )
       
  1448             {
       
  1449             CleanupStack::PushL( htmlBodyPart );
       
  1450 
       
  1451             TInt fetchedBodySize = htmlBodyPart->FetchedContentSize();
       
  1452             TInt wholeContentSize = htmlBodyPart->ContentSize();
       
  1453             if ( fetchedBodySize == wholeContentSize )
       
  1454                 {
       
  1455                 HBufC* htmlData = HBufC::NewLC( fetchedBodySize );
       
  1456                 TPtr pointer = htmlData->Des();
       
  1457                 htmlBodyPart->GetContentToBufferL( pointer, 0 );
       
  1458                 HBufC* txtData = TFsEmailUiUtility::ConvertHtmlToTxtL( *htmlData );
       
  1459                 CleanupStack::PopAndDestroy( htmlData );
       
  1460                 CleanupStack::PushL( txtData );
       
  1461 
       
  1462                 // User large fixed maximum amount of characters to append.
       
  1463                 // In normal cases all text is included.
       
  1464                 TPtrC truncatedText = txtData->Left( KPlainTextLimitationInChars );
       
  1465                 iBodyLength = truncatedText.Length();
       
  1466                 AppendFormattedTextL( truncatedText, EViewerFontText );
       
  1467                 // Append hotspot data for content
       
  1468                 iBodyTextHotSpotData.Reset();
       
  1469                 FindBodyTextHotSpotsL( truncatedText );
       
  1470                 CleanupStack::PopAndDestroy( txtData );
       
  1471                 // Make sure that text viewer is not filled with more than max
       
  1472                 // number of hotspot count
       
  1473                 TInt hotspotCount = iBodyTextHotSpotData.Count();
       
  1474                 if ( hotspotCount > KMaxHotspotCount )
       
  1475                     {
       
  1476                     hotspotCount = KMaxHotspotCount;
       
  1477                     }
       
  1478                 for ( TInt i=0; i < hotspotCount; i++ )
       
  1479                     {
       
  1480                     AddBodyHotsSpotWithTextFormatingL( iBodyTextHotSpotData[i] );
       
  1481                     }
       
  1482                 }
       
  1483 
       
  1484             CleanupStack::PopAndDestroy( htmlBodyPart );
       
  1485             }
       
  1486         }
       
  1487     }
       
  1488 
       
  1489 // -----------------------------------------------------------------------------
       
  1490 // CFSEmailUiMailViewerRichText::AppendFetchedBodytextLinesL
       
  1491 // Append rest of the body text replacing "Fetching more text"
       
  1492 // -----------------------------------------------------------------------------
       
  1493 void CFSEmailUiMailViewerRichText::AppendFetchedBodytextLinesL( CFSMailMessage& aMessagePtr )
       
  1494 	{
       
  1495     FUNC_LOG;
       
  1496 	TInt startBodyPoint = iBodyLength;
       
  1497 	CFSMailMessagePart* plainTextBodyPart = aMessagePtr.PlainTextBodyPartL();
       
  1498 	if ( plainTextBodyPart )
       
  1499 		{
       
  1500 		CleanupStack::PushL( plainTextBodyPart );
       
  1501         // Fetching More text is not required any more
       
  1502 		SetEmptyStatusLayoutTextL();
       
  1503 
       
  1504 		// Limit the whole data reading to KPlainTextLimitationInChars, usually this is more than
       
  1505 		// enough for mobile email client
       
  1506 		TInt fetchedSize = plainTextBodyPart->FetchedContentSize();
       
  1507 		TInt bufSize = Min( fetchedSize, KPlainTextLimitationInChars );
       
  1508         HBufC* plainTextData16 = HBufC::NewLC( bufSize );
       
  1509 
       
  1510 		// Get more fetched content to buffer
       
  1511 		TPtr pointer = plainTextData16->Des();
       
  1512 		plainTextBodyPart->GetContentToBufferL( pointer, 0 );
       
  1513 
       
  1514         // Store body length
       
  1515 		iBodyLength = plainTextData16->Length();
       
  1516 
       
  1517 		// Safety check required by POP protocol. Sometimes iBodyLength changes
       
  1518 		// when message has been fetched. Following is added to prevent crashes related to that.
       
  1519 		if ( startBodyPoint > iBodyLength )
       
  1520 		    {
       
  1521 		    startBodyPoint = iBodyLength;
       
  1522 		    }
       
  1523 
       
  1524         // Insert rest of the body text after previously added body text
       
  1525         TPtrC restOfThePlainText = plainTextData16->Mid( startBodyPoint );
       
  1526         InsertFormattedTextL( restOfThePlainText, EViewerFontText,
       
  1527             iHeaderLength + startBodyPoint );
       
  1528 
       
  1529         // Find hotspots from the added body text
       
  1530 		TInt previousBodyHotspotCount = iBodyTextHotSpotData.Count();
       
  1531 		FindBodyTextHotSpotsL( restOfThePlainText );
       
  1532         // Make sure that text viewer is not filled with more than max
       
  1533         // number of hotspot count
       
  1534         TInt hotspotCount = iBodyTextHotSpotData.Count();
       
  1535         if ( hotspotCount > KMaxHotspotCount )
       
  1536              {
       
  1537              hotspotCount = KMaxHotspotCount;
       
  1538              }
       
  1539 		for ( TInt i = previousBodyHotspotCount; i < hotspotCount; i++ )
       
  1540 			{
       
  1541 			iBodyTextHotSpotData[i].iStartPos += startBodyPoint;
       
  1542 			AddBodyHotsSpotWithTextFormatingL( iBodyTextHotSpotData[i] );
       
  1543 			}
       
  1544 
       
  1545 	 	iTextViewer->ReloadTextL();
       
  1546 		CleanupStack::PopAndDestroy( plainTextData16 );
       
  1547 		CleanupStack::PopAndDestroy( plainTextBodyPart );
       
  1548 		}
       
  1549 
       
  1550 	}
       
  1551 
       
  1552 // -----------------------------------------------------------------------------
       
  1553 // CFSEmailUiMailViewerRichText::CreateStatusLayoutL
       
  1554 // Creates status layout to display fetching more text.
       
  1555 // -----------------------------------------------------------------------------
       
  1556 void CFSEmailUiMailViewerRichText::CreateStatusLayoutL( TBool aSetEmptyContents /*= ETrue*/ )
       
  1557     {
       
  1558     FUNC_LOG;
       
  1559     // ensure not created twice
       
  1560     if ( !iStatusVisual && iTextViewer )
       
  1561         {
       
  1562         iStatusLayout = static_cast<CAlfAnchorLayout*>( iTextViewer->GetStatusLayout() );
       
  1563         CAlfControl* textViewerControl = iTextViewer->GetControl();
       
  1564         iStatusVisual = CAlfTextVisual::AddNewL( *textViewerControl, iStatusLayout );
       
  1565         iStatusVisual->EnableShadow( EFalse );
       
  1566         iStatusVisual->SetColor( iAppUi.LayoutHandler()->ViewerBodyTextColor() );
       
  1567         
       
  1568         TAlfTimedValue statusVisualOpacity;
       
  1569         statusVisualOpacity.SetValueNow ( 1 );
       
  1570         iStatusVisual->SetOpacity( statusVisualOpacity );
       
  1571     
       
  1572         // <cmail> Platform layout change
       
  1573         /*iStatusVisual->SetTextStyle( iAppUi.LayoutHandler()->FSTextStyleFromIdL( EFSFontTypeSmallBold )->Id() );*/
       
  1574         iStatusVisual->SetTextStyle( iAppUi.LayoutHandler()->FSTextStyleFromLayoutL( AknLayoutScalable_Apps::list_single_cmail_header_caption_pane_t1() ).Id() );
       
  1575         // </cmail> Platform layout change
       
  1576         iStatusVisual->SetAlign( EAlfAlignHCenter, EAlfAlignVTop );
       
  1577 
       
  1578         if ( aSetEmptyContents )
       
  1579             {
       
  1580             SetEmptyStatusLayoutTextL();
       
  1581             }
       
  1582         }
       
  1583     }
       
  1584 
       
  1585 // -----------------------------------------------------------------------------
       
  1586 // CFSEmailUiMailViewerRichText::AppendFetchingMoreTextL
       
  1587 // metdod for updating the animated text while rest of the message is been fetched
       
  1588 // -----------------------------------------------------------------------------
       
  1589 void CFSEmailUiMailViewerRichText::AppendFetchingMoreTextL()
       
  1590     {
       
  1591     FUNC_LOG;
       
  1592     // Create status layout if it doesn't exist yet
       
  1593     CreateStatusLayoutL( EFalse );    
       
  1594 
       
  1595     // add fetching content text with current animation		
       
  1596     HBufC* fetchingContentText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_FETCHING_CONTENT_TEXT ); 
       
  1597 
       
  1598     // create buffer for "Fetching more text" and dots animation
       
  1599     HBufC* newDes = HBufC::NewLC( fetchingContentText->Length() + KTotalNumberOfLines + KTotalNumberOfLines);
       
  1600     TPtr des = newDes->Des();
       
  1601 
       
  1602     // add KTotalNumberOfLines always at the beginning
       
  1603     for( TInt i = 0 ; i < KTotalNumberOfLines / KNumberOfLines ; i++ )
       
  1604         {
       
  1605         des.Append( KThreeLines );
       
  1606         }
       
  1607 
       
  1608     // append fething text
       
  1609     des.Append( *fetchingContentText );
       
  1610 
       
  1611     // add dots according to current ellipsis count
       
  1612     for( TInt i = 0 ; i < iCurrentEllipsisCount ; i++ )
       
  1613         {
       
  1614         des.Append( KThreeLines );
       
  1615         }
       
  1616 
       
  1617     // ellipses count counter going through 0,1,2,3,0,1,2,3,0,... sequence
       
  1618     if( iCurrentEllipsisCount >= KTotalNumberOfLines / KNumberOfLines )
       
  1619         {
       
  1620         iCurrentEllipsisCount = 0;
       
  1621         }
       
  1622     else
       
  1623         {
       
  1624         iCurrentEllipsisCount++;
       
  1625         }
       
  1626 
       
  1627     // just in case, try clipping the text if it doesn't fit in one line for some reason.
       
  1628     TRect screenRect = iTextViewer->GetControl()->DisplayArea();
       
  1629     //<cmail>
       
  1630     const CAknLayoutFont* bodyTextFont = GetCorrectFontL( EViewerFontBody );
       
  1631     TInt rightMargin = iAppUi.LayoutHandler()->ViewerRightMarginInPixels();
       
  1632     TInt leftMargin = iAppUi.LayoutHandler()->ViewerLeftMarginInPixels();
       
  1633     TInt pixelsToFit = screenRect.iBr.iX - rightMargin - leftMargin;
       
  1634     AknTextUtils::ClipToFit( des, *bodyTextFont, pixelsToFit );
       
  1635     //</cmail>
       
  1636 
       
  1637     // Assign the text to status layout.
       
  1638     iStatusVisual->SetTextL( *newDes );
       
  1639     iStatusLayout->SetClipping( EFalse );
       
  1640     TSize statusSize = iStatusVisual->TextExtents();
       
  1641     iStatusLayout->SetSize( statusSize );
       
  1642     iStatusVisual->SetRect( TRect( TPoint( 0, 0 ), statusSize ) );
       
  1643     iTextViewer->UpdateStatusLayout();
       
  1644 
       
  1645     CleanupStack::PopAndDestroy( newDes );
       
  1646     CleanupStack::PopAndDestroy( fetchingContentText );
       
  1647     }
       
  1648 
       
  1649 // -----------------------------------------------------------------------------
       
  1650 // CFSEmailUiMailViewerRichText::SetEmptyStatusLayoutTextL
       
  1651 // The text in status layout is updated to contain only a couple of line feeds.
       
  1652 // This ensures, that the whole body can be scrolled visible also when the
       
  1653 // attachment downloading popup is shown in the bottom.
       
  1654 // -----------------------------------------------------------------------------
       
  1655 void CFSEmailUiMailViewerRichText::SetEmptyStatusLayoutTextL()
       
  1656     {
       
  1657     FUNC_LOG;
       
  1658     _LIT( KEmptyStatusText, "\n " );
       
  1659     if ( iStatusVisual && iStatusLayout && iTextViewer )
       
  1660         {
       
  1661         iStatusVisual->SetTextL( KEmptyStatusText );
       
  1662         iStatusLayout->SetClipping( EFalse );
       
  1663         TSize statusSize = iStatusVisual->TextExtents();
       
  1664         iStatusLayout->SetSize( statusSize );
       
  1665         iStatusVisual->SetRect( TRect( TPoint( 0, 0 ), statusSize ) );
       
  1666         iTextViewer->UpdateStatusLayout();
       
  1667         }
       
  1668     }
       
  1669 
       
  1670 // -----------------------------------------------------------------------------
       
  1671 // CFSEmailUiMailViewerRichText::SetHotspotHighlightedColorL
       
  1672 // -----------------------------------------------------------------------------
       
  1673 void CFSEmailUiMailViewerRichText::SetHotspotHighlightedColorL( TInt aStartIndx, TInt aLenght, TBool aHighlight )
       
  1674 	{
       
  1675     FUNC_LOG;
       
  1676     TCharFormat charFormat;
       
  1677     TCharFormatMask charFormatMask;
       
  1678     if ( aHighlight )
       
  1679         {
       
  1680         charFormat.iFontPresentation.iTextColor = SkinFontColorByType( EViewerFontHotspotHighLighted );
       
  1681         }
       
  1682     else
       
  1683         {
       
  1684         charFormat.iFontPresentation.iTextColor = SkinFontColorByType( EViewerFontHotspotNormal );
       
  1685         }
       
  1686 
       
  1687 	charFormatMask.SetAttrib( EAttColor );
       
  1688 	iViewerRichText->ApplyCharFormatL( charFormat, charFormatMask, aStartIndx, aLenght );
       
  1689 	iTextViewer->ReloadTextL();
       
  1690 	}
       
  1691 
       
  1692 // ---------------------------------------------------------------------------
       
  1693 // Getter for the index of the attachment hotspot
       
  1694 // ---------------------------------------------------------------------------
       
  1695 TInt CFSEmailUiMailViewerRichText::AttachmentHotSpotIndex() const
       
  1696     {
       
  1697     FUNC_LOG;
       
  1698     return iAttachmentHotSpotIndex;
       
  1699     }
       
  1700 
       
  1701 // ---------------------------------------------------------------------------
       
  1702 // Getter for the index of the View HTML hotspot
       
  1703 // ---------------------------------------------------------------------------
       
  1704 TInt CFSEmailUiMailViewerRichText::ViewHtmlHotSpotIndex() const
       
  1705     {
       
  1706     FUNC_LOG;
       
  1707     return iViewHtmlHotSpotIndex;
       
  1708     }
       
  1709 
       
  1710 // ---------------------------------------------------------------------------
       
  1711 // Helper function for getting hotspot text from rich text data
       
  1712 // ---------------------------------------------------------------------------
       
  1713 HBufC* CFSEmailUiMailViewerRichText::GetHotspotTextLC( TInt aStartPos,
       
  1714     TInt aLength ) const
       
  1715     {
       
  1716     FUNC_LOG;
       
  1717     __ASSERT_DEBUG( aStartPos >= 0, User::Invariant() );
       
  1718     __ASSERT_DEBUG( aLength > 0, User::Invariant() );
       
  1719 
       
  1720     HBufC* des = HBufC::NewLC( aLength );
       
  1721 
       
  1722     // Hotspot text is retrived in a loop, because the CPlainText::Read
       
  1723     // method may return only part of the requested text
       
  1724     TInt documentLength = iViewerRichText->DocumentLength();
       
  1725     while ( aLength > 0 && aStartPos < documentLength )
       
  1726         {
       
  1727         TPtrC text = iViewerRichText->Read( aStartPos, aLength );
       
  1728         des->Des().Append( text );
       
  1729         aLength -= text.Length();
       
  1730         aStartPos += text.Length();
       
  1731         }
       
  1732 
       
  1733     return des;
       
  1734     }
       
  1735 
       
  1736 // -----------------------------------------------------------------------------
       
  1737 // CFSEmailUiMailViewerRichText::FindBodyTextHotSpotsL
       
  1738 // -----------------------------------------------------------------------------
       
  1739 void CFSEmailUiMailViewerRichText::FindBodyTextHotSpotsL( const TDesC& aBodyContent )
       
  1740 	{
       
  1741     FUNC_LOG;
       
  1742 	// Use s60 find item engine to find hotspots from the body text
       
  1743 	CFindItemEngine* hotspotSearch = CFindItemEngine::NewL
       
  1744 		(
       
  1745 		aBodyContent,
       
  1746 		// define wanted
       
  1747 		(CFindItemEngine::TFindItemSearchCase)
       
  1748 		(CFindItemEngine::EFindItemSearchMailAddressBin |
       
  1749 		CFindItemEngine::EFindItemSearchPhoneNumberBin |
       
  1750 		CFindItemEngine::EFindItemSearchURLBin |
       
  1751 		CFindItemEngine::EFindItemSearchScheme )
       
  1752 		);
       
  1753 	CleanupStack::PushL( hotspotSearch );
       
  1754 
       
  1755 	// <cmail>
       
  1756 	// insert found data to member variable iHotSpotData
       
  1757 	const CArrayFixFlat<CFindItemEngine::SFoundItem>* itemArray = hotspotSearch->ItemArray();
       
  1758 	TInt itemCount = hotspotSearch->ItemCount();
       
  1759 	for ( TInt i = 0; i < itemCount; i++ )
       
  1760 		{
       
  1761 		CFindItemEngine::SFoundItem* foundItem = const_cast<CFindItemEngine::SFoundItem*> ( &itemArray->At( i ) );
       
  1762 		TBool foundSameHotspotTwice = EFalse;
       
  1763 		// Check if same hotspot is found twice. This may happen when both flags
       
  1764 		// EFindItemSearchScheme and EFindItemSearchURLBin are ON for search request.
       
  1765 		for ( TInt j = i + 1; j < itemCount; j++ )
       
  1766 			{
       
  1767 			if ( foundItem->iStartPos == itemArray->At( j ).iStartPos )
       
  1768 				{
       
  1769 				foundSameHotspotTwice = ETrue;
       
  1770 				break;
       
  1771 				}
       
  1772 			}
       
  1773 		if ( !foundSameHotspotTwice )
       
  1774 			{
       
  1775 			// At this phase hotspot is one character too early
       
  1776 			// Change it to right place. If FindItemEngine implementation
       
  1777 			// will change then following line must be removed.
       
  1778 			//foundItem->iStartPos++;
       
  1779 			iBodyTextHotSpotData.AppendL( itemArray->At( i ) );
       
  1780 			}
       
  1781 		}
       
  1782 	// </cmail>
       
  1783 
       
  1784 	CleanupStack::PopAndDestroy( hotspotSearch );
       
  1785 	}
       
  1786 
       
  1787 
       
  1788 //<cmail>
       
  1789 // -----------------------------------------------------------------------------
       
  1790 // CFSEmailUiMailViewerRichText::GetCorrectFontL
       
  1791 // -----------------------------------------------------------------------------
       
  1792 const CAknLayoutFont* CFSEmailUiMailViewerRichText::GetCorrectFontL( TViewerFontType aFontType ) const
       
  1793     {
       
  1794 	FUNC_LOG;
       
  1795      /*
       
  1796      EViewerFontTitle = 0,
       
  1797      EViewerFontText,
       
  1798      EViewerFontBody,
       
  1799      EViewerFontHotspotNormal,
       
  1800      EViewerFontHotspotHighLighted,
       
  1801      EViewerFontSent,
       
  1802      EViewerFontIndentation
       
  1803     */
       
  1804     const CAknLayoutFont* font = NULL;
       
  1805 
       
  1806     switch ( aFontType )
       
  1807         {
       
  1808         case EViewerFontTitle:
       
  1809         case EViewerFontSent:
       
  1810             {
       
  1811             font = CurrentTitleFontL();
       
  1812             }
       
  1813             break;
       
  1814         case EViewerFontText:
       
  1815         case EViewerFontBody:
       
  1816         case EViewerFontHotspotNormal:
       
  1817         case EViewerFontHotspotHighLighted:
       
  1818         case EViewerFontIndentation:
       
  1819         default:
       
  1820             {
       
  1821             font = CurrentTextFontL();
       
  1822             }
       
  1823             break;
       
  1824         }
       
  1825 
       
  1826     if (NULL == font)
       
  1827         User::Leave(KErrGeneral);
       
  1828 
       
  1829     return font;
       
  1830 
       
  1831     }
       
  1832 
       
  1833 /*
       
  1834 // -----------------------------------------------------------------------------
       
  1835 // CFSEmailUiMailViewerRichText::ReConstructFontArrayL
       
  1836 // -----------------------------------------------------------------------------
       
  1837 void CFSEmailUiMailViewerRichText::ReConstructFontArrayL()
       
  1838 	{
       
  1839     FUNC_LOG;
       
  1840 	iFontsArray.ResetAndDestroy();
       
  1841 
       
  1842 	// append title font
       
  1843 	CAknLayoutFont* titleFont = CurrentTitleFontLC();
       
  1844 	iFontsArray.AppendL( titleFont );
       
  1845 	CleanupStack::Pop( titleFont );
       
  1846 
       
  1847 	// append text font
       
  1848 	CAknLayoutFont* textFont = CurrentTextFontLC();
       
  1849 	iFontsArray.AppendL( textFont );
       
  1850 	CleanupStack::Pop( textFont );
       
  1851 
       
  1852 	// append body font
       
  1853 	CAknLayoutFont* bodyFont = CurrentTextFontLC();
       
  1854 	iFontsArray.AppendL( bodyFont );
       
  1855 	CleanupStack::Pop( bodyFont );
       
  1856 
       
  1857 	// append not highlighted hotspot font
       
  1858 	CAknLayoutFont* normalHotspotFont = CurrentTextFontLC();
       
  1859 	iFontsArray.AppendL( normalHotspotFont );
       
  1860 	CleanupStack::Pop( normalHotspotFont );
       
  1861 
       
  1862 	// append highlighted hotspot font
       
  1863 	CAknLayoutFont* highLightedHotspotFont = CurrentTextFontLC();
       
  1864 	iFontsArray.AppendL( highLightedHotspotFont );
       
  1865 	CleanupStack::Pop( highLightedHotspotFont );
       
  1866 
       
  1867 	// append sent line font
       
  1868 	CAknLayoutFont* sentLineFont = CurrentSentTextFontLC();
       
  1869 	iFontsArray.AppendL( sentLineFont );
       
  1870 	CleanupStack::Pop( sentLineFont );
       
  1871 
       
  1872 	// append indentation font
       
  1873 	CAknLayoutFont* indentationFont = CurrentTextFontLC();
       
  1874 	iFontsArray.AppendL( indentationFont );
       
  1875 	CleanupStack::Pop( indentationFont );
       
  1876 	}
       
  1877 */
       
  1878 
       
  1879 /*
       
  1880 // -----------------------------------------------------------------------------
       
  1881 // CFSEmailUiMailViewerRichText::FontFromFontArray
       
  1882 // -----------------------------------------------------------------------------
       
  1883 CAknLayoutFont& CFSEmailUiMailViewerRichText::FontFromFontArray( TViewerFontType aFontType ) const
       
  1884 	{
       
  1885     FUNC_LOG;
       
  1886 	return *iFontsArray[aFontType];
       
  1887 	}
       
  1888 */
       
  1889 //</cmail>
       
  1890 
       
  1891 
       
  1892 // -----------------------------------------------------------------------------
       
  1893 // CFSEmailUiMailViewerRichText::SkinFontColorByType
       
  1894 // -----------------------------------------------------------------------------
       
  1895 TRgb CFSEmailUiMailViewerRichText::SkinFontColorByType( TViewerFontType aFontType )
       
  1896 	{
       
  1897     FUNC_LOG;
       
  1898 	TRgb returnedColor;
       
  1899 	switch ( aFontType )
       
  1900 		{
       
  1901 		case EViewerFontTitle:
       
  1902 			{
       
  1903 			returnedColor = iAppUi.LayoutHandler()->ViewerTitleTextColor();
       
  1904 			}
       
  1905 			break;
       
  1906 		case EViewerFontBody:
       
  1907 			{
       
  1908 			returnedColor = iAppUi.LayoutHandler()->ViewerBodyTextColor();
       
  1909 			}
       
  1910 			break;
       
  1911 		case EViewerFontHotspotNormal:
       
  1912 			{
       
  1913 			returnedColor = iAppUi.LayoutHandler()->ViewerNormalHotspotTextColor();
       
  1914 			}
       
  1915 			break;
       
  1916 		case EViewerFontHotspotHighLighted:
       
  1917 			{
       
  1918 			returnedColor = iAppUi.LayoutHandler()->ViewerHighlightedHotspotTextColor();
       
  1919 			}
       
  1920 			break;
       
  1921 		case EViewerFontSent:
       
  1922 			{
       
  1923 			// <cmail>
       
  1924 			//returnedColor = iAppUi.LayoutHandler()->ViewerTitleFontHeight();
       
  1925 			returnedColor = iAppUi.LayoutHandler()->ViewerTitleTextColor();
       
  1926 			// </cmail>
       
  1927 		    }
       
  1928 			break;
       
  1929 		case EViewerFontText:
       
  1930 		default:
       
  1931 			{
       
  1932 			returnedColor = iAppUi.LayoutHandler()->ViewerTextTextColor();
       
  1933 			}
       
  1934 			break;
       
  1935 		}
       
  1936 	return returnedColor;
       
  1937 	}
       
  1938 
       
  1939 //<cmail> LAYOUT CHANGES
       
  1940 
       
  1941 /*
       
  1942 // -----------------------------------------------------------------------------
       
  1943 // CFSEmailUiMailViewerRichText::CurrentTitleFontLC
       
  1944 // -----------------------------------------------------------------------------
       
  1945 CAknLayoutFont* CFSEmailUiMailViewerRichText::CurrentTitleFontLC()
       
  1946 	{
       
  1947     FUNC_LOG;
       
  1948 	TAknLogicalFontId logicalFontId = iAppUi.LayoutHandler()->ViewerTitleFontAknLogicalFontId();
       
  1949 	TAknFontSpecification spec( logicalFontId );
       
  1950 	TInt heightInPixels = iAppUi.LayoutHandler()->ViewerTitleFontHeight();
       
  1951 	spec.SetTextPaneHeight( heightInPixels );
       
  1952 	CWsScreenDevice* dev = CCoeEnv::Static()->ScreenDevice();
       
  1953 	CAknLayoutFont* font = AknFontAccess::CreateLayoutFontFromSpecificationL( *dev, spec );
       
  1954 	CleanupStack::PushL( font );
       
  1955 	return font;
       
  1956 	}
       
  1957 // -----------------------------------------------------------------------------
       
  1958 // CFSEmailUiMailViewerRichText::CurrentTextFontLC
       
  1959 // -----------------------------------------------------------------------------
       
  1960 CAknLayoutFont* CFSEmailUiMailViewerRichText::CurrentTextFontLC()
       
  1961 	{
       
  1962     FUNC_LOG;
       
  1963 	TAknLogicalFontId logicalFontId = iAppUi.LayoutHandler()->ViewerTextFontAknLogicalFontId();
       
  1964 	TAknFontSpecification spec( logicalFontId );
       
  1965 	TInt heightInPixels = iAppUi.LayoutHandler()->ViewerTextFontHeight();
       
  1966 	spec.SetTextPaneHeight( heightInPixels );
       
  1967 	CWsScreenDevice* dev = CCoeEnv::Static()->ScreenDevice();
       
  1968 	CAknLayoutFont* font = AknFontAccess::CreateLayoutFontFromSpecificationL( *dev, spec );
       
  1969 	CleanupStack::PushL( font );
       
  1970 	return font;
       
  1971 	}
       
  1972 */
       
  1973 
       
  1974 
       
  1975 // -----------------------------------------------------------------------------
       
  1976 // CFSEmailUiMailViewerRichText::CurrentTitleFontL
       
  1977 // -----------------------------------------------------------------------------
       
  1978 const CAknLayoutFont* CFSEmailUiMailViewerRichText::CurrentTitleFontL() const
       
  1979     {
       
  1980 	FUNC_LOG;
       
  1981     TRect mainPaneRect;
       
  1982     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
  1983 
       
  1984     TAknLayoutRect cmailPaneRect;
       
  1985     cmailPaneRect.LayoutRect(mainPaneRect, AknLayoutScalable_Apps::list_cmail_pane());
       
  1986 
       
  1987     TAknLayoutRect labelRect;
       
  1988     labelRect.LayoutRect(cmailPaneRect.Rect(), AknLayoutScalable_Apps::list_single_cmail_header_caption_pane());
       
  1989 
       
  1990     TAknLayoutText layoutText;
       
  1991     layoutText.LayoutText(labelRect.Rect(), AknLayoutScalable_Apps::list_single_cmail_header_caption_pane_t1());
       
  1992 
       
  1993     const CAknLayoutFont* font = CAknLayoutFont::AsCAknLayoutFontOrNull( layoutText.Font() );
       
  1994 
       
  1995     //All fonts must be loaded properly? Leave if something is failing.
       
  1996     if(NULL == font)
       
  1997         User::Leave(KErrGeneral);
       
  1998 
       
  1999     return font;
       
  2000 
       
  2001     }
       
  2002 
       
  2003 
       
  2004 // -----------------------------------------------------------------------------
       
  2005 // CFSEmailUiMailViewerRichText::CurrentTextFontL
       
  2006 // -----------------------------------------------------------------------------
       
  2007 const CAknLayoutFont* CFSEmailUiMailViewerRichText::CurrentTextFontL() const
       
  2008     {
       
  2009 	FUNC_LOG;
       
  2010     TRect mainPaneRect;
       
  2011     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
  2012 
       
  2013     TAknLayoutRect cmailPaneRect;
       
  2014     cmailPaneRect.LayoutRect(mainPaneRect, AknLayoutScalable_Apps::list_cmail_pane());
       
  2015 
       
  2016     //Using variety 0 -> 1 row line by default
       
  2017     TAknLayoutRect labelRect;
       
  2018     labelRect.LayoutRect(cmailPaneRect.Rect(), AknLayoutScalable_Apps::list_single_cmail_header_detail_pane( 0 ));
       
  2019 
       
  2020     TAknLayoutText layoutText;
       
  2021     layoutText.LayoutText(labelRect.Rect(), AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_t1( 0 ));
       
  2022 
       
  2023     const CAknLayoutFont* font = CAknLayoutFont::AsCAknLayoutFontOrNull( layoutText.Font() );
       
  2024 
       
  2025     //All fonts must be loaded properly? Leave if something is failing.
       
  2026     if(NULL == font)
       
  2027         User::Leave(KErrGeneral);
       
  2028 
       
  2029     return font;
       
  2030 
       
  2031     }
       
  2032 
       
  2033 
       
  2034 // -----------------------------------------------------------------------------
       
  2035 // CFSEmailUiMailViewerRichText::CurrentSentTextFontLC
       
  2036 // -----------------------------------------------------------------------------
       
  2037 const CAknLayoutFont* CFSEmailUiMailViewerRichText::CurrentSentTextFontL() const
       
  2038 	{
       
  2039 	return CurrentTitleFontL();
       
  2040 	}
       
  2041 //</cmail>
       
  2042 
       
  2043 // -----------------------------------------------------------------------------
       
  2044 // CFSEmailUiMailViewerRichText::CurrentSpacingHeight
       
  2045 // -----------------------------------------------------------------------------
       
  2046 TInt CFSEmailUiMailViewerRichText::CurrentSpacingHeight( TViewerSpacingIconType aSpacingIconType ) const
       
  2047 	{
       
  2048     FUNC_LOG;
       
  2049 	TInt heightInPixels = 0;
       
  2050 	switch( aSpacingIconType )
       
  2051 		{
       
  2052 		case ETopMostSpace:
       
  2053 			{
       
  2054 			heightInPixels = iAppUi.LayoutHandler()->ViewerTopMostSpaceHeight();
       
  2055 			}
       
  2056 			break;
       
  2057 		case ERecipientSpace:
       
  2058 			{
       
  2059 			heightInPixels = iAppUi.LayoutHandler()->ViewerRecipientSpaceHeight();
       
  2060 			}
       
  2061 			break;
       
  2062 		case EHeaderInfoSpace:
       
  2063 			{
       
  2064 			heightInPixels = iAppUi.LayoutHandler()->ViewerHeaderInfoSpaceHeight();
       
  2065 			}
       
  2066 			break;
       
  2067 		case EBottomMostSpace:
       
  2068 			{
       
  2069 			heightInPixels = iAppUi.LayoutHandler()->ViewerBottomMostSpaceHeight();
       
  2070 			}
       
  2071 			break;
       
  2072 		}
       
  2073 	return heightInPixels;
       
  2074 	}
       
  2075 
       
  2076 // -----------------------------------------------------------------------------
       
  2077 // CFSEmailUiMailViewerRichText::InsertTransparentSpacingIconL
       
  2078 // -----------------------------------------------------------------------------
       
  2079 void CFSEmailUiMailViewerRichText::InsertTransparentSpacingIconL( TViewerSpacingIconType aSpacingIconType )
       
  2080 	{
       
  2081     FUNC_LOG;
       
  2082 	TInt currentSpace = CurrentSpacingHeight( aSpacingIconType );
       
  2083 	TInt fontSide = 0;
       
  2084 	switch ( aSpacingIconType )
       
  2085 		{
       
  2086 		case ETopMostSpace:
       
  2087         case EBottomMostSpace:
       
  2088 			{
       
  2089 			TInt currentTextHeight = iAppUi.LayoutHandler()->ViewerTitleFontHeight();
       
  2090 			fontSide = currentSpace - currentTextHeight;
       
  2091 			}
       
  2092 			break;
       
  2093 		case ERecipientSpace:
       
  2094 			{
       
  2095 			TInt currentTextHeight = iAppUi.LayoutHandler()->ViewerTextFontHeight();
       
  2096 			fontSide = currentSpace - currentTextHeight;
       
  2097 			}
       
  2098 			break;
       
  2099 		case EHeaderInfoSpace:
       
  2100 			{
       
  2101 			TInt currentTextHeight = iAppUi.LayoutHandler()->ViewerTitleFontHeight();
       
  2102 			fontSide = currentSpace - currentTextHeight;
       
  2103 			}
       
  2104 			break;
       
  2105 		}
       
  2106 	iCurrentSpacingIconSize.SetSize( fontSide, fontSide );
       
  2107 
       
  2108 	UpdateIconL( EViewerIconSpacing );
       
  2109 
       
  2110 	// Add extra space before line ending so that we can modify the line height
       
  2111 	AppendSpaceL();
       
  2112 
       
  2113 	AppendNewLineL();
       
  2114 	iHeaderLineInfo.iHeaderLineCount++;
       
  2115 
       
  2116 	// to make the icon need less space.
       
  2117     TCharFormat charFormat;
       
  2118     TCharFormatMask charFormatMask;
       
  2119 	charFormat.iFontSpec.iHeight = CEikonEnv::Static()->ScreenDevice()->VerticalPixelsToTwips( fontSide );
       
  2120     charFormat.iFontPresentation.iUnderline = EUnderlineOff;
       
  2121     charFormatMask.SetAttrib( EAttFontHeight );
       
  2122     charFormatMask.SetAttrib( EAttFontUnderline );
       
  2123     iViewerRichText->ApplyCharFormatL( charFormat, charFormatMask, iViewerRichText->DocumentLength() - 3, 3 );
       
  2124 	}
       
  2125 
       
  2126 // -----------------------------------------------------------------------------
       
  2127 // CFSEmailUiMailViewerRichText::InsertSpaceAfterIconL
       
  2128 // -----------------------------------------------------------------------------
       
  2129 void CFSEmailUiMailViewerRichText::InsertSpaceAfterIconL()
       
  2130 	{
       
  2131     FUNC_LOG;
       
  2132 	TInt spaceInPixels = iAppUi.LayoutHandler()->ViewerPixelsBetweenMsgStatusIconAndSubject();
       
  2133 	iCurrentSpacingIconSize.SetSize( spaceInPixels, spaceInPixels );
       
  2134 	UpdateIconL( EViewerIconSpacing );
       
  2135 	}
       
  2136 
       
  2137 // -----------------------------------------------------------------------------
       
  2138 // CFSEmailUiMailViewerRichText::InsertHotspotTextAndFontL
       
  2139 // -----------------------------------------------------------------------------
       
  2140 void CFSEmailUiMailViewerRichText::InsertHotspotTextAndFontL( const TDesC& aText )
       
  2141     {
       
  2142     FUNC_LOG;
       
  2143     AppendFormattedTextL( aText, EViewerFontHotspotNormal );
       
  2144     }
       
  2145 
       
  2146 // -----------------------------------------------------------------------------
       
  2147 // Appends formatted text to the rich text
       
  2148 // -----------------------------------------------------------------------------
       
  2149 void CFSEmailUiMailViewerRichText::AppendFormattedTextL( const TDesC& aText,
       
  2150     TViewerFontType aFontType )
       
  2151     {
       
  2152     FUNC_LOG;
       
  2153     iRichTextDocumentLength = iViewerRichText->DocumentLength();
       
  2154     InsertFormattedTextL( aText, aFontType, iRichTextDocumentLength );
       
  2155     }
       
  2156 
       
  2157 // -----------------------------------------------------------------------------
       
  2158 // Inserts formatted text to the rich text
       
  2159 // -----------------------------------------------------------------------------
       
  2160 void CFSEmailUiMailViewerRichText::InsertFormattedTextL( const TDesC& aText,
       
  2161     TViewerFontType aFontType, TInt aPosition )
       
  2162     {
       
  2163     FUNC_LOG;
       
  2164     ASSERT( aPosition >= 0 );
       
  2165     ASSERT( aPosition <= iViewerRichText->DocumentLength() );
       
  2166 
       
  2167     // Insert text at given position
       
  2168     iViewerRichText->InsertL( aPosition, aText );
       
  2169 
       
  2170     //<cmail>
       
  2171     const CAknLayoutFont* newFont = GetCorrectFontL( aFontType );
       
  2172 
       
  2173     TRgb fontColor = SkinFontColorByType( aFontType );
       
  2174     TFontUnderline underline = EUnderlineOff;
       
  2175     if ( aFontType == EViewerFontHotspotNormal )
       
  2176         {
       
  2177         underline = EUnderlineOn;
       
  2178         }
       
  2179 
       
  2180     ApplyFontToTextL( newFont, aPosition, aText.Length(), fontColor, underline );
       
  2181     //</cmail>
       
  2182     }
       
  2183 
       
  2184 //<cmail>
       
  2185 
       
  2186 // -----------------------------------------------------------------------------
       
  2187 // CFSEmailUiMailViewerRichText::ApplyFontToTextL
       
  2188 // -----------------------------------------------------------------------------
       
  2189 void CFSEmailUiMailViewerRichText::ApplyFontToTextL( const CAknLayoutFont* aFont,
       
  2190 														 TInt aStartInx,
       
  2191 														 TInt aLength,
       
  2192 														 TRgb& aColor,
       
  2193 														 TFontUnderline aUnderline )
       
  2194 	{
       
  2195     FUNC_LOG;
       
  2196     TCharFormat charFormat;
       
  2197     TCharFormatMask charFormatMask;
       
  2198     charFormat.iFontSpec = aFont->FontSpecInTwips();
       
  2199     // Applies antialiasing for all text in mail viewer.
       
  2200     charFormat.iFontSpec.iFontStyle.SetBitmapType( EAntiAliasedGlyphBitmap );
       
  2201     charFormat.iFontPresentation.iTextColor = aColor;
       
  2202     charFormat.iFontPresentation.iUnderline = aUnderline;
       
  2203     charFormatMask.SetAll();
       
  2204     iViewerRichText->ApplyCharFormatL( charFormat, charFormatMask, aStartInx, aLength );
       
  2205 	}
       
  2206 //</cmail>
       
  2207 
       
  2208 // -----------------------------------------------------------------------------
       
  2209 // CFSEmailUiMailViewerRichText::AddBodyHotsSpotWithTextFormatingL
       
  2210 // -----------------------------------------------------------------------------
       
  2211 void CFSEmailUiMailViewerRichText::AddBodyHotsSpotWithTextFormatingL( const CFindItemEngine::SFoundItem& aBodyHotSpotData )
       
  2212 	{
       
  2213     FUNC_LOG;
       
  2214 	iViewerRichText->SetHotSpotL( aBodyHotSpotData.iStartPos + iHeaderLength,
       
  2215 									  aBodyHotSpotData.iLength, KHotspotHighlightOn );
       
  2216 
       
  2217 	// add underlining and right color the the hotspots
       
  2218 	//<cmail>
       
  2219 	const CAknLayoutFont* newFont = GetCorrectFontL( EViewerFontText );
       
  2220 	TRgb fontColor = SkinFontColorByType( EViewerFontHotspotNormal );
       
  2221 
       
  2222 	TFontUnderline underline = EUnderlineOn;
       
  2223  	ApplyFontToTextL( newFont, aBodyHotSpotData.iStartPos + iHeaderLength,
       
  2224  					 aBodyHotSpotData.iLength, fontColor, underline );
       
  2225     //</cmail>
       
  2226 
       
  2227 	}
       
  2228 
       
  2229 // <cmail> separator line  
       
  2230 
       
  2231 // -----------------------------------------------------------------------------
       
  2232 // CFSEmailUiMailViewerRichText::AppendSeparatorLineL
       
  2233 // Append attachement(s) line to the rich text.
       
  2234 // -----------------------------------------------------------------------------
       
  2235 void CFSEmailUiMailViewerRichText::AppendSeparatorLineL()
       
  2236     {
       
  2237     FUNC_LOG;
       
  2238     UpdateIconL( EViewerIconSeparatorLine );       
       
  2239     }
       
  2240 
       
  2241 // -----------------------------------------------------------------------------
       
  2242 // CFSEmailUiMailViewerRichText::SeparatorLineWidth
       
  2243 // -----------------------------------------------------------------------------
       
  2244 TInt CFSEmailUiMailViewerRichText::SeparatorLineWidth() const
       
  2245     {
       
  2246     FUNC_LOG;
       
  2247     // For some reason, the ratioanally calculated text width seems to be a bit
       
  2248     // wider than the width where GenericTextViewer does line wrapping. Reserve
       
  2249     // some extra pixels to overcome this. Maybe there is some difference in 
       
  2250     // the ways the text width is calculated?
       
  2251     const TInt KExtraPixels( 10 );
       
  2252 
       
  2253     TRect screenRect = iTextViewer->GetControl()->DisplayArea();
       
  2254     TInt scrollBarBreadth = CEikScrollBar::DefaultScrollBarBreadth();
       
  2255     
       
  2256     // Calculate space left for actual text
       
  2257     TInt rightMargin = iAppUi.LayoutHandler()->ViewerRightMarginInPixels() + scrollBarBreadth;
       
  2258     TInt leftMargin = iAppUi.LayoutHandler()->ViewerLeftMarginInPixels();
       
  2259     TInt widthInPixels = screenRect.iBr.iX - rightMargin - leftMargin - KExtraPixels;
       
  2260     
       
  2261     return widthInPixels;
       
  2262     }
       
  2263 
       
  2264 // </cmail> separator line  
       
  2265 
       
  2266 // End of the file
       
  2267