meetingrequest/mrgui/mrfieldbuilderpluginextension/src/cesmrviewerattendeesfield.cpp
branchRCL_3
changeset 64 3533d4323edc
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 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:  ESMR UI Container class
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmrviewerattendeesfield.h"
       
    19 
       
    20 #include "mesmrlistobserver.h"
       
    21 #include "cesmrrichtextlink.h"
       
    22 #include "esmrfieldbuilderdef.h"
       
    23 #include "cmrlabel.h"
       
    24 #include "nmrlayoutmanager.h"
       
    25 
       
    26 #include <caluser.h>
       
    27 #include <calentry.h>
       
    28 #include <StringLoader.h>
       
    29 #include <esmrgui.rsg>
       
    30 #include <CPbkContactEngine.h>
       
    31 #include <AknBidiTextUtils.h>
       
    32 
       
    33 // DEBUG
       
    34 #include "emailtrace.h"
       
    35 
       
    36 
       
    37 // CONSTANTS
       
    38 /// Unnamed namespace for local definitions
       
    39 namespace { // codescanner::namespace
       
    40 
       
    41 _LIT( KNewLine, "\f" );
       
    42 const TInt KMaxLineCount = 4;
       
    43 const TInt KNumberOfComponents = 2;
       
    44 const TInt KMargin = 5;
       
    45 
       
    46 static void RPointerArrayResetAndDestroy( TAny* aPtr )
       
    47     {
       
    48     static_cast<RPointerArray<CESMRRichTextLink>*>( aPtr )->ResetAndDestroy();
       
    49     }
       
    50 
       
    51 } // namespace
       
    52 
       
    53 
       
    54 // ======== MEMBER FUNCTIONS ========
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CESMRViewerAttendeesField::NewL
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CESMRViewerAttendeesField* CESMRViewerAttendeesField::NewL(
       
    61         CCalAttendee::TCalRole aRole )
       
    62     {
       
    63     FUNC_LOG;
       
    64     CESMRViewerAttendeesField* self =
       
    65         new (ELeave) CESMRViewerAttendeesField( aRole );
       
    66     CleanupStack::PushL ( self );
       
    67     self->ConstructL ( );
       
    68     CleanupStack::Pop ( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CESMRViewerAttendeesField::ConstructL
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 void CESMRViewerAttendeesField::ConstructL( )
       
    77     {
       
    78     FUNC_LOG;
       
    79 
       
    80     SetFieldId ( (iRole == CCalAttendee::EReqParticipant) ? EESMRFieldAttendee
       
    81             : EESMRFieldOptAttendee );
       
    82 
       
    83     iTitle = CMRLabel::NewL( this );
       
    84 
       
    85     iRichTextViewer = CESMRRichTextViewer::NewL (this );
       
    86     CESMRField::ConstructL( iRichTextViewer ); // ownership transferred
       
    87     iRichTextViewer->SetEdwinSizeObserver ( this );
       
    88     iRichTextViewer->SetLinkObserver (this );
       
    89     iRichTextViewer->SetParent( this );
       
    90 
       
    91     HBufC* label = StringLoader::LoadLC (iRole == CCalAttendee::EReqParticipant ?
       
    92             R_QTN_MEET_REQ_LABEL_REQUIRED : R_QTN_MEET_REQ_LABEL_OPT );
       
    93     iTitle->SetTextL ( *label );
       
    94 
       
    95     CleanupStack::PopAndDestroy( label );
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CESMRViewerAttendeesField::InitializeL
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CESMRViewerAttendeesField::InitializeL()
       
   103     {
       
   104     FUNC_LOG;
       
   105     TAknLayoutText layoutText =
       
   106         NMRLayoutManager::GetLayoutText( Rect(),
       
   107                 NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
       
   108     iRichTextViewer->SetFontL( layoutText.Font() );
       
   109     iRichTextViewer->ApplyLayoutChangesL();
       
   110     UpdateAttendeesListL();
       
   111     //wake up current contact menu selection by calling this
       
   112     iRichTextViewer->FocusChanged( ENoDrawNow );
       
   113     iRichTextViewer->SetEventQueue( iEventQueue );
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CESMRViewerAttendeesField::SetOutlineFocusL
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CESMRViewerAttendeesField::SetOutlineFocusL( TBool aFocus )
       
   121     {
       
   122     FUNC_LOG;
       
   123     CESMRField::SetOutlineFocusL (aFocus );
       
   124     iRichTextViewer->SetFocus( aFocus );
       
   125 
       
   126     if ( aFocus )
       
   127         {
       
   128         SetMiddleSoftKeyVisible( ETrue );
       
   129         }
       
   130     else
       
   131         {
       
   132         iShowAllAttendees = EFalse;
       
   133         UpdateAttendeesListL();
       
   134         iRichTextViewer->ResetActionMenuL();
       
   135         }
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CESMRViewerAttendeesField::InternalizeL
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CESMRViewerAttendeesField::InternalizeL( MESMRCalEntry& aEntry )
       
   143     {
       
   144     FUNC_LOG;
       
   145     CCalEntry& entry = aEntry.Entry();
       
   146     RPointerArray<CCalAttendee>& attendees = entry.AttendeesL();
       
   147     iCalAttendees.ReserveL(attendees.Count());
       
   148     for (TInt i=0; i<attendees.Count ( ); ++i )
       
   149         {
       
   150         CCalAttendee* attendee = attendees[i];
       
   151         if ( attendee->RoleL() == iRole )
       
   152             {
       
   153             iCalAttendees.AppendL( attendee );
       
   154             }
       
   155         }
       
   156 
       
   157     UpdateAttendeesListL();
       
   158 
       
   159     if ( iRichTextViewer->TextLength() > 0 )
       
   160         {
       
   161         //wake up current contact menu selection by calling this
       
   162         iRichTextViewer->FocusChanged( ENoDrawNow );
       
   163         }
       
   164     else
       
   165         {
       
   166         iObserver->HideControl( iFieldId );
       
   167         }
       
   168     iDisableRedraw = ETrue;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CESMRViewerAttendeesField::GetMinimumVisibleVerticalArea
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CESMRViewerAttendeesField::GetMinimumVisibleVerticalArea(
       
   176         TInt& aUpper, TInt& aLower)
       
   177     {
       
   178     FUNC_LOG;
       
   179     aLower = iRichTextViewer->CurrentLineNumber() * iRichTextViewer->RowHeight();
       
   180     aUpper = aLower - iRichTextViewer->RowHeight();
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CESMRViewerAttendeesField::GetCursorLineVerticalPos
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CESMRViewerAttendeesField::GetCursorLineVerticalPos(TInt& aUpper, TInt& aLower)
       
   188     {
       
   189     FUNC_LOG;
       
   190     aLower = iRichTextViewer->CurrentLineNumber() * iRichTextViewer->RowHeight();
       
   191     aUpper = aLower - iRichTextViewer->RowHeight();
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CESMRViewerAttendeesField::ListObserverSet
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CESMRViewerAttendeesField::ListObserverSet( )
       
   199     {
       
   200     FUNC_LOG;
       
   201     iRichTextViewer->SetListObserver( iObserver );
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CESMRViewerAttendeesField::SizeChanged
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void CESMRViewerAttendeesField::SizeChanged( )
       
   209     {
       
   210     FUNC_LOG;
       
   211     // Store iRichTextViewer original width.
       
   212     TInt richTextViewerWidth = iRichTextViewer->Size().iWidth;
       
   213 
       
   214     // Get field's rect
       
   215     TRect rect( Rect() );
       
   216 
       
   217     // First row for title
       
   218     TAknLayoutRect rowLayoutRect =
       
   219         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   220     TRect rowRect = rowLayoutRect.Rect();
       
   221 
       
   222     // Layout title to first row's rect
       
   223     TAknTextComponentLayout titleLayout =
       
   224         NMRLayoutManager::GetTextComponentLayout(
       
   225                 NMRLayoutManager::EMRTextLayoutText );
       
   226     AknLayoutUtils::LayoutLabel( iTitle, rect, titleLayout );
       
   227 
       
   228     TAknLayoutText labelLayout =
       
   229             NMRLayoutManager::GetLayoutText(
       
   230                     rect, NMRLayoutManager::EMRTextLayoutText );
       
   231 
       
   232     // Setting font for the label
       
   233     iTitle->SetFont( labelLayout.Font() );
       
   234 
       
   235     // Move upper left corner below first line and get second row's rect.
       
   236     rect.iTl.iY += rowRect.Height();
       
   237     rowLayoutRect =
       
   238         NMRLayoutManager::GetFieldRowLayoutRect( rect, 2 );
       
   239     rowRect = rowLayoutRect.Rect();
       
   240 
       
   241     // Get default 1 row editor rect.
       
   242     TAknLayoutText viewerLayoutText =
       
   243         NMRLayoutManager::GetLayoutText( rowRect,
       
   244                 NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
       
   245     TRect viewerRect = viewerLayoutText.TextRect();
       
   246     // Resize resize it's height according to actual height required by edwin.
       
   247     viewerRect.Resize( 0, iExpandedSize.iHeight - viewerRect.Height() );
       
   248 
       
   249     // Layouting focus
       
   250     TRect bgRect( 0, 0, 0, 0 );
       
   251     if( iCalAttendees.Count() > 1 )
       
   252     	{
       
   253     	bgRect.SetRect(
       
   254     			TPoint( viewerRect.iTl.iX,
       
   255     					viewerRect.iTl.iY - FocusMargin() ),
       
   256     					TPoint( viewerRect.iBr.iX,
       
   257     							viewerRect.iBr.iY + FocusMargin() ) );
       
   258     	}
       
   259     else
       
   260     	{
       
   261     	TAknLayoutRect bgLayoutRect =
       
   262     	NMRLayoutManager::GetLayoutRect(
       
   263     			rowRect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   264     	bgRect = bgLayoutRect.Rect();
       
   265     	}
       
   266 
       
   267     // Move focus rect so that it's relative to field's position.
       
   268     bgRect.Move( -Position() );
       
   269     SetFocusRect( bgRect );
       
   270 
       
   271     iRichTextViewer->SetRect( viewerRect );
       
   272 
       
   273     // Failures are ignored.
       
   274     TRAP_IGNORE(
       
   275             iRichTextViewer->SetFontL( viewerLayoutText.Font() );
       
   276             if( iCalAttendees.Count() > 0 )
       
   277                 {
       
   278                 iRichTextViewer->SetLineSpacingL( LineSpacing() );
       
   279                 }
       
   280             iRichTextViewer->ApplyLayoutChangesL();
       
   281             );
       
   282 
       
   283     // Update AttendeesList only if iRichTextViewer width was changed.
       
   284     // This happens when screen orientation changes e.g. This check
       
   285     // also prevents recursive calls to UpdateAttendeesListL since
       
   286     // it causes edwin size changed event.
       
   287     if ( iRichTextViewer->Size().iWidth != richTextViewerWidth )
       
   288         {
       
   289         // Most of this case is screen orientation, in this case we need to
       
   290         // Record the index of focusing link, after updating link array, then
       
   291         // reset the focusing to original one.
       
   292         TInt focusingIndex = iRichTextViewer->GetFocusLink();
       
   293         // Ignore leave, there's nothing we can do if leave occurs.
       
   294         TRAP_IGNORE( UpdateAttendeesListL() );
       
   295         if ( KErrNotFound != focusingIndex )
       
   296             {
       
   297             iRichTextViewer->SetFocusLink( focusingIndex );
       
   298             //wake up current contact menu selection by calling this
       
   299             iRichTextViewer->FocusChanged(ENoDrawNow);
       
   300             }
       
   301         }
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CESMRViewerAttendeesField::OfferKeyEventL
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 TKeyResponse CESMRViewerAttendeesField::OfferKeyEventL( const TKeyEvent& aEvent,
       
   309         TEventCode aType )
       
   310     {
       
   311     FUNC_LOG;
       
   312     TKeyResponse response = EKeyWasNotConsumed;
       
   313     response = iRichTextViewer->OfferKeyEventL ( aEvent, aType );
       
   314 
       
   315     //track up and down events to change MSK
       
   316     if ( aType == EEventKey )
       
   317         {
       
   318         if ( aEvent.iScanCode == EStdKeyUpArrow
       
   319              || aEvent.iScanCode == EStdKeyDownArrow )
       
   320             {
       
   321             const CESMRRichTextLink* link =
       
   322                 iRichTextViewer->GetSelectedLink ( );
       
   323             if( link )
       
   324                 {
       
   325                 if (link->Type() == CESMRRichTextLink::ETypeShowAll )
       
   326                     {
       
   327                     ChangeMiddleSoftKeyL(
       
   328                             EESMRCmdShowAllAttendees, R_QTN_MEET_REQ_SHOW_ALL);
       
   329                     }
       
   330                 else
       
   331                     {
       
   332                     RestoreMiddleSoftKeyL();
       
   333                     SetMiddleSoftKeyVisible( ETrue );
       
   334                     }
       
   335                 }
       
   336             }
       
   337         }
       
   338 
       
   339     return response;
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // CESMRViewerAttendeesField::MinimumSize()
       
   344 // ---------------------------------------------------------------------------
       
   345 //
       
   346 TSize CESMRViewerAttendeesField::MinimumSize()
       
   347     {
       
   348     // Minimum size ->  Height: TitleRow + Editor size + Margin
       
   349     //                  Width: Parent's Width
       
   350     //                   (so the content pane that holds all the fields)
       
   351     TRect rect( Rect() );
       
   352     TAknLayoutRect row1LayoutRect =
       
   353         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   354     TInt titleHeight = row1LayoutRect.Rect().Height();
       
   355 
       
   356     // Add title field height
       
   357     TInt totalHeight = titleHeight;
       
   358 
       
   359     TAknLayoutRect row2LayoutRect =
       
   360         NMRLayoutManager::GetFieldRowLayoutRect( rect, 2 );
       
   361     TInt editorRowHeight = row2LayoutRect.Rect().Height();
       
   362 
       
   363     TAknTextComponentLayout editorLayout =
       
   364         NMRLayoutManager::GetTextComponentLayout(
       
   365                 NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
       
   366 
       
   367     // Editor height from Layout data
       
   368     TInt editorHeight = editorLayout.H();
       
   369     // Margin is the outer row's height - editor's layout height
       
   370     TInt margin = editorRowHeight - editorHeight;
       
   371     // Parent has the width
       
   372     TInt width( Parent()->Size().iWidth );
       
   373     // Count the total height of the attendee field.
       
   374     // iExpandedSize is used because the Editor size might be something else
       
   375     // than what is stated in Layout data.
       
   376     totalHeight += iExpandedSize.iHeight + margin;
       
   377     return TSize( width, totalHeight );
       
   378     }
       
   379 
       
   380 // ---------------------------------------------------------------------------
       
   381 // CESMRViewerAttendeesField::ExecuteGenericCommandL()
       
   382 // ---------------------------------------------------------------------------
       
   383 //
       
   384 TBool CESMRViewerAttendeesField::ExecuteGenericCommandL( TInt aCommand )
       
   385     {
       
   386     FUNC_LOG;
       
   387 
       
   388     TBool isUsed( EFalse );
       
   389     if (aCommand == EESMRCmdShowAllAttendees)
       
   390         {
       
   391         iShowAllAttendees = ETrue;
       
   392         UpdateAttendeesListL();
       
   393 
       
   394         RestoreMiddleSoftKeyL();
       
   395         //wake up current contact menu selection by calling this
       
   396         iRichTextViewer->FocusChanged(ENoDrawNow);
       
   397 
       
   398         isUsed = ETrue;
       
   399         }
       
   400     if ( aCommand == EAknSoftkeySelect )
       
   401         {
       
   402         iRichTextViewer->LinkSelectedL();
       
   403         isUsed = ETrue;
       
   404         }
       
   405 
       
   406     return isUsed;
       
   407     }
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // CESMRViewerAttendeesField::HandleEdwinSizeEventL
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 TBool CESMRViewerAttendeesField::HandleEdwinSizeEventL(CEikEdwin* /*aEdwin*/,
       
   414         TEdwinSizeEvent /*aType*/, TSize aSize )
       
   415     {
       
   416     FUNC_LOG;
       
   417     iExpandedSize = aSize;
       
   418     
       
   419     if ( iObserver && iDisableRedraw )
       
   420         {
       
   421         iObserver->ControlSizeChanged ( this );
       
   422         
       
   423         if ( !iOutlineFocus )
       
   424             {
       
   425             RecordField();
       
   426             }
       
   427         }
       
   428     
       
   429     return iDisableRedraw;
       
   430     }
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // CESMRViewerAttendeesField::HandleRichTextLinkSelection
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 TBool CESMRViewerAttendeesField::HandleRichTextLinkSelection(
       
   437         const CESMRRichTextLink* aLink )
       
   438     {
       
   439     FUNC_LOG;
       
   440     if (aLink->Type ( )== CESMRRichTextLink::ETypeShowAll )
       
   441         {
       
   442         iShowAllAttendees = ETrue;
       
   443         TRAPD( err, UpdateAttendeesListL() );
       
   444 
       
   445         if (err == KErrNone )
       
   446             {
       
   447             return ETrue;
       
   448             }
       
   449         }
       
   450     return EFalse;
       
   451     }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CESMRViewerAttendeesField::CountComponentControls
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 TInt CESMRViewerAttendeesField::CountComponentControls( ) const
       
   458     {
       
   459     FUNC_LOG;
       
   460     TInt count = KNumberOfComponents;
       
   461     return count;
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CESMRViewerAttendeesField::ComponentControl
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 CCoeControl* CESMRViewerAttendeesField::ComponentControl( TInt aInd ) const
       
   469     {
       
   470     FUNC_LOG;
       
   471     switch ( aInd )
       
   472         {
       
   473         case 0:
       
   474             {
       
   475             return iTitle;
       
   476             }
       
   477         case 1:
       
   478             {
       
   479             return iRichTextViewer;
       
   480             }
       
   481         default:
       
   482             {
       
   483             return NULL;
       
   484             }
       
   485         }
       
   486     }
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CESMRViewerAttendeesField::~CESMRViewerAttendeesField
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 CESMRViewerAttendeesField::~CESMRViewerAttendeesField( )
       
   493     {
       
   494     FUNC_LOG;
       
   495     delete iTitle;
       
   496     iCalAttendees.Reset();
       
   497     }
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // CESMRViewerAttendeesField::CESMRViewerAttendeesField
       
   501 // -----------------------------------------------------------------------------
       
   502 //
       
   503 CESMRViewerAttendeesField::CESMRViewerAttendeesField(
       
   504         CCalAttendee::TCalRole aRole ) :
       
   505     iRole( aRole)
       
   506     {
       
   507     FUNC_LOG;
       
   508     SetFocusType( EESMRHighlightFocus );
       
   509     }
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 // CESMRViewerAttendeesField::ClipTextLC
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 HBufC* CESMRViewerAttendeesField::ClipTextLC(
       
   516         const TDesC& aText, const CFont& aFont, TInt aWidth )
       
   517     {
       
   518     FUNC_LOG;
       
   519     HBufC* text = HBufC::NewLC( aText.Length() + KAknBidiExtraSpacePerLine );
       
   520     TPtr textPtr = text->Des();
       
   521     AknBidiTextUtils::ConvertToVisualAndClip(
       
   522             aText, textPtr, aFont, aWidth, aWidth );
       
   523     return text;
       
   524     }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // CESMRViewerAttendeesField::UpdateAttendeesListL
       
   528 // -----------------------------------------------------------------------------
       
   529 //
       
   530 void CESMRViewerAttendeesField::UpdateAttendeesListL()
       
   531     {
       
   532     FUNC_LOG;
       
   533     RBuf buffer; // codescanner::resourcenotoncleanupstack
       
   534     buffer.CleanupClosePushL();
       
   535 
       
   536     TAknLayoutText text = NMRLayoutManager::GetLayoutText(
       
   537             Rect(),
       
   538             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   539     const CFont* font = text.Font();
       
   540 
       
   541     TSize iconSize( 20, 20);
       
   542 
       
   543     TInt maxLineWidth = iRichTextViewer->LayoutWidth();
       
   544     maxLineWidth -= font->TextWidthInPixels( KAddressDelimeterSemiColon );
       
   545     maxLineWidth -= iconSize.iWidth;
       
   546 
       
   547     RPointerArray<CESMRRichTextLink> attendeeLinks;  // codescanner::resourcenotoncleanupstack
       
   548     TCleanupItem arrayCleanup( RPointerArrayResetAndDestroy, &attendeeLinks );
       
   549     CleanupStack::PushL( arrayCleanup );
       
   550     attendeeLinks.ReserveL(iCalAttendees.Count());
       
   551     for ( TInt i = 0; i < iCalAttendees.Count(); ++i )
       
   552         {
       
   553         CCalAttendee* attendee = iCalAttendees[i];
       
   554 
       
   555         // Attendee email address.
       
   556         TPtrC addr = attendee->Address();
       
   557         // Attendee common name.
       
   558         TPtrC name = attendee->CommonName();
       
   559         // Actual text to be added to attendee field (email or common name).
       
   560         TPtrC text = addr;
       
   561 
       
   562         // If attendee has common name, use it instead.
       
   563         if ( name.Length() > 0 )
       
   564             {
       
   565             text.Set( name );
       
   566             }
       
   567 
       
   568         HBufC* clippedTextHBufC = ClipTextLC( text, *font, maxLineWidth );
       
   569         TPtr clippedText = clippedTextHBufC->Des();
       
   570         clippedText.Trim();
       
   571 
       
   572         if ( clippedText.Length() > 0 )
       
   573             {
       
   574             CESMRRichTextLink* link = CESMRRichTextLink::NewL(
       
   575                     buffer.Length(),
       
   576                     clippedText.Length() +
       
   577                         KAddressDelimeterSemiColon().Length(),
       
   578                     addr,
       
   579                     CESMRRichTextLink::ETypeEmail,
       
   580                     CESMRRichTextLink::ETriggerKeyRight );
       
   581             CleanupStack::PushL( link );
       
   582             attendeeLinks.AppendL( link );
       
   583             CleanupStack::Pop( link );
       
   584 
       
   585             // Append text and semicolon to buffer.
       
   586             buffer.ReAllocL( buffer.Length() +
       
   587                              clippedText.Length() +
       
   588                              KAddressDelimeterSemiColon().Length() +
       
   589                              KNewLine().Length() );
       
   590             buffer.Append( clippedText );
       
   591             buffer.Append( KAddressDelimeterSemiColon );
       
   592             buffer.Append( KNewLine );
       
   593             }
       
   594 
       
   595         CleanupStack::PopAndDestroy( clippedTextHBufC );
       
   596 
       
   597         // End loop if we have exceeded KMaxLineCount and
       
   598         // we don't want to show all attendees
       
   599         if ( attendeeLinks.Count() > KMaxLineCount && !iShowAllAttendees )
       
   600             {
       
   601             break;
       
   602             }
       
   603         }
       
   604 
       
   605     // If there are more lines in use than KMaxLineCount and
       
   606     // we don't want to show all attendees, leave only
       
   607     // KMaxLineCount-1 attendees and add 'show all'
       
   608     // link to the end.
       
   609     if ( attendeeLinks.Count() > KMaxLineCount && !iShowAllAttendees )
       
   610         {
       
   611         // Remove unnecessary part of buffer.
       
   612         buffer.SetLength( attendeeLinks[KMaxLineCount - 1]->StartPos() );
       
   613 
       
   614         // Remove links from the list.
       
   615         while ( attendeeLinks.Count() >= KMaxLineCount )
       
   616             {
       
   617             delete attendeeLinks[KMaxLineCount - 1];
       
   618             attendeeLinks.Remove( KMaxLineCount - 1 );
       
   619             }
       
   620 
       
   621         // Create and append 'show all' link.
       
   622         CESMRRichTextLink* showAllLink;
       
   623         HBufC* showAllBuf = StringLoader::LoadLC( R_QTN_MEET_REQ_SHOW_ALL );
       
   624         buffer.ReAllocL( buffer.Length() +
       
   625                          showAllBuf->Length() );
       
   626         showAllLink = CESMRRichTextLink::NewL( buffer.Length ( ),
       
   627                 showAllBuf->Length(), KNullDesC,
       
   628                 CESMRRichTextLink::ETypeShowAll,
       
   629                 CESMRRichTextLink::ETriggerKeyOk );
       
   630         buffer.Append( *showAllBuf );
       
   631         CleanupStack::PopAndDestroy( showAllBuf );
       
   632         CleanupStack::PushL( showAllLink );
       
   633         attendeeLinks.AppendL( showAllLink );
       
   634         CleanupStack::Pop( showAllLink );
       
   635         }
       
   636     // Remove unnecessary new line from the end of buffer.
       
   637     else if ( buffer.Length() >= KNewLine().Length() )
       
   638         {
       
   639         buffer.SetLength( buffer.Length() - KNewLine().Length() );
       
   640         }
       
   641 
       
   642     if ( buffer.Length() > 0 )
       
   643         {
       
   644         iRichTextViewer->SetTextL( &buffer );
       
   645         iRichTextViewer->SetMargins( KMargin );
       
   646 
       
   647         // Add all links to iRichTextViewer.
       
   648         while ( attendeeLinks.Count() > 0 )
       
   649             {
       
   650             CESMRRichTextLink* link = attendeeLinks[0];
       
   651             CleanupStack::PushL( link );
       
   652             attendeeLinks.Remove( 0 );
       
   653             iRichTextViewer->AddLinkL( link );
       
   654             CleanupStack::Pop( link );
       
   655             }
       
   656         }
       
   657     SizeChanged();
       
   658     CleanupStack::PopAndDestroy( &attendeeLinks );
       
   659     CleanupStack::PopAndDestroy( &buffer );
       
   660     }
       
   661 
       
   662 // ---------------------------------------------------------------------------
       
   663 // CESMRViewerAttendeesField::LineSpacing
       
   664 // ---------------------------------------------------------------------------
       
   665 //
       
   666 TInt CESMRViewerAttendeesField::LineSpacing()
       
   667     {
       
   668     FUNC_LOG;
       
   669     // Calculates the line spacing based on default one line layout data
       
   670     TInt lineSpacing( 0 );
       
   671 
       
   672     TRect rect( Rect() );
       
   673 
       
   674     TAknLayoutRect rowLayoutRect =
       
   675         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   676     TRect rowRect = rowLayoutRect.Rect();
       
   677 
       
   678     TAknLayoutText labelLayout =
       
   679      NMRLayoutManager::GetLayoutText(
       
   680              rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   681 
       
   682     TRect defaultTextRect = labelLayout.TextRect();
       
   683 
       
   684     TInt difference = rowRect.Height() - defaultTextRect.Height();
       
   685 
       
   686     lineSpacing = difference * 2;
       
   687 
       
   688     return lineSpacing;
       
   689     }
       
   690 
       
   691 // ---------------------------------------------------------------------------
       
   692 // CESMRViewerAttendeesField::FocusMargin
       
   693 // ---------------------------------------------------------------------------
       
   694 //
       
   695 TInt CESMRViewerAttendeesField::FocusMargin()
       
   696     {
       
   697     FUNC_LOG;
       
   698     // Calculates focus margin based on default one line layout data
       
   699     TInt focusMagin( 0 );
       
   700 
       
   701     TRect rect( Rect() );
       
   702 
       
   703     TAknLayoutRect rowLayoutRect =
       
   704         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   705     TRect rowRect = rowLayoutRect.Rect();
       
   706 
       
   707     TAknLayoutText labelLayout =
       
   708      NMRLayoutManager::GetLayoutText(
       
   709              rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   710 
       
   711     TRect defaultTextRect = labelLayout.TextRect();
       
   712 
       
   713     TAknLayoutRect bgLayoutRect =
       
   714         NMRLayoutManager::GetLayoutRect(
       
   715                 rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   716     TRect defaultBgRect( bgLayoutRect.Rect() );
       
   717 
       
   718     TInt difference = defaultBgRect.Height() - defaultTextRect.Height();
       
   719 
       
   720     focusMagin = TReal( difference / 2 );
       
   721 
       
   722     return focusMagin;
       
   723     }
       
   724 
       
   725 // End of file
       
   726