meetingrequest/mrgui/mrfieldbuilderpluginextension/src/cesmrattendeefield.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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:  ESMR titled field implementation
       
    15  *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrattendeefield.h"
       
    20 
       
    21 #include <eiklabel.h>
       
    22 #include <avkon.hrh>
       
    23 #include <caluser.h>
       
    24 #include <calentry.h>
       
    25 #include <StringLoader.h>
       
    26 #include <esmrgui.rsg>
       
    27 #include <AknsFrameBackgroundControlContext.h>
       
    28 //<cmail>
       
    29 #include "esmrcommands.h"
       
    30 #include "CFSMailClient.h"
       
    31 //</cmail>
       
    32 #include "cesmrncspopuplistbox.h"
       
    33 #include "cesmrncsemailaddressobject.h"
       
    34 #include "mesmrlistobserver.h"
       
    35 #include "cesmrborderlayer.h"
       
    36 #include "cesmrcontacthandler.h"
       
    37 #include "mesmrmeetingrequestentry.h"
       
    38 #include "esmrfieldbuilderdef.h"
       
    39 #include "cesmrlayoutmgr.h"
       
    40 // <cmail> Removed profiling. </cmail>
       
    41 
       
    42 using namespace ESMRLayout;
       
    43 
       
    44 //CONSTANTS
       
    45 
       
    46 // unnamed namespace for local definitions
       
    47 namespace { // codescanner::namespace
       
    48 
       
    49 const TInt KMaxRemoteSearchResponseLength = 255;
       
    50 
       
    51 static void RPointerArrayResetAndDestroy( TAny* aPtr )
       
    52     {
       
    53     static_cast<RPointerArray<CESMRNcsEmailAddressObject>*>( aPtr )->ResetAndDestroy();
       
    54     }
       
    55 
       
    56 #ifdef _DEBUG
       
    57 
       
    58 // Panic code literal
       
    59 _LIT( KESMRAttendeeField, "ESMRAttendeeField" );
       
    60 
       
    61 /** Panic code enumeration */
       
    62 enum TESMRAttendeeFieldPanic
       
    63     {
       
    64     EESMRAttendeeFieldNotMeetingRequestEntry // Passed entry is not MR
       
    65     };
       
    66 
       
    67 void Panic( TESMRAttendeeFieldPanic aPanic )
       
    68     {
       
    69     User::Panic( KESMRAttendeeField, aPanic );
       
    70     }
       
    71 
       
    72 #endif // _DEBUG
       
    73 
       
    74 }//namespace
       
    75 
       
    76 // ======== MEMBER FUNCTIONS ========
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CESMRAttendeeField::CESMRAttendeeField
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CESMRAttendeeField::CESMRAttendeeField( CCalAttendee::TCalRole aRole ) :
       
    83     iRole( aRole)
       
    84     {
       
    85     FUNC_LOG;
       
    86     //do nothing
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CESMRAttendeeField::~CESMRAttendeeField
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CESMRAttendeeField::~CESMRAttendeeField( )
       
    94     {
       
    95     FUNC_LOG;
       
    96     delete iAacListBox;
       
    97     delete iTitle;
       
    98     delete iContactHandler;
       
    99     delete iDefaultText;
       
   100     delete iFrameBgContext;
       
   101     delete iPhoneOwnerAddr;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CESMRAttendeeField::NewL
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CESMRAttendeeField* CESMRAttendeeField::NewL( CCalAttendee::TCalRole aRole )
       
   109     {
       
   110     FUNC_LOG;
       
   111     CESMRAttendeeField* self = new (ELeave) CESMRAttendeeField( aRole );
       
   112     CleanupStack::PushL ( self );
       
   113     self->ConstructL ( );
       
   114     CleanupStack::Pop ( self );
       
   115     return self;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CESMRAttendeeField::ConstructL
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CESMRAttendeeField::ConstructL( )
       
   123     {
       
   124     FUNC_LOG;
       
   125     SetExpandable ( );
       
   126 
       
   127     SetFieldId ( (iRole == CCalAttendee::EReqParticipant) ? EESMRFieldAttendee
       
   128                                                           : EESMRFieldOptAttendee );
       
   129 
       
   130     iTitle = new (ELeave) CEikLabel();
       
   131     iTitle->SetLabelAlignment ( CESMRLayoutManager::IsMirrored ( ) ? ELayoutAlignRight
       
   132                                                                    : ELayoutAlignLeft );
       
   133 
       
   134     iContactHandler = CESMRContactHandler::NewL();
       
   135 
       
   136     iDefaultText = StringLoader::LoadL ( R_QTN_MEET_REQ_CONTACT_FIELD );
       
   137     iEditor = new ( ELeave ) CESMRNcsAifEditor( *iContactHandler, iDefaultText );
       
   138 
       
   139     iEditor->SetPopupList(this );
       
   140 
       
   141     HBufC* label = StringLoader::LoadLC (iRole == CCalAttendee::EReqParticipant ?
       
   142             R_QTN_MEET_REQ_LABEL_REQUIRED:R_QTN_MEET_REQ_LABEL_OPT );
       
   143 
       
   144     iTitle->SetTextL ( *label );
       
   145     CleanupStack::PopAndDestroy (label );
       
   146     
       
   147     iBackground = AknsDrawUtils::ControlContext( this );
       
   148     
       
   149     CESMRField::ConstructL ( iEditor );
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CESMRAttendeeField::InitializeL
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CESMRAttendeeField::InitializeL()
       
   157     {
       
   158     FUNC_LOG;
       
   159     iEditor->SetFontL( iLayout->Font(iCoeEnv, iFieldId), iLayout );
       
   160     iEditor->SetAlignment ( EAknEditorAlignBidi | EAknEditorAlignCenter );
       
   161     iEditor->SetAknEditorInputMode ( EAknEditorTextInputMode );
       
   162     iEditor->SetAknEditorFlags ( EAknEditorFlagNoT9| EAknEditorFlagUseSCTNumericCharmap );
       
   163     iEditor->SetAknEditorCurrentCase ( EAknEditorLowerCase );
       
   164     iEditor->CreateScrollBarFrameL()->SetScrollBarVisibilityL ( CEikScrollBarFrame::EOff,
       
   165                                                                 CEikScrollBarFrame::EOff );
       
   166     iEditor->SetEdwinSizeObserver ( this );
       
   167 
       
   168     iTitleSize = iLayout->FieldSize ( EESMRFieldAttendeeLabel );
       
   169     iTitle->SetFont( iLayout->Font(iCoeEnv, EESMRFieldAttendeeLabel) );
       
   170     
       
   171     iAacListBox->Initialise(iLayout);
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CESMRAttendeeField::InternalizeL
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CESMRAttendeeField::InternalizeL( MESMRCalEntry& aEntry )
       
   179     {
       
   180     FUNC_LOG;
       
   181     CCalEntry& entry = aEntry.Entry ( );
       
   182     RPointerArray< CCalAttendee > attendees = entry.AttendeesL ( );
       
   183     RPointerArray< CESMRNcsEmailAddressObject > addressList; // codescanner::resourcenotoncleanupstack
       
   184     TCleanupItem arrayCleanup( RPointerArrayResetAndDestroy, &addressList );
       
   185     CleanupStack::PushL( arrayCleanup );
       
   186 
       
   187     for (TInt i(0); i < attendees.Count ( ); i++ )
       
   188         {
       
   189         if ( attendees[i]->RoleL() == iRole )
       
   190             {
       
   191             const TDesC& addr = attendees[i]->Address ( );
       
   192             const TDesC& commonName = attendees[i]->CommonName ( );
       
   193 
       
   194             CESMRNcsEmailAddressObject* obj = CESMRNcsEmailAddressObject::NewL ( commonName, addr );
       
   195             CleanupStack::PushL (obj );
       
   196             addressList.AppendL( obj );
       
   197             CleanupStack::Pop( obj );
       
   198             }
       
   199         }
       
   200 
       
   201     if (attendees.Count() > 0 )
       
   202         {
       
   203         if ( !iObserver->IsControlVisible(iFieldId ) )
       
   204             {
       
   205             iObserver->InsertControl(iFieldId );
       
   206             }
       
   207         iEditor->SetAddressesL( addressList );
       
   208         }
       
   209     else
       
   210         {
       
   211         AppendDefaultTextL();
       
   212         //during initialisation, SelectAllL() in setoutlinefocus gets overridden so this is needed
       
   213         iEditor->SelectAllL();
       
   214         }
       
   215 
       
   216     //don't show optional attendees field on initialisation if there are none
       
   217     if ( iRole == CCalAttendee::EOptParticipant )
       
   218         {
       
   219         if ( addressList.Count() == 0 )
       
   220             {
       
   221             this->MakeVisible(EFalse);
       
   222             }
       
   223         }
       
   224 
       
   225     CleanupStack::PopAndDestroy( &addressList );
       
   226     // this is needed to be re-called here, otherwise the CEikEdwin
       
   227     // does not get correctly instantiated with default text
       
   228     iEditor->FocusChanged(EDrawNow);
       
   229     
       
   230     UpdateSendOptionL();
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CESMRAttendeeField::ExternalizeL
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void CESMRAttendeeField::ExternalizeL( MESMRCalEntry& aEntry )
       
   238     {
       
   239     FUNC_LOG;
       
   240     MESMRMeetingRequestEntry* mrEntry = NULL;
       
   241     if ( MESMRCalEntry::EESMRCalEntryMeetingRequest == aEntry.Type() )
       
   242         {
       
   243         mrEntry = static_cast<MESMRMeetingRequestEntry*>(&aEntry);
       
   244         }
       
   245 
       
   246     // This should always be called for MR entries
       
   247     __ASSERT_DEBUG( mrEntry, Panic(EESMRAttendeeFieldNotMeetingRequestEntry ) );
       
   248 
       
   249     if(iEditor->HasDefaultText())
       
   250         {
       
   251         ClearDefaultTextL();
       
   252         }
       
   253 
       
   254     // remove all previous attendees from the attendee list
       
   255     CCalEntry& entry = mrEntry->Entry();
       
   256     
       
   257     if ( !iPhoneOwnerAddr )
       
   258     	{
       
   259 		CCalUser* phoneOwner = entry.PhoneOwnerL();
       
   260 		if (phoneOwner)
       
   261 			{
       
   262 			iPhoneOwnerAddr = phoneOwner->Address().AllocL();
       
   263 			}
       
   264     	}
       
   265     
       
   266     ClearAttendeeListL ( entry );
       
   267     ParseAttendeesL ( *mrEntry );
       
   268     
       
   269     HBufC *text = iEditor->GetTextInHBufL();
       
   270         
       
   271     //If there is no added attendees put back the default text
       
   272     if(!text)
       
   273         {
       
   274     	AppendDefaultTextL();
       
   275     	//during initialisation, SelectAllL() in setoutlinefocus gets overridden so this is needed
       
   276     	iEditor->SelectAllL();
       
   277     	}
       
   278     delete text;
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CESMRAttendeeField::ExpandedHeight
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 TInt CESMRAttendeeField::ExpandedHeight( ) const
       
   286     {
       
   287     FUNC_LOG;
       
   288     return iTitleSize.iHeight + iExpandedSize.iHeight;
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // CESMRSubjectField::GetMinimumVisibleVerticalArea
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 void CESMRAttendeeField::GetMinimumVisibleVerticalArea(TInt& aUpper, TInt& aLower)
       
   296     {
       
   297     FUNC_LOG;
       
   298     TRect rect;
       
   299 
       
   300     TRAPD( err, iEditor->GetLineRectL( rect ) );
       
   301 
       
   302     if ( err == KErrNone )
       
   303         {
       
   304         rect.Move( 0, iTitleSize.iHeight );
       
   305         aUpper = rect.iTl.iY;
       
   306         aLower = rect.iBr.iY;
       
   307         }
       
   308     else
       
   309         {
       
   310         // This isn't expected to happen in any situation.
       
   311         // but if it does at least there will be no zero size
       
   312         CESMRField::GetMinimumVisibleVerticalArea( aUpper, aLower );
       
   313         }
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CESMRAttendeeField::CountComponentControls
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 TInt CESMRAttendeeField::CountComponentControls( ) const
       
   321     {
       
   322     FUNC_LOG;
       
   323     TInt count = CESMRField::CountComponentControls ( );
       
   324 
       
   325     if ( iTitle )
       
   326         {
       
   327         ++count;
       
   328         }
       
   329 
       
   330     return count;
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CESMRAttendeeField::ComponentControl
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 CCoeControl* CESMRAttendeeField::ComponentControl( TInt aInd ) const
       
   338     {
       
   339     FUNC_LOG;
       
   340     if ( aInd == 0 )
       
   341         {
       
   342         return iTitle;
       
   343         }
       
   344     return CESMRField::ComponentControl ( aInd );
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // CESMRAttendeeField::SizeChanged
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void CESMRAttendeeField::SizeChanged( )
       
   352     {
       
   353     FUNC_LOG;
       
   354     TRect rect = Rect ( );
       
   355 
       
   356     if ( CESMRLayoutManager::IsMirrored ( ) )
       
   357         {
       
   358         TPoint titlePos( rect.iBr.iX - iTitleSize.iWidth, rect.iTl.iY );
       
   359         iTitle->SetExtent ( titlePos, iTitleSize );
       
   360 
       
   361         TSize textSize( rect.Width ( ) - ( KIconSize.iWidth + KIconBorderMargin ),
       
   362                 iExpandedSize.iHeight );
       
   363         TPoint textPos( rect.iBr.iX - KIconSize.iWidth- textSize.iWidth,
       
   364                 rect.iTl.iY + iTitleSize.iHeight );
       
   365         iBorder->SetExtent ( textPos, textSize );
       
   366         }
       
   367     else
       
   368         {
       
   369         // title
       
   370         iTitle->SetExtent ( rect.iTl, iTitleSize );
       
   371 
       
   372         // editor (editor is wrapped inside the 'iBorder' member)
       
   373         TRect borderRect(TPoint (
       
   374                 rect.iTl.iX + KIconSize.iWidth + KIconBorderMargin,
       
   375                 rect.iTl.iY + iTitleSize.iHeight ), TSize (
       
   376                 rect.Width ( )- KIconSize.iWidth + KIconBorderMargin - KFieldEndMargin,
       
   377                 iExpandedSize.iHeight ));
       
   378 
       
   379         iBorder->SetRect (borderRect );
       
   380         }
       
   381 
       
   382     if ( iAacListBox && iAacListBox->IsVisible ( ) )
       
   383         {
       
   384         TRAPD( error, iAacListBox->SetPopupMaxRectL( ResolvePopupRectL()) )
       
   385         if ( error )
       
   386             {
       
   387             CEikonEnv::Static()->// codescanner::eikonenvstatic
       
   388                 HandleError( error );
       
   389             }
       
   390         }
       
   391     
       
   392     if( iFrameBgContext )
       
   393         {
       
   394         TRect visibleRect = CalculateVisibleRect( iEditor->Rect() );
       
   395         iFrameBgContext->SetFrameRects( visibleRect, visibleRect );
       
   396         }    
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // CESMRAttendeeField::PositionChanged
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 void CESMRAttendeeField::PositionChanged( )
       
   404     {
       
   405     FUNC_LOG;
       
   406     if ( iAacListBox && iAacListBox->IsVisible ( ) )
       
   407         {
       
   408         TRAPD( error, iAacListBox->SetPopupMaxRectL( ResolvePopupRectL()) )
       
   409         if ( error )
       
   410             {
       
   411             CEikonEnv::Static()->// codescanner::eikonenvstatic
       
   412                 HandleError( error );
       
   413             }
       
   414         }
       
   415     
       
   416     if( iFrameBgContext )
       
   417         {
       
   418         TRect visibleRect = CalculateVisibleRect( iEditor->Rect() );
       
   419         iFrameBgContext->SetFrameRects( visibleRect, visibleRect );
       
   420         }
       
   421     }
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CESMRAttendeeField::ResolvePopupRectL
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 TRect CESMRAttendeeField::ResolvePopupRectL( )
       
   428     {
       
   429     FUNC_LOG;
       
   430     if ( !iAacListBox )
       
   431         {
       
   432         return TRect(0,0,0,0);
       
   433         }
       
   434 
       
   435     TRect popupRect = iBorder->Rect();
       
   436     TRect lineRect;
       
   437     iEditor->GetLineRectL( lineRect );
       
   438     lineRect.Move( 0, popupRect.iTl.iY );
       
   439     TRect parentRect = Parent()->Rect();
       
   440 
       
   441     TInt listBoxBorderHeight = iAacListBox->CalcHeightBasedOnNumOfItems( 0 );
       
   442     TInt listBoxItemHeight = iAacListBox->CalcHeightBasedOnNumOfItems( 1 )
       
   443                                 - listBoxBorderHeight;
       
   444 
       
   445     if ( lineRect.iTl.iY > ( parentRect.Height() >> 1 ) )
       
   446         {
       
   447         // Draw popup list on top of cursor
       
   448         popupRect.iTl.iY = parentRect.iTl.iY;
       
   449         popupRect.iBr.iY = lineRect.iTl.iY;
       
   450 
       
   451         TInt diff = popupRect.Height() % listBoxItemHeight;
       
   452         popupRect.iTl.iY += diff - listBoxBorderHeight;
       
   453         }
       
   454     else
       
   455         {
       
   456         // Draw popup list below cursor
       
   457         popupRect.iTl.iY = lineRect.iBr.iY;
       
   458         popupRect.iBr.iY = parentRect.iBr.iY;
       
   459 
       
   460         TInt diff = popupRect.Height() % listBoxItemHeight;
       
   461         popupRect.iBr.iY -= diff - listBoxBorderHeight;
       
   462         }
       
   463 
       
   464     return popupRect;
       
   465     }
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // CNcsAddressInputField:::AppendDefaultTextL()
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 void CESMRAttendeeField::AppendDefaultTextL()
       
   472     {
       
   473     FUNC_LOG;
       
   474     iEditor->SetTextL( iDefaultText );
       
   475     iEditor->HandleTextChangedL();
       
   476     }
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CNcsAddressInputField::ClearDefaultTextL()
       
   480 // -----------------------------------------------------------------------------
       
   481 //
       
   482 void CESMRAttendeeField::ClearDefaultTextL()
       
   483     {
       
   484     FUNC_LOG;
       
   485     iEditor->SetTextL( &KNullDesC );
       
   486     iEditor->HandleTextChangedL();
       
   487     }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // CESMRAttendeeField::OfferKeyEventL
       
   491 // ---------------------------------------------------------------------------
       
   492 //
       
   493 TKeyResponse CESMRAttendeeField::OfferKeyEventL( 
       
   494         const TKeyEvent& aKeyEvent,
       
   495         TEventCode aType )
       
   496     {
       
   497     FUNC_LOG;
       
   498 
       
   499     TKeyResponse ret( EKeyWasNotConsumed);
       
   500 
       
   501     if ( aKeyEvent.iCode == EKeyEnter || 
       
   502          aKeyEvent.iScanCode == EStdKeyEnter ||
       
   503          aKeyEvent.iCode == EKeyYes ||
       
   504          aKeyEvent.iScanCode == EStdKeyYes )
       
   505         {//prevent these keys from being used in any attendee field editor
       
   506         return EKeyWasConsumed;
       
   507         }
       
   508 
       
   509     if ( aKeyEvent.iCode == EKeyUpArrow || aKeyEvent.iCode == EKeyDownArrow )
       
   510         {
       
   511         if( iAacListBox && iAacListBox->IsVisible() && !iAacListBox->IsPopupEmpty() )
       
   512             {
       
   513             return iAacListBox->OfferKeyEventL( aKeyEvent, aType );
       
   514             }
       
   515         else
       
   516             {
       
   517             ret = iEditor->OfferKeyEventL (aKeyEvent, aType );
       
   518             }
       
   519         }
       
   520     else
       
   521         {
       
   522         if ( iAacListBox && iAacListBox->IsVisible ( ) )
       
   523             {
       
   524             if( aKeyEvent.iCode == EKeyDevice3 || aKeyEvent.iCode == EKeyDevice4 ||
       
   525                 aKeyEvent.iCode == EKeyOK )
       
   526                 {
       
   527                 DoPopupSelectL();
       
   528                 ret = EKeyWasConsumed;
       
   529                 }
       
   530             }
       
   531         }
       
   532 
       
   533     if ( ret == EKeyWasNotConsumed )
       
   534         {
       
   535         ret = iEditor->OfferKeyEventL (aKeyEvent, aType );
       
   536         UpdateSendOptionL();
       
   537         }
       
   538 
       
   539     // Scroll editor.
       
   540     if ( iObserver && aType == EEventKey )
       
   541         {
       
   542         CTextLayout* textLayout = iEditor->TextLayout();
       
   543         TInt lineHeight = iEditor->GetLineHeightL();
       
   544 
       
   545         TPoint cursorPos( 0,0 );
       
   546         textLayout->DocPosToXyPosL( iEditor->CursorPos(), cursorPos );
       
   547 
       
   548         TInt editorTlY = iEditor->Position().iY;
       
   549         TInt listHeight = iObserver->ListHeight();
       
   550         
       
   551         TInt cursorTopY = cursorPos.iY - lineHeight + editorTlY;
       
   552         TInt cursorBottomY = cursorPos.iY + lineHeight + editorTlY;
       
   553 
       
   554         // If cursor is below visible area
       
   555         if ( cursorBottomY > listHeight )
       
   556             {
       
   557             iObserver->MoveListAreaUpL( cursorBottomY - listHeight );
       
   558             }
       
   559         // If cursor is over the top of visible area
       
   560         else if ( cursorTopY < 0 )
       
   561             {
       
   562             iObserver->MoveListAreaDownL( -cursorTopY );
       
   563             }
       
   564         // Latch on top of the screen
       
   565         else if ( textLayout->GetLineNumber( iEditor->CursorPos() ) < 2 )
       
   566             {
       
   567             iObserver->MoveListAreaDownL( iTitleSize.iHeight );
       
   568             }
       
   569         
       
   570         }
       
   571     return ret;
       
   572     }
       
   573 
       
   574 // ---------------------------------------------------------------------------
       
   575 // CESMRAttendeeField::SetContainerWindowL()
       
   576 // ---------------------------------------------------------------------------
       
   577 //
       
   578 void CESMRAttendeeField::SetContainerWindowL( const CCoeControl& aControl )
       
   579     {
       
   580     FUNC_LOG;
       
   581     CESMRField::SetContainerWindowL ( aControl );
       
   582 
       
   583     iEditor->ConstructL (
       
   584             this,
       
   585             KMaxAddressFieldLines,
       
   586             0,
       
   587             CEikEdwin::EAvkonEditor | CEikEdwin::EResizable |
       
   588             CEikEdwin::ENoAutoSelection |CEikEdwin::EInclusiveSizeFixed |
       
   589             CEikEdwin::ENoHorizScrolling 
       
   590             );
       
   591 
       
   592     iAacListBox = CESMRNcsPopupListBox::NewL ( this, *iContactHandler );
       
   593     iAacListBox->MakeVisible ( EFalse );
       
   594     iAacListBox->SetObserver( this );
       
   595     iAacListBox->ActivateL();
       
   596     iButtonGroupContainer = CEikButtonGroupContainer::Current();
       
   597 
       
   598     }
       
   599 
       
   600 // ---------------------------------------------------------------------------
       
   601 // CESMRAttendeeField::ActivateL
       
   602 // ---------------------------------------------------------------------------
       
   603 //
       
   604 void CESMRAttendeeField::ActivateL()
       
   605     {
       
   606     CCoeControl::ActivateL();
       
   607     
       
   608     TRect editorRect = iEditor->Rect();
       
   609     
       
   610     delete iFrameBgContext;
       
   611     iFrameBgContext = NULL;
       
   612     iFrameBgContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrInput, editorRect, editorRect, EFalse ) ;
       
   613 
       
   614     iFrameBgContext->SetParentContext( iBackground );
       
   615     iEditor->SetSkinBackgroundControlContextL( iFrameBgContext );
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------------------------
       
   619 // CESMRAttendeeField::HandleEdwinSizeEventL
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 TBool CESMRAttendeeField::HandleEdwinSizeEventL(CEikEdwin* /*aEdwin*/,
       
   623         TEdwinSizeEvent /*aType*/, TSize aSize )
       
   624     {
       
   625     FUNC_LOG;
       
   626     iExpandedSize = aSize;
       
   627     if ( iObserver )
       
   628         {
       
   629         iObserver->ControlSizeChanged ( this );
       
   630         }
       
   631     
       
   632     if ( iFrameBgContext )
       
   633         {
       
   634         TRect visibleRect = CalculateVisibleRect( iEditor->Rect() );
       
   635         iFrameBgContext->SetFrameRects( visibleRect, visibleRect );
       
   636         }
       
   637     
       
   638     return ETrue;
       
   639     }
       
   640 
       
   641 // ---------------------------------------------------------------------------
       
   642 // CESMRAttendeeField::UpdatePopupContactListL
       
   643 // ---------------------------------------------------------------------------
       
   644 //
       
   645 void CESMRAttendeeField::UpdatePopupContactListL( 
       
   646         const TDesC& aMatchString, 
       
   647         TBool /*iListAll*/)
       
   648     {
       
   649     FUNC_LOG;
       
   650     if ( aMatchString.CompareC ( KNullDesC )== 0 )
       
   651         {
       
   652         ClosePopupContactListL ( );
       
   653         }
       
   654     else if ( iAacListBox )
       
   655         {
       
   656         // Popup will be shown when async HandleControlEventL is received
       
   657         iAacListBoxEnabled = ETrue;
       
   658 
       
   659         if ( iAacListBox->IsVisible() )
       
   660             {
       
   661             iAacListBox->SetSearchTextL( aMatchString );
       
   662             }
       
   663         else
       
   664             {
       
   665             iAacListBox->InitAndSearchL ( aMatchString );
       
   666             }
       
   667         }
       
   668     }
       
   669 
       
   670 // ---------------------------------------------------------------------------
       
   671 // CESMRHeaderContainer:ShowPopupCbaL
       
   672 // ---------------------------------------------------------------------------
       
   673 //
       
   674 void CESMRAttendeeField::ShowPopupCbaL( TBool aShow )
       
   675     {
       
   676     if( aShow )
       
   677             {
       
   678             iButtonGroupContainer->SetCommandSetL( 
       
   679                     R_CONTACT_POPUP_SOFTKEYS_SELECT_CANCEL);
       
   680             }
       
   681         else
       
   682             {
       
   683             iButtonGroupContainer->SetCommandSetL( 
       
   684                     R_CONTACT_EDITOR_SOFTKEYS_OPTIONS_DONE__ADD);       
       
   685             }
       
   686         iButtonGroupContainer->DrawDeferred();
       
   687     }
       
   688 
       
   689 // ---------------------------------------------------------------------------
       
   690 // CESMRHeaderContainer:ExecuteGenericCommandL
       
   691 // ---------------------------------------------------------------------------
       
   692 //
       
   693 void CESMRAttendeeField::ExecuteGenericCommandL( TInt aCommand )
       
   694     {
       
   695     FUNC_LOG;
       
   696     switch ( aCommand )
       
   697         {
       
   698         case EESMRCmdAttendeeInsertContact:
       
   699             {
       
   700             iContactHandler->GetAddressesFromPhonebookL( this );
       
   701             }
       
   702             break;
       
   703          case EESMRCmdAttendeeSoftkeySelect:
       
   704              {
       
   705              DoPopupSelectL();
       
   706              }
       
   707              break;
       
   708          case EESMRCmdAttendeeSoftkeyCancel:
       
   709              {
       
   710              ClosePopupContactListL();
       
   711              }
       
   712              break;
       
   713          default:
       
   714              break;
       
   715         }
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------------------------
       
   719 // CESMRBooleanField::SetOutlineFocusL
       
   720 // ---------------------------------------------------------------------------
       
   721 //
       
   722 void CESMRAttendeeField::SetOutlineFocusL( TBool aFocus )
       
   723     {
       
   724     FUNC_LOG;
       
   725     CESMRField::SetOutlineFocusL( aFocus );
       
   726 
       
   727     if (aFocus) //Focus is gained on the field
       
   728         {
       
   729         if ( iEditor->HasDefaultText() )
       
   730             {
       
   731             iEditor->SelectAllL();
       
   732             }
       
   733         ChangeMiddleSoftKeyL( R_MR_ADD_SOFTKEY );
       
   734         }
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------------------------
       
   738 // CESMRAttendeeField::OperationComplete()
       
   739 // ---------------------------------------------------------------------------
       
   740 //
       
   741 void CESMRAttendeeField::OperationCompleteL(
       
   742         TContactHandlerCmd /*aCmd*/,
       
   743         const RPointerArray<CESMRClsItem>* aContacts )
       
   744     {
       
   745     FUNC_LOG;
       
   746     if ( aContacts )
       
   747         {
       
   748         RPointerArray<CESMRNcsEmailAddressObject> ncsObjects;  // codescanner::resourcenotoncleanupstack
       
   749         TCleanupItem arrayCleanup( RPointerArrayResetAndDestroy, &ncsObjects );
       
   750         CleanupStack::PushL( arrayCleanup );
       
   751         for ( int i = 0; i < aContacts->Count(); i++ )
       
   752             {
       
   753             CESMRNcsEmailAddressObject* object =
       
   754                 CESMRNcsEmailAddressObject::NewL(
       
   755                     (*aContacts)[i]->DisplayName(),
       
   756                     (*aContacts)[i]->EmailAddress() );
       
   757             object->SetDisplayFull( (*aContacts)[i]->MultipleEmails() );
       
   758             ncsObjects.Append( object );
       
   759             }
       
   760 
       
   761         iEditor->AppendAddressesL(ncsObjects);
       
   762         CleanupStack::PopAndDestroy( &ncsObjects );
       
   763         UpdateSendOptionL();
       
   764         }
       
   765     }
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // CESMRAttendeeField::OperationError
       
   769 // ---------------------------------------------------------------------------
       
   770 //
       
   771 void CESMRAttendeeField::OperationErrorL( TContactHandlerCmd /*aCmd*/,
       
   772                                           TInt /*aError*/ )
       
   773     {
       
   774     FUNC_LOG;
       
   775     //Nothing to do
       
   776     }
       
   777 
       
   778 // ---------------------------------------------------------------------------
       
   779 // CESMRAttendeeField::HandleControlEventL
       
   780 // ---------------------------------------------------------------------------
       
   781 //
       
   782 void CESMRAttendeeField::HandleControlEventL(
       
   783         CCoeControl *aControl, 
       
   784         TCoeEvent aEventType )
       
   785     {
       
   786     FUNC_LOG;
       
   787     if ( aControl == iAacListBox &&
       
   788          aEventType == MCoeControlObserver::EEventStateChanged &&
       
   789          iAacListBoxEnabled )
       
   790         {
       
   791         if ( iAacListBox && iAacListBox->IsVisible() && iAacListBox->IsPopupEmpty() )
       
   792             {
       
   793             ClosePopupContactListL();
       
   794             }
       
   795         else if ( iAacListBox && !iAacListBox->IsVisible() && !iAacListBox->IsPopupEmpty() )
       
   796             {
       
   797             iAacListBox->SetPopupMaxRectL( ResolvePopupRectL() );
       
   798             iAacListBox->MakeVisible ( ETrue );
       
   799             ShowPopupCbaL( ETrue );
       
   800             }
       
   801         else
       
   802             {
       
   803             UpdateSendOptionL();
       
   804             }
       
   805         }
       
   806     }
       
   807 
       
   808 // ---------------------------------------------------------------------------
       
   809 // CESMRAttendeeField::ClearAttendeeListL
       
   810 // ---------------------------------------------------------------------------
       
   811 //
       
   812 void CESMRAttendeeField::ClearAttendeeListL( CCalEntry& aEntry )
       
   813     {
       
   814     FUNC_LOG;
       
   815     RPointerArray< CCalAttendee > & att = aEntry.AttendeesL( );
       
   816     for (TInt i(0); i < att.Count( ); )
       
   817         {
       
   818         // if there is an attendee with this fields role, remove it
       
   819         if ( att[i]->RoleL( )== iRole )
       
   820             {
       
   821             aEntry.DeleteAttendeeL( i );
       
   822             }
       
   823         else
       
   824             {
       
   825             ++i;
       
   826             }
       
   827         }
       
   828     }
       
   829 
       
   830 // ---------------------------------------------------------------------------
       
   831 // CESMRAttendeeField::ParseAttendeesL
       
   832 // ---------------------------------------------------------------------------
       
   833 //
       
   834 void CESMRAttendeeField::ParseAttendeesL(
       
   835 		MESMRMeetingRequestEntry& aMREntry )
       
   836     {
       
   837     FUNC_LOG;
       
   838     iEditor->CheckAddressWhenFocusLostL ( );
       
   839 
       
   840     RPointerArray<CESMRNcsEmailAddressObject> attendees = iEditor->GetAddressesL ( );
       
   841     CCalEntry& entry( aMREntry.Entry() );
       
   842     TInt count = attendees.Count ( );
       
   843     
       
   844     for (TInt i=0; i<count; i++ )
       
   845         {
       
   846         CESMRNcsEmailAddressObject* obj = attendees[i];
       
   847         CCalAttendee* attendee = CCalAttendee::NewL ( obj->EmailAddress ( ) );
       
   848         attendee->SetRoleL ( iRole );
       
   849         attendee->SetCommonNameL ( obj->DisplayName ( ) );
       
   850 
       
   851         if ( EESMRRoleOrganizer == aMREntry.RoleL() || 
       
   852         	 aMREntry.IsForwardedL() )
       
   853             {
       
   854             attendee->SetResponseRequested( ETrue );
       
   855             }
       
   856         
       
   857         entry.AddAttendeeL ( attendee );
       
   858         if (iPhoneOwnerAddr && attendee->Address().CompareF(*iPhoneOwnerAddr) == 0)
       
   859         	{
       
   860         	entry.SetPhoneOwnerL(static_cast<CCalUser*>(attendee));
       
   861         	}
       
   862         }
       
   863         
       
   864     }
       
   865 
       
   866 // -----------------------------------------------------------------------------
       
   867 // CESMRHeaderContainer::DoPopupSelect
       
   868 // -----------------------------------------------------------------------------
       
   869 //
       
   870 void CESMRAttendeeField::DoPopupSelectL()
       
   871     {
       
   872     FUNC_LOG;
       
   873     if( iAacListBox && iAacListBox->IsRemoteLookupItemSelected() )
       
   874         {
       
   875         // Launch remote lookup
       
   876         HBufC* lookupText = iEditor->GetLookupTextLC();
       
   877         CPbkxRemoteContactLookupServiceUiContext::TResult::TExitReason exitReason;
       
   878         CESMRNcsEmailAddressObject* address = ExecuteRemoteSearchL(
       
   879             exitReason,
       
   880             *lookupText );
       
   881         if ( address )
       
   882             {
       
   883             CleanupStack::PushL( address );
       
   884             iEditor->AddAddressL( *address );
       
   885             CleanupStack::PopAndDestroy( address );
       
   886             }
       
   887         CleanupStack::PopAndDestroy( lookupText );
       
   888         }
       
   889     else if( iAacListBox && !iAacListBox->IsPopupEmpty() )
       
   890         {
       
   891         CESMRNcsEmailAddressObject* emailAddress  = 
       
   892                 iAacListBox->ReturnCurrentEmailAddressLC();
       
   893         if( emailAddress )
       
   894             {
       
   895             if ( emailAddress->EmailAddress().Compare( KNullDesC ))
       
   896                 {
       
   897                 iEditor->AddAddressL( *emailAddress );
       
   898                 }
       
   899             else
       
   900                 {
       
   901                 // selected contact doesn't have email address, launch remote contact lookup
       
   902                 // rcl must be usable, since otherwise there couldn't be any items
       
   903                 // without email addresses
       
   904                 CPbkxRemoteContactLookupServiceUiContext::TResult::TExitReason exitReason;
       
   905                 CESMRNcsEmailAddressObject* remAddress = ExecuteRemoteSearchL(
       
   906                     exitReason,
       
   907                     emailAddress->DisplayName() );
       
   908                 if ( remAddress )
       
   909                     {
       
   910                     CleanupStack::PushL( remAddress );
       
   911                     iEditor->AddAddressL( *remAddress );
       
   912                     CleanupStack::PopAndDestroy( remAddress );
       
   913                     }
       
   914                 }
       
   915             CleanupStack::PopAndDestroy( emailAddress );
       
   916             }
       
   917         }
       
   918     ClosePopupContactListL();
       
   919     }
       
   920 
       
   921 // -----------------------------------------------------------------------------
       
   922 // CNcsHeaderContainer::ClosePopupContactListL()
       
   923 // -----------------------------------------------------------------------------
       
   924 //
       
   925 void CESMRAttendeeField::ClosePopupContactListL()
       
   926     {
       
   927     FUNC_LOG;
       
   928     // Disable popup if we get async HandleControlEventL later
       
   929     iAacListBoxEnabled = EFalse;
       
   930 
       
   931     if ( iAacListBox && iAacListBox->IsVisible() )
       
   932         {
       
   933         iAacListBox->MakeVisible( EFalse );
       
   934         AknsUtils::SetAvkonSkinEnabledL( ETrue );
       
   935         ShowPopupCbaL( EFalse );
       
   936         }
       
   937     
       
   938     UpdateSendOptionL();
       
   939     }
       
   940 
       
   941 // ---------------------------------------------------------------------------
       
   942 // CNcsHeaderContainer::ExecuteRemoteSearchL
       
   943 // ---------------------------------------------------------------------------
       
   944 //
       
   945 CESMRNcsEmailAddressObject* CESMRAttendeeField::ExecuteRemoteSearchL(
       
   946     CPbkxRemoteContactLookupServiceUiContext::TResult::TExitReason& /*aExitReason*/,
       
   947     const TDesC& aSearchText )
       
   948     {
       
   949     FUNC_LOG;
       
   950     RBuf displayname;  // codescanner::resourcenotoncleanupstack
       
   951     displayname.CreateL( KMaxRemoteSearchResponseLength );
       
   952     displayname.CleanupClosePushL();
       
   953     RBuf emailAddress;  // codescanner::resourcenotoncleanupstack
       
   954     emailAddress.CreateL( KMaxRemoteSearchResponseLength );
       
   955     emailAddress.CleanupClosePushL();
       
   956     
       
   957     TBool contactSelected = iContactHandler->LaunchRemoteLookupL( aSearchText,
       
   958                                                                   displayname,
       
   959                                                                   emailAddress );
       
   960 
       
   961     CESMRNcsEmailAddressObject* address = NULL;
       
   962     if ( contactSelected )
       
   963         {
       
   964         if ( !displayname.Length() )
       
   965             {
       
   966             address = CESMRNcsEmailAddressObject::NewL( emailAddress, emailAddress );
       
   967             }
       
   968         else
       
   969             {
       
   970             address = CESMRNcsEmailAddressObject::NewL( displayname, emailAddress );
       
   971             }
       
   972         }
       
   973 
       
   974     CleanupStack::PopAndDestroy( &emailAddress );
       
   975     CleanupStack::PopAndDestroy( &displayname );
       
   976     
       
   977     return address;
       
   978     }
       
   979 
       
   980 // ---------------------------------------------------------------------------
       
   981 // CESMRAttendeeField::UpdateSendOptionL
       
   982 // ---------------------------------------------------------------------------
       
   983 //
       
   984 void CESMRAttendeeField::UpdateSendOptionL()
       
   985     {
       
   986     FUNC_LOG;
       
   987     // Check if editor has text and it is different from default text.
       
   988     HBufC *text = iEditor->GetTextInHBufL();
       
   989     TBool enable = text && text->Length() > 0 && text->Compare( *iDefaultText ) != 0;
       
   990     delete text;
       
   991 
       
   992     // Send proper command to CESMREditorDialog::ProcessCommandL
       
   993     TInt command = 0;
       
   994     if ( iRole == CCalAttendee::EReqParticipant )
       
   995         {
       
   996         if ( enable )
       
   997             {
       
   998             command = EESMRCmdAttendeeRequiredEnabled;
       
   999             }
       
  1000         else
       
  1001             {
       
  1002             command = EESMRCmdAttendeeRequiredDisabled;
       
  1003             }
       
  1004         }
       
  1005     else if ( iRole == CCalAttendee::EOptParticipant )
       
  1006         {
       
  1007         if ( enable )
       
  1008             {
       
  1009             command = EESMRCmdAttendeeOptionalEnabled;
       
  1010             }
       
  1011         else
       
  1012             {
       
  1013             command = EESMRCmdAttendeeOptionalDisabled;
       
  1014             }
       
  1015         }
       
  1016     
       
  1017     NotifyEventL( command );
       
  1018     }
       
  1019 
       
  1020 //EOF
       
  1021