meetingrequest/mrgui/mrfieldbuilderpluginextension/src/cesmrviewerattachmentsfield.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-2009 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:  Meeting request attachments field
       
    15  *
       
    16 */
       
    17 #include "emailtrace.h"
       
    18 #include "cesmrviewerattachmentsfield.h"
       
    19 
       
    20 //<cmail>
       
    21 #include "mesmrcalentry.h"
       
    22 #include "cesmrcontactmenuattachmenthandler.h"
       
    23 //</cmail>
       
    24 #include <esmrgui.rsg>
       
    25 #include <StringLoader.h>
       
    26 //<cmail>
       
    27 #include "esmricalvieweropcodes.hrh"
       
    28 #include "cfsmailmessage.h"
       
    29 //</cmail>
       
    30 
       
    31 #include "cesmrrichtextviewer.h"
       
    32 #include "cesmrrichtextlink.h"
       
    33 #include "mesmrlistobserver.h"
       
    34 #include "mesmrmeetingrequestentry.h"
       
    35 #include "tesmrinputparams.h"
       
    36 #include "cesmrattachment.h"
       
    37 #include "cesmrattachmentinfo.h"
       
    38 #include "cesmrcontactmenuhandler.h"
       
    39 #include "cmrimage.h"
       
    40 #include "nmrlayoutmanager.h"
       
    41 
       
    42 
       
    43 // Unnamed namespace for local definitions
       
    44 namespace { // codescanner::namespace
       
    45 
       
    46 //<cmail>
       
    47 // MR does not contain attachments
       
    48 const TInt KNoAttachments( 0 );
       
    49 // MR contains one attachment
       
    50 const TInt KOneAttachment( 1 );
       
    51 //</cmail>
       
    52 
       
    53 const TInt KOneKiloByte( 1024 );
       
    54 
       
    55 }//namespace
       
    56 
       
    57 // ======== MEMBER FUNCTIONS ========
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CESMRViewerAttachmentsField::CESMRViewerAttachmentsField
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CESMRViewerAttachmentsField::CESMRViewerAttachmentsField()
       
    64 : iFocused(EFalse)
       
    65     {
       
    66     FUNC_LOG;
       
    67     SetFieldId( EESMRFieldAttachments );
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CESMRViewerAttachmentsField::~CESMRViewerAttachmentsField
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CESMRViewerAttachmentsField::~CESMRViewerAttachmentsField()
       
    75     {
       
    76     FUNC_LOG;
       
    77     delete iFieldIcon;
       
    78     delete iRichTextViewer;
       
    79     delete iAttachmentText;
       
    80     
       
    81     iESMRStatic.Close();
       
    82     
       
    83     delete iAttachmentInfo;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CESMRViewerAttachmentsField::NewL
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CESMRViewerAttachmentsField* CESMRViewerAttachmentsField::NewL()
       
    91     {
       
    92     FUNC_LOG;
       
    93     CESMRViewerAttachmentsField* self = new( ELeave )CESMRViewerAttachmentsField;
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL();
       
    96     CleanupStack::Pop( self );
       
    97     return self;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CESMRViewerAttachmentsField::ConstructL()
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CESMRViewerAttachmentsField::ConstructL()
       
   105     {
       
   106     FUNC_LOG;
       
   107     SetFocusType( EESMRNoFocus );
       
   108     
       
   109     iFieldIcon = CMRImage::NewL(  NMRBitmapManager::EMRBitmapMailAttachment );
       
   110     iFieldIcon->SetParent( this );
       
   111     
       
   112     iRichTextViewer = CESMRRichTextViewer::NewL( this );
       
   113     iRichTextViewer->SetEdwinSizeObserver( this );
       
   114     iRichTextViewer->SetLinkObserver( this );
       
   115     iRichTextViewer->SetParent( this );
       
   116     
       
   117     iRichTextViewer->SetActionMenuStatus( ETrue );
       
   118     iESMRStatic.ConnectL();   
       
   119     iCntMenuHdlr = &iESMRStatic.ContactMenuHandlerL();
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CESMRViewerAttachmentsField::MinimumSize
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TSize CESMRViewerAttachmentsField::MinimumSize()
       
   127     {
       
   128     // Let's calculate the required rect of the iRichTextViewer.
       
   129     // We will not use directly the iRichTextViewer height, because it might
       
   130     // not exist, or the height of the viewer might still be incorrect
       
   131     TRect richTextViewerRect = RichTextViewerRect();
       
   132 
       
   133     // We will use as minimum size the parents width 
       
   134     // but the calculated iRichTextViewers height 
       
   135     return TSize( Parent()->Size().iWidth, richTextViewerRect.Height() );
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CESMRViewerAttachmentsField::InitializeL
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CESMRViewerAttachmentsField::InitializeL()
       
   143     {
       
   144     FUNC_LOG;
       
   145     // Setting Font for the rich text viewer
       
   146     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
       
   147             Rect(), 
       
   148             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   149     
       
   150     iRichTextViewer->SetFontL( text.Font(), iLayout );
       
   151         
       
   152     // This is called so theme changes will apply when changing theme "on the fly"
       
   153     if ( IsFocused() )
       
   154         {
       
   155         iRichTextViewer->FocusChanged( EDrawNow );
       
   156         }
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CESMRViewerAttachmentsField::InternalizeL()
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CESMRViewerAttachmentsField::InternalizeL( MESMRCalEntry& aEntry )
       
   164     {
       
   165     FUNC_LOG;
       
   166     MESMRMeetingRequestEntry* mrEntry = NULL;
       
   167     if ( aEntry.Type() != MESMRCalEntry::EESMRCalEntryMeetingRequest )
       
   168         {
       
   169         // This is not meeting request entry so attachment field should be removed from ui
       
   170         iObserver->RemoveControl( FieldId() );
       
   171         return;
       
   172         }
       
   173     else
       
   174         {
       
   175         mrEntry = static_cast<MESMRMeetingRequestEntry*>( &aEntry );
       
   176 
       
   177         TESMRInputParams startupParams;
       
   178         if ( mrEntry && mrEntry->StartupParameters(startupParams) )
       
   179             {
       
   180             // Startup parameters exist --> Let's check if there are attachments
       
   181 
       
   182             if ( startupParams.iAttachmentInfo )
       
   183                 {
       
   184                 iMailMessage = startupParams.iMailMessage;
       
   185                 
       
   186                 UpdateAttachmentInfoL();
       
   187                 
       
   188                 iCntMenuHdlr->SetCommandObserver( this );
       
   189                 
       
   190                 iAttachmentCount = 0;
       
   191                 
       
   192                 if ( iAttachmentInfo )
       
   193                     {
       
   194                     iAttachmentCount = iAttachmentInfo->AttachmentCount();
       
   195                     }
       
   196 
       
   197                 if ( iAttachmentCount > KOneAttachment )
       
   198                     {
       
   199                     // There are more than one attachments
       
   200                     TInt attachmentsSizeSum(0);
       
   201                     for (TInt i(0); i < iAttachmentCount; ++i )
       
   202                         {
       
   203                         const CESMRAttachment& attachment(
       
   204                                 iAttachmentInfo->AttachmentL( i ) );
       
   205 
       
   206                         TInt attachmentSize( attachment.AttachmentSizeInBytes() );
       
   207                         attachmentsSizeSum += attachmentSize;
       
   208                         }
       
   209                     if ( attachmentsSizeSum >= KOneKiloByte )
       
   210                         {
       
   211                         CArrayFixFlat<TInt>* ints =
       
   212                                 new ( ELeave ) CArrayFixFlat<TInt>( 1 );
       
   213 
       
   214                         CleanupStack::PushL(ints);
       
   215                         ints->AppendL( iAttachmentCount );
       
   216                         ints->AppendL( attachmentsSizeSum / KOneKiloByte );
       
   217 
       
   218                         iAttachmentText = StringLoader::LoadL(
       
   219                                 R_QTN_FSE_VIEWER_HEADER_ATTACHMENTS_TOTAL,
       
   220                                 *ints );
       
   221 
       
   222                         CleanupStack::PopAndDestroy(ints);
       
   223                         }
       
   224                     else
       
   225                         {
       
   226                         iAttachmentText = StringLoader::LoadL(
       
   227                                 R_QTN_FSE_VIEWER_HEADER_ATTACHMENTS_LESS_THAN_KB,
       
   228                                 iAttachmentCount);
       
   229                         }
       
   230                     }
       
   231                 else if ( iAttachmentCount > 0 )
       
   232                     {
       
   233                     // There is one attachment
       
   234                     const CESMRAttachment& attachment(
       
   235                             iAttachmentInfo->AttachmentL( 0 ) );
       
   236                     TPtrC attachmentName( attachment.AttachmentName() );
       
   237 
       
   238                     TInt attachmentSize( attachment.AttachmentSizeInBytes() );
       
   239 
       
   240                     if ( attachmentSize >= KOneKiloByte )
       
   241                         {
       
   242                         // "%0U %1N kB"
       
   243 
       
   244                         CDesCArrayFlat* attachmentStrings = 
       
   245 							new(ELeave)CDesCArrayFlat( 1 );
       
   246                         CleanupStack::PushL( attachmentStrings );
       
   247                         //First string
       
   248                         attachmentStrings->AppendL( attachmentName ); 
       
   249 
       
   250                         CArrayFixFlat<TInt>* integers =
       
   251                                 new (ELeave) CArrayFixFlat<TInt>(1);
       
   252                         CleanupStack::PushL( integers );
       
   253                         integers->AppendL( attachmentSize / KOneKiloByte );
       
   254 
       
   255                         iAttachmentText = StringLoader::LoadL(
       
   256                                 R_QTN_FSE_VIEWER_HEADER_ATTACHMENT,
       
   257                                 *attachmentStrings,
       
   258                                 *integers );
       
   259 
       
   260                         // Pop and delete strings array
       
   261                         CleanupStack::PopAndDestroy( integers );
       
   262                         CleanupStack::PopAndDestroy( attachmentStrings );
       
   263                         }
       
   264                     else
       
   265                         {
       
   266                         iAttachmentText = StringLoader::LoadL(
       
   267                                 R_QTN_FSE_VIEWER_HEADER_ATTACHMENT_LESS_THAN_KB,
       
   268                                 attachmentName);
       
   269                         }
       
   270                     }
       
   271 
       
   272                 if ( iAttachmentText )
       
   273                     {
       
   274                     iRichTextViewer->SetTextL( iAttachmentText, EFalse );
       
   275                     // After setting the text, the viewer line count is known
       
   276                     iLineCount = iRichTextViewer->LineCount();
       
   277                     
       
   278                     CESMRRichTextLink* link = CESMRRichTextLink::NewL (
       
   279                             0, iAttachmentText->Length ( ),
       
   280                             iAttachmentText->Des(),
       
   281                             CESMRRichTextLink::ETypeAttachment,
       
   282                             CESMRRichTextLink::ETriggerKeyRight );
       
   283                     
       
   284                     CleanupStack::PushL( link );
       
   285                     iRichTextViewer->AddLinkL( link );
       
   286                     CleanupStack::Pop( link );
       
   287                     }
       
   288                 }
       
   289             }
       
   290         }
       
   291 
       
   292     if ( KNoAttachments == iAttachmentCount )
       
   293         {
       
   294         iObserver->RemoveControl( FieldId() );
       
   295         }
       
   296     
       
   297     iDisableRedraw = ETrue;
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CESMRViewerAttachmentsField::HandleRichTextLinkSelection
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 TBool CESMRViewerAttachmentsField::HandleRichTextLinkSelection(
       
   305         const CESMRRichTextLink* /*aLink*/ )
       
   306     {
       
   307     FUNC_LOG;
       
   308     
       
   309     // <cmail>
       
   310     TRAP_IGNORE( iCntMenuHdlr->ShowActionMenuL() );
       
   311     // </cmail>
       
   312     
       
   313     return ETrue;
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CESMRViewerAttachmentsField::OfferKeyEventL()
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 TKeyResponse CESMRViewerAttachmentsField::OfferKeyEventL(
       
   321         const TKeyEvent& aEvent,
       
   322         TEventCode aType )
       
   323     {
       
   324     FUNC_LOG;
       
   325     TKeyResponse response( EKeyWasNotConsumed );
       
   326 
       
   327     if ( ( aType == EEventKey || aType == EEventKeyUp ) &&
       
   328             aEvent.iScanCode == EStdKeyDevice3 )
       
   329         {
       
   330         // Selection key was pressed --> Trigger open attachment view command
       
   331         NotifyEventL( EESMRCmdMskOpenEmailAttachment );
       
   332                 
       
   333         response = EKeyWasConsumed;
       
   334         }
       
   335     else
       
   336         {
       
   337         response = iRichTextViewer->OfferKeyEventL ( aEvent, aType );
       
   338         }
       
   339 
       
   340     return response;
       
   341     }
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 // CESMRViewerAttachmentsField::HandleEdwinSizeEventL()
       
   345 // ---------------------------------------------------------------------------
       
   346 //
       
   347 TBool CESMRViewerAttachmentsField::HandleEdwinSizeEventL( 
       
   348         CEikEdwin* aEdwin,
       
   349         TEdwinSizeEvent /*aType*/, 
       
   350         TSize aSize )
       
   351     {
       
   352     FUNC_LOG;
       
   353     TBool reDraw( EFalse );
       
   354         
       
   355      // Let's save the required size for the iRichTextViewer
       
   356      iSize = aSize;
       
   357      
       
   358      if ( iObserver && aEdwin == iRichTextViewer )
       
   359         {
       
   360         iObserver->ControlSizeChanged( this );
       
   361         reDraw = ETrue;
       
   362         }
       
   363      return reDraw;
       
   364      }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // CESMRViewerAttachmentsField::ListObserverSet
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CESMRViewerAttachmentsField::ListObserverSet()
       
   371     {
       
   372     FUNC_LOG;
       
   373     iRichTextViewer->SetListObserver( iObserver );
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // CESMRViewerAttachmentsField::SetOutlineFocusL
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CESMRViewerAttachmentsField::SetOutlineFocusL( TBool aFocus )
       
   381     {
       
   382     FUNC_LOG;
       
   383     CESMRField::SetOutlineFocusL( aFocus );
       
   384     
       
   385     if ( iRichTextViewer )
       
   386         {
       
   387         iRichTextViewer->SetFocus( aFocus );
       
   388         }
       
   389 
       
   390     if ( aFocus && aFocus != iFocused )
       
   391         {
       
   392         // <cmail>
       
   393         UpdateAttachmentInfoL();
       
   394     	
       
   395         if( iAttachmentInfo->AttachmentCount() > KOneAttachment )
       
   396         	{
       
   397 	        ChangeMiddleSoftKeyL( EESMRCmdOpenAttachmentView,
       
   398 	                              R_QTN_MSK_VIEWLIST );
       
   399         	}
       
   400        	else
       
   401        		{
       
   402             // There is one attachment
       
   403             const CESMRAttachment& attachment(
       
   404                     iAttachmentInfo->AttachmentL( 0 ) );
       
   405        		
       
   406        		if( attachment.AttachmenState() == CESMRAttachment::EAttachmentStateDownloaded )
       
   407        			{
       
   408        			ChangeMiddleSoftKeyL( EESMRCmdOpenAttachment,
       
   409 	                              R_QTN_MSK_OPEN );
       
   410        			}
       
   411        		else
       
   412        			{
       
   413        			ChangeMiddleSoftKeyL( EESMRCmdDownloadAttachment,
       
   414 	                              R_QTN_MSK_DOWNLOAD );
       
   415        			}
       
   416        		}       		
       
   417         // </cmail>
       
   418         }
       
   419     iFocused = aFocus;    
       
   420     }
       
   421 
       
   422 // <cmail>    
       
   423 // ---------------------------------------------------------------------------
       
   424 // CESMRViewerAttachmentsField::MessagePartPointerArrayCleanup
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 void CESMRViewerAttachmentsField::MessagePartPointerArrayCleanup( TAny* aArray )
       
   428     {
       
   429     FUNC_LOG;
       
   430     RPointerArray<CFSMailMessagePart>* messagePartArray =
       
   431         static_cast<RPointerArray<CFSMailMessagePart>*>( aArray );
       
   432 
       
   433     messagePartArray->ResetAndDestroy();
       
   434     messagePartArray->Close();
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // CESMRViewerAttachmentsField::UpdateAttachmentInfoL
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CESMRViewerAttachmentsField::UpdateAttachmentInfoL()
       
   442     {
       
   443     if ( iMailMessage->IsFlagSet( EFSMsgFlag_Attachments ) )
       
   444         {
       
   445         RPointerArray<CFSMailMessagePart> attachmentParts;
       
   446         CleanupStack::PushL(
       
   447                 TCleanupItem(
       
   448                     MessagePartPointerArrayCleanup,
       
   449                     &attachmentParts) );
       
   450 
       
   451         iMailMessage->AttachmentListL( attachmentParts );
       
   452 
       
   453         // find  calendar part from the list
       
   454         CFSMailMessagePart* calendarPart = 
       
   455             iMailMessage->FindBodyPartL( KFSMailContentTypeTextCalendar );
       
   456         CleanupStack::PushL( calendarPart );
       
   457         
       
   458         if ( calendarPart )
       
   459             {
       
   460             // remove calendar body part from attachment list
       
   461             for ( TInt ii = attachmentParts.Count() - 1; ii >= 0; --ii )
       
   462                 {
       
   463                 if ( attachmentParts[ii]->GetPartId() == calendarPart->GetPartId() )
       
   464                     {
       
   465                     delete attachmentParts[ii];
       
   466                     attachmentParts.Remove(ii);
       
   467                     break;
       
   468                     }
       
   469                 }
       
   470             }
       
   471         CleanupStack::PopAndDestroy( calendarPart );
       
   472 
       
   473         iAttachmentCount = attachmentParts.Count();
       
   474         if ( iAttachmentCount > 0 )
       
   475             {
       
   476             delete iAttachmentInfo;
       
   477             iAttachmentInfo = NULL;
       
   478 
       
   479             CESMRAttachmentInfo* attachmentInfo = CESMRAttachmentInfo::NewL();
       
   480             CleanupStack::PushL( attachmentInfo );
       
   481 
       
   482             for( TInt i(0); i < iAttachmentCount; ++i )
       
   483                 {
       
   484                 CESMRAttachment::TESMRAttachmentState state(
       
   485                         CESMRAttachment::EAttachmentStateDownloaded );
       
   486 
       
   487                 if ( EFSFull != attachmentParts[i]->FetchLoadState() )
       
   488                     {
       
   489                     state = CESMRAttachment::EAttachmentStateNotDownloaded;
       
   490                     }
       
   491 
       
   492                 TInt contentSize( attachmentParts[i]->ContentSize() );
       
   493                 TPtrC attachmentName( attachmentParts[i]->AttachmentNameL() );
       
   494                 if ( contentSize > 0 && attachmentName.Length() )
       
   495                     {
       
   496                     attachmentInfo->AddAttachmentInfoL(
       
   497                             attachmentName,
       
   498                             contentSize,
       
   499                             state );
       
   500                     }
       
   501                 }
       
   502 
       
   503             if ( attachmentInfo->AttachmentCount() )
       
   504                 {
       
   505                 iAttachmentInfo = attachmentInfo;
       
   506                 CleanupStack::Pop( attachmentInfo );
       
   507                 }
       
   508             else
       
   509                 {
       
   510                 CleanupStack::PopAndDestroy( attachmentInfo );
       
   511                 }
       
   512 
       
   513             attachmentInfo = NULL;
       
   514             }
       
   515         CleanupStack::PopAndDestroy(); // attachmentparts
       
   516 
       
   517         // relay attachment info to contact menu so we can display
       
   518         // options based on attachment state
       
   519         if ( iAttachmentInfo )
       
   520             {
       
   521             iCntMenuHdlr->SetAttachmentInfoL( iAttachmentInfo );
       
   522             }
       
   523         }    
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------------------------
       
   527 // CESMRViewerAttachmentsField::ExecuteGenericCommandL
       
   528 // ---------------------------------------------------------------------------
       
   529 //
       
   530 void CESMRViewerAttachmentsField::ExecuteGenericCommandL( TInt aCommand )
       
   531     {
       
   532     FUNC_LOG;
       
   533 
       
   534     switch ( aCommand )
       
   535         {
       
   536        	case EESMRCmdOpenAttachment:// Fall through
       
   537         case EESMRCmdOpenAttachmentView:// Fall through
       
   538         case EESMRCmdDownloadAttachment: // Fall through
       
   539             {
       
   540             NotifyEventL( aCommand );
       
   541             
       
   542             break;
       
   543             }
       
   544         case EESMRCmdClipboardCopy:
       
   545             {
       
   546             iRichTextViewer->CopyCurrentLinkValueToClipBoardL();
       
   547             break;
       
   548             }
       
   549          default:
       
   550             {
       
   551             break;
       
   552             }
       
   553         }
       
   554     }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CESMRRichTextViewer::ProcessCommandL
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 void CESMRViewerAttachmentsField::ProcessCommandL( TInt aCommandId )
       
   561     {
       
   562     FUNC_LOG;
       
   563 
       
   564     NotifyEventL( aCommandId );
       
   565     }
       
   566 
       
   567 
       
   568 // ---------------------------------------------------------------------------
       
   569 // CESMRViewerAttachmentsField::CountComponentControls
       
   570 // ---------------------------------------------------------------------------
       
   571 //
       
   572 TInt CESMRViewerAttachmentsField::CountComponentControls() const
       
   573     {
       
   574     TInt count( 0 );
       
   575     if ( iFieldIcon )
       
   576         {
       
   577         ++count;
       
   578         }
       
   579 
       
   580     if ( iRichTextViewer )
       
   581         {
       
   582         ++count;
       
   583         }
       
   584     return count;
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------------------------
       
   588 // CESMRViewerAttachmentsField::ComponentControl
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 CCoeControl* CESMRViewerAttachmentsField::ComponentControl( 
       
   592         TInt aIndex ) const
       
   593     {
       
   594     switch ( aIndex )
       
   595         {
       
   596         case 0:
       
   597             return iFieldIcon;
       
   598         case 1:
       
   599             return iRichTextViewer;
       
   600         default:
       
   601             return NULL;
       
   602         }
       
   603     }
       
   604 
       
   605 // ---------------------------------------------------------------------------
       
   606 // CESMRViewerAttachmentsField::SizeChanged
       
   607 // ---------------------------------------------------------------------------
       
   608 //
       
   609 void CESMRViewerAttachmentsField::SizeChanged( )
       
   610     {
       
   611     TRect rect = Rect();
       
   612 
       
   613     // LAYOUTING FIELD ICON
       
   614     if( iFieldIcon )
       
   615         {
       
   616         TAknWindowComponentLayout iconLayout = 
       
   617             NMRLayoutManager::GetWindowComponentLayout( 
       
   618                     NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   619         AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout );
       
   620         }
       
   621 
       
   622     // LAYOUTING FIELD BACKGROUND
       
   623     TAknLayoutRect bgLayoutRect =
       
   624         NMRLayoutManager::GetLayoutRect( 
       
   625                 rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   626     TRect bgRect( bgLayoutRect.Rect() );
       
   627     // Move focus rect so that it's relative to field's position
       
   628     bgRect.Move( -Position() );
       
   629     SetFocusRect( bgRect );
       
   630     
       
   631     
       
   632     // LAYOUTING FIELD TEXT VIEWER
       
   633     if( iRichTextViewer )
       
   634         {
       
   635         iRichTextViewer->SetRect( RichTextViewerRect() );
       
   636         }
       
   637     }
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 // CESMRViewerAttachmentsField::SetContainerWindowL
       
   641 // ---------------------------------------------------------------------------
       
   642 //
       
   643 void CESMRViewerAttachmentsField::SetContainerWindowL( 
       
   644         const CCoeControl& aContainer )
       
   645     {
       
   646     CCoeControl::SetContainerWindowL( aContainer );
       
   647     iRichTextViewer->SetContainerWindowL( aContainer );
       
   648     }
       
   649 
       
   650 // ---------------------------------------------------------------------------
       
   651 // CESMRViewerAttachmentsField::RichTextViewerRect
       
   652 // ---------------------------------------------------------------------------
       
   653 //
       
   654 TRect CESMRViewerAttachmentsField::RichTextViewerRect()
       
   655     {
       
   656     TRect rect = Rect();
       
   657     
       
   658     TAknTextComponentLayout edwinLayout = NMRLayoutManager::GetTextComponentLayout( 
       
   659             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   660 
       
   661     // Text layout rect for one line viewer
       
   662     TAknLayoutText textLayout;
       
   663     textLayout.LayoutText( rect, edwinLayout );
       
   664     TRect textLayoutRect = textLayout.TextRect();
       
   665 
       
   666     TRect viewerRect = textLayoutRect;
       
   667     
       
   668     // If iRichTextViewer has lines and iSize has been set, 
       
   669     // we will use iSize.iHeight as the viewers height
       
   670     if( iLineCount > 0 && iSize.iHeight > 0 )
       
   671         {
       
   672         viewerRect.SetHeight( iSize.iHeight );
       
   673         }
       
   674     // Otherwise we will use one row height as the height of the 
       
   675     // iRichTextViewer
       
   676     else
       
   677         {
       
   678         TAknLayoutRect rowLayoutRect = 
       
   679             NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   680         viewerRect.SetHeight( rowLayoutRect.Rect().Height() );
       
   681         }
       
   682    
       
   683     return viewerRect;
       
   684     }
       
   685 
       
   686 //EOF