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