emailuis/emailui/src/ncsheadercontainer.cpp
branchRCL_3
changeset 80 726fba06891a
parent 73 c8382f7b54ef
equal deleted inserted replaced
73:c8382f7b54ef 80:726fba06891a
    21 #include <StringLoader.h>
    21 #include <StringLoader.h>
    22 #include <aknViewAppUi.h>
    22 #include <aknViewAppUi.h>
    23 #include <aknnotewrappers.h> //CAknInformationNote
    23 #include <aknnotewrappers.h> //CAknInformationNote
    24 #include <FreestyleEmailUi.rsg>
    24 #include <FreestyleEmailUi.rsg>
    25 #include <aknphysics.h>
    25 #include <aknphysics.h>
    26 #include <AknPriv.hrh>
       
    27 
    26 
    28 #include "cfsmailbox.h"
    27 #include "cfsmailbox.h"
    29 #include <FreestyleEmailUi.rsg>
    28 #include <FreestyleEmailUi.rsg>
    30 #include <layoutmetadata.cdl.h>
       
    31 
    29 
    32 #include "FSEmailBuildFlags.h"
    30 #include "FSEmailBuildFlags.h"
    33 #include "ncsheadercontainer.h"
    31 #include "ncsheadercontainer.h"
    34 #include "ncscomposeviewcontainer.h"
    32 #include "ncscomposeviewcontainer.h"
    35 #include "ncsemailaddressobject.h"
    33 #include "ncsemailaddressobject.h"
    81 	CAknPhysics* aPhysics ): 
    79 	CAknPhysics* aPhysics ): 
    82 	iParent( aParent ),
    80 	iParent( aParent ),
    83 	iFieldSizeObserver( static_cast< CNcsComposeViewContainer& >( aParent ) ),
    81 	iFieldSizeObserver( static_cast< CNcsComposeViewContainer& >( aParent ) ),
    84 	iMailBox( aMailBox ),
    82 	iMailBox( aMailBox ),
    85 	iLongTapEventConsumed( EFalse ),
    83 	iLongTapEventConsumed( EFalse ),
    86     iPhysics( aPhysics ),
    84     iPhysics( aPhysics )
    87     iSplitScreenVKBEnabled( EFalse )
       
    88 	{
    85 	{
    89     FUNC_LOG;
    86     FUNC_LOG;
    90 	}
    87 	}
    91 
    88 
    92 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
   128 	// Create 'subject' field
   125 	// Create 'subject' field
   129 	iSubjectField = CNcsSubjectField::NewL( R_FSE_EDITOR_HEADER_SUBJECT, 
   126 	iSubjectField = CNcsSubjectField::NewL( R_FSE_EDITOR_HEADER_SUBJECT, 
   130 	        &iFieldSizeObserver, this );
   127 	        &iFieldSizeObserver, this );
   131     
   128     
   132     iAttachmentField = CNcsAttachmentField::NewL( R_NCS_ATTACHMENT_LABEL_TEXT, 
   129     iAttachmentField = CNcsAttachmentField::NewL( R_NCS_ATTACHMENT_LABEL_TEXT, 
   133             &iFieldSizeObserver, this );
   130             &iFieldSizeObserver, this, this );
   134 
   131 
   135     // Setup the control array
   132     // Setup the control array
   136     // Add all of them now so the container and parent is set correctly
   133     // Add all of them now so the container and parent is set correctly
   137     InitComponentArrayL();
   134     InitComponentArrayL();
   138     CCoeControlArray& controls = Components();
   135     CCoeControlArray& controls = Components();
   160         {
   157         {
   161         controls.Remove( iBccField );
   158         controls.Remove( iBccField );
   162         }
   159         }
   163 
   160 
   164     // initially attachments field is hidden
   161     // initially attachments field is hidden
   165     iAttachmentField->MakeVisible( EFalse );
   162 	iAttachmentField->MakeVisible( EFalse );
   166     controls.Remove( iAttachmentField );
   163 	controls.Remove( iAttachmentField );
   167 
   164 
   168     // test whether mailbox supports remote lookup
   165 	// test whether mailbox supports remote lookup
   169     TBool remoteLookupSupported = 
   166 	TBool remoteLookupSupported = 
   170         TFsEmailUiUtility::IsRemoteLookupSupported( iMailBox );
   167         TFsEmailUiUtility::IsRemoteLookupSupported( iMailBox );
   171 
   168 	
   172     iAacListBox = CNcsPopupListBox::NewL( 
   169 	iAacListBox = CNcsPopupListBox::NewL( 
   173         this, iMailBox, *this, remoteLookupSupported );
   170 	        this, iMailBox, *this, remoteLookupSupported );
       
   171 	iAacListBox->MakeVisible( EFalse );
   174 
   172 
   175     iRALInProgress = EFalse;
   173     iRALInProgress = EFalse;
   176 
   174 
   177     iToField->EnableKineticScrollingL( iPhysics );
   175     iToField->EnableKineticScrollingL( iPhysics );
   178     iCcField->EnableKineticScrollingL( iPhysics );
   176     iCcField->EnableKineticScrollingL( iPhysics );
   194 	delete iAacListBox;
   192 	delete iAacListBox;
   195 	delete iLongTapDetector;
   193 	delete iLongTapDetector;
   196 	}
   194 	}
   197 
   195 
   198 // ---------------------------------------------------------------------------
   196 // ---------------------------------------------------------------------------
   199 // From MNcsPopupListBoxObserver.
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 TBool CNcsHeaderContainer::PopupVisibilityChangingL( TBool aVisible )
       
   203     {
       
   204     CNcsComposeViewContainer& parent =
       
   205         static_cast<CNcsComposeViewContainer&>( iParent );
       
   206 
       
   207     if ( aVisible )
       
   208         {
       
   209         DoScrollFocusToTop();
       
   210         iAacListBox->SetPopupMaxRect( CalculatePopupRect() );
       
   211         }
       
   212     else
       
   213         {
       
   214         // Scroll editor top, if it can be fully displayed.
       
   215         if ( parent.ContentTotalHeight() < parent.VisibleAreaHeight() )
       
   216             {
       
   217             parent.Scroll( 0, ETrue );
       
   218             }
       
   219         }
       
   220 
       
   221     parent.UpdateScrollBarVisibility( !aVisible );
       
   222     ShowPopupMenuBarL( aVisible );
       
   223     return ETrue;
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // From MNcsPopupListBoxObserver.
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 void CNcsHeaderContainer::PopupItemSelectedL()
       
   231     {
       
   232     DoPopupSelectL();
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // CNcsHeaderContainer::FocusChanged
   197 // CNcsHeaderContainer::FocusChanged
   237 // ---------------------------------------------------------------------------
   198 // ---------------------------------------------------------------------------
   238 //
   199 //
   239 void CNcsHeaderContainer::FocusChanged( TDrawNow aDrawNow )
   200 void CNcsHeaderContainer::FocusChanged( TDrawNow aDrawNow )
   240     {
   201     {
   277             }
   238             }
   278         iFocused->SetFocus( ETrue, aDrawNow );
   239         iFocused->SetFocus( ETrue, aDrawNow );
   279         }
   240         }
   280     }
   241     }
   281 
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // CNcsHeaderContainer::ShowCursor
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 void CNcsHeaderContainer::ShowCursor( TBool aShow, TDrawNow aDrawNow )
       
   248     {
       
   249     CCoeControl* focused = FindFocused();
       
   250     if ( focused )
       
   251         {
       
   252         iFocused = focused;
       
   253         }
       
   254     if ( iFocused ) 
       
   255         {
       
   256         iFocused->SetFocus( aShow, aDrawNow );
       
   257         }
       
   258     }
       
   259 
   282 // -----------------------------------------------------------------------------
   260 // -----------------------------------------------------------------------------
   283 // CNcsHeaderContainer::Draw() const
   261 // CNcsHeaderContainer::Draw() const
   284 // Draws the display
   262 // Draws the display
   285 // -----------------------------------------------------------------------------
   263 // -----------------------------------------------------------------------------
   286 void CNcsHeaderContainer::Draw( const TRect& /*aRect*/ ) const
   264 void CNcsHeaderContainer::Draw( const TRect& /*aRect*/ ) const
   287 	{
   265 	{
   288     FUNC_LOG;
   266     FUNC_LOG;
   289 	}
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CNcsHeaderContainer::DrawAttachmentFocusNow() const
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CNcsHeaderContainer::DrawAttachmentFocusNow()
       
   296 	{
       
   297     FUNC_LOG;
       
   298     iAttachmentField->DrawDeferred();
       
   299 	}
   267 	}
   300 
   268 
   301 // -----------------------------------------------------------------------------
   269 // -----------------------------------------------------------------------------
   302 // CNcsHeaderContainer::HandleControlArrayEventL()
   270 // CNcsHeaderContainer::HandleControlArrayEventL()
   303 // Handles removal or additons of controls to the header.
   271 // Handles removal or additons of controls to the header.
   369 // -----------------------------------------------------------------------------
   337 // -----------------------------------------------------------------------------
   370 void CNcsHeaderContainer::HandlePointerEventL( 
   338 void CNcsHeaderContainer::HandlePointerEventL( 
   371         const TPointerEvent& aPointerEvent )
   339         const TPointerEvent& aPointerEvent )
   372     {
   340     {
   373     FUNC_LOG;
   341     FUNC_LOG;
   374     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
   342     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
   375         {
   343         {
   376         CCoeControl* component = 0;
   344         CCoeControl* clicked = 0;
   377         for ( TInt i=0; i < Components().Count(); ++i )
   345         for ( TInt i=0; i < Components().Count(); ++i )
   378             {
   346             {
   379             TRect rc = Components().At( i ).iControl->Rect();
   347             TRect rc = Components().At( i ).iControl->Rect();
   380             if ( rc.Contains( aPointerEvent.iPosition ) )
   348             if ( rc.Contains( aPointerEvent.iPosition ) )
   381                 {
   349                 {
   382                 component = Components().At( i ).iControl;
   350                 clicked = Components().At( i ).iControl;
   383                 }
   351                 }
   384             }
   352             }
   385 
   353 
   386         if ( component )
   354         if ( clicked )
   387             {
   355             {
   388             CCoeControl* pOldCtrl = FindFocused();
   356             CCoeControl* pOldCtrl = FindFocused();
   389             CCoeControl* pNewCtrl= component;
   357             CCoeControl* pNewCtrl= clicked;
   390 
   358 
   391             if ( pOldCtrl != pNewCtrl )
   359             if ( pOldCtrl != pNewCtrl )
   392                 {
   360                 {
   393                 // Unfocus the control
   361                 // Unfocus the control
   394                 if ( pOldCtrl )
   362                 if ( pOldCtrl )
   401                 if ( pOldCtrl )
   369                 if ( pOldCtrl )
   402                     {
   370                     {
   403                     CommitFieldL( pOldCtrl );
   371                     CommitFieldL( pOldCtrl );
   404                     }
   372                     }
   405 
   373 
   406                 // If the attachments label has changed focus
       
   407                 if ( pOldCtrl == iAttachmentField || 
       
   408                         pNewCtrl == iAttachmentField )
       
   409                     {
       
   410                     DrawAttachmentFocusNow();
       
   411                     }
       
   412 
       
   413                 CNcsComposeViewContainer* container = 
   374                 CNcsComposeViewContainer* container = 
   414                         static_cast<CNcsComposeViewContainer*>( &iParent );
   375                     static_cast<CNcsComposeViewContainer*>( &iParent );
   415                 container->UpdateScrollBar();
   376                 container->UpdateScrollBar();
   416                 }
   377                 }
   417 
   378 
   418             DrawDeferred();
   379             if ( iLongTapEventConsumed )
   419             }
       
   420         }
       
   421 
       
   422     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   423         {
       
   424         if ( iLongTapEventConsumed )
       
   425             {
       
   426             iLongTapEventConsumed = EFalse;
       
   427             return;
       
   428             }
       
   429 
       
   430         CCoeControl* component = 0;
       
   431         for ( TInt i=0; i < Components().Count(); ++i )
       
   432             {
       
   433             TRect rc = Components().At( i ).iControl->Rect();
       
   434             if ( rc.Contains( aPointerEvent.iPosition ) )
       
   435                 {
   380                 {
   436                 component = Components().At( i ).iControl;
   381                 iLongTapEventConsumed = EFalse;
       
   382                 return;
   437                 }
   383                 }
   438             }
   384 
   439 
       
   440         if ( component && component == iFocused )
       
   441             {
       
   442             TBool physicsActionOngoing( EFalse );
   385             TBool physicsActionOngoing( EFalse );
   443             if ( iPhysics && iPhysics->OngoingPhysicsAction() != CAknPhysics::EAknPhysicsActionNone )
   386             if ( iPhysics && iPhysics->OngoingPhysicsAction() != CAknPhysics::EAknPhysicsActionNone )
   444                 {
   387                 {
   445                 physicsActionOngoing = ETrue;
   388                 physicsActionOngoing = ETrue;
   446                 }
   389             }
   447 
   390 
   448             if ( component == iAttachmentField && !physicsActionOngoing )
   391             if( pNewCtrl == iAttachmentField && !physicsActionOngoing )
   449                 {
   392                 {
   450                 CNcsComposeViewContainer& parent = 
   393                 CNcsComposeViewContainer& parent = 
   451                         static_cast<CNcsComposeViewContainer&>( iParent );
   394                     static_cast<CNcsComposeViewContainer&>( iParent );
   452                 parent.HandleAttachmentsOpenCommandL();
   395                 parent.HandleAttachmentOpenCommandL();
   453                 }
   396                 }
   454             }
   397             }
   455         }
   398         }
   456 
   399 
   457     CCoeControl::HandlePointerEventL( aPointerEvent );
   400     CCoeControl::HandlePointerEventL( aPointerEvent );
   507 TKeyResponse CNcsHeaderContainer::OfferKeyEventL( 
   450 TKeyResponse CNcsHeaderContainer::OfferKeyEventL( 
   508         const TKeyEvent& aKeyEvent, TEventCode aType )
   451         const TKeyEvent& aKeyEvent, TEventCode aType )
   509     {
   452     {
   510     FUNC_LOG;
   453     FUNC_LOG;
   511     TKeyResponse ret( EKeyWasNotConsumed );
   454     TKeyResponse ret( EKeyWasNotConsumed );
   512     
       
   513     TBool doScroll( EFalse );
   455     TBool doScroll( EFalse );
   514 
   456     CCoeControl* focused = FindFocused();
   515     if ( aKeyEvent.iCode == EKeyUpArrow || aKeyEvent.iCode == EKeyDownArrow )
   457 
       
   458     if ( aKeyEvent.iCode == EKeyUpArrow || 
       
   459          aKeyEvent.iCode == EKeyDownArrow )
   516         {
   460         {
   517         if ( iAacListBox && iAacListBox->IsVisible() && 
   461         if ( iAacListBox && iAacListBox->IsVisible() && 
   518              !iAacListBox->IsPopupEmpty() )
   462              !iAacListBox->IsPopupEmpty() )
   519             {
   463             {
   520             return iAacListBox->OfferKeyEventL( aKeyEvent, aType );
   464            	return iAacListBox->OfferKeyEventL( aKeyEvent, aType );
   521             }
   465             }
   522         else
   466         else if ( focused )
   523             {
   467             {
   524             ret = FindFocused()->OfferKeyEventL( aKeyEvent, aType );
   468             ret = focused->OfferKeyEventL( aKeyEvent, aType );
   525             doScroll = ( ret == EKeyWasConsumed ); 
   469             doScroll = ( ret == EKeyWasConsumed ); 
   526             }
   470             }
   527 
   471 
   528         if ( ret == EKeyWasNotConsumed ) 
   472         if ( ret == EKeyWasNotConsumed ) 
   529             {
   473             {
   530             ret = ChangeFocusL( aKeyEvent );
   474             ret = ChangeFocusL( aKeyEvent );
   531             DrawDeferred();
   475             DrawDeferred();
   532             }
   476             }
   533         }
   477         }
   534     else
   478     else
   535     	{
   479         {
   536         if ( FindFocused() == iAttachmentField )
   480         if ( IsPopupActive() && aType == EEventKey )
   537         	{
   481             {
   538         	if ( aType == EEventKey )
   482             // select current
   539         	    {
   483             if( aKeyEvent.iCode == EKeyEnter || 
   540                 CNcsComposeViewContainer& parent = 
   484                 aKeyEvent.iCode == EKeyDevice4 || 
   541                     static_cast<CNcsComposeViewContainer&>( iParent );
   485                 aKeyEvent.iCode == EKeyOK )
   542 
   486                 {
   543                 if ( aKeyEvent.iCode == EKeyEnter || 
   487                 DoPopupSelectL();
   544                      aKeyEvent.iScanCode == EStdKeyEnter ||  
   488                 ret = EKeyWasConsumed;
   545                      aKeyEvent.iCode == EKeyOK || 
   489                 }
   546                      aKeyEvent.iScanCode == EStdKeyDevice3 )
   490             }
   547             	    {   
   491         else
   548             	    // open list or attachment
   492             {
   549             	    parent.HandleAttachmentsOpenCommandL();
   493             // Don't allow line feeds in header fields.
   550             	    ret = EKeyWasConsumed;
   494             // Could be nice if enter committed the field and moved the focus
   551             	    }
   495             // to next one
   552         	    }
   496             if ( aType == EEventKey && 
   553             }
   497                  ( aKeyEvent.iCode == EKeyEnter || 
   554 		else if ( IsPopupActive() && aType == EEventKey )
   498                    aKeyEvent.iScanCode == EStdKeyEnter) )
   555 			{
   499                 {
   556 			// select current
   500                 focused->OfferKeyEventL( aKeyEvent, aType );
   557 			if( aKeyEvent.iCode == EKeyEnter || 
   501                 ret = EKeyWasConsumed;
   558 			    aKeyEvent.iCode == EKeyDevice4 || 
   502                 }
   559 				aKeyEvent.iCode == EKeyOK )
   503             }
   560 				{
   504         }
   561 				DoPopupSelectL();
       
   562 				ret = EKeyWasConsumed;
       
   563 				}
       
   564 			}
       
   565 		else
       
   566 		    {
       
   567 		    // Don't allow line feeds in header fields.
       
   568 		    // Could be nice if enter committed the field and moved the focus
       
   569 		    // to next one
       
   570 		    if ( aType == EEventKey && 
       
   571 		         ( aKeyEvent.iCode == EKeyEnter || 
       
   572 		           aKeyEvent.iScanCode == EStdKeyEnter) )
       
   573 		        {
       
   574 		        FindFocused()->OfferKeyEventL( aKeyEvent, aType );
       
   575 		        ret = EKeyWasConsumed;
       
   576 		        doScroll = ETrue;
       
   577 		        }
       
   578 		    }
       
   579     	}
       
   580     if ( ret == EKeyWasNotConsumed )
   505     if ( ret == EKeyWasNotConsumed )
   581     	{
   506         {
   582     	CCoeControl* focused = FindFocused();
   507         if ( focused )
   583     	if ( focused )
   508             {
   584     		{
   509             ret = focused->OfferKeyEventL( aKeyEvent, aType );
   585     		ret = focused->OfferKeyEventL( aKeyEvent, aType );
   510 
   586     		
   511             if(aType==EEventKeyDown)
   587     		if( aType == EEventKeyDown &&
   512                 {
   588     		    aKeyEvent.iScanCode != EStdKeyUpArrow &&
   513                 doScroll = ETrue; 
   589     		    aKeyEvent.iScanCode != EStdKeyDownArrow )
   514                 }
   590     		    {
   515             else 
   591     		    doScroll = ETrue; 
   516                 {
   592     		    }
   517                 doScroll = (ret == EKeyWasConsumed); 
   593     		else 
   518                 }
   594     		    {
   519             }
   595     		    doScroll = (ret == EKeyWasConsumed); 
   520         }
   596     		    }
   521 
   597     		}
   522     if ( doScroll )
   598     	}
   523         {
   599 
   524         DoScroll();
   600     if( doScroll )
   525         }
   601     	{
       
   602     	DoScroll();
       
   603     	}
       
   604 
   526 
   605     return ret;
   527     return ret;
   606 	}
   528     }
   607 
   529 
   608 // ---------------------------------------------------------------------------
   530 // ---------------------------------------------------------------------------
   609 // CNcsHeaderContainer::FindFocused
   531 // CNcsHeaderContainer::FindFocused
   610 // ---------------------------------------------------------------------------
   532 // ---------------------------------------------------------------------------
   611 //
   533 //
   648         }
   570         }
   649 
   571 
   650     // Unfocus the control
   572     // Unfocus the control
   651     pOldCtrl->SetFocus( EFalse, ENoDrawNow );
   573     pOldCtrl->SetFocus( EFalse, ENoDrawNow );
   652 
   574 
   653     CCoeControl* pNewCtrl= NULL;
   575     CCoeControl* pNewCtrl = NULL;
   654     if ( ( aKeyEvent.iCode == EKeyDownArrow && cur.Next() ) ||
   576     if ( aKeyEvent.iCode == EKeyDownArrow && cur.Next() ) 
   655          ( aKeyEvent.iCode == EKeyUpArrow && cur.Prev() ) )
       
   656         {
   577         {
   657         pNewCtrl = cur.Control<CCoeControl>();
   578         pNewCtrl = cur.Control<CCoeControl>();
       
   579         if ( pNewCtrl == iAttachmentField )
       
   580             {
       
   581             iAttachmentField->SetFocusedAttachmentLabelIndex( 0 );
       
   582             }
       
   583         pNewCtrl->SetFocus( ETrue, ENoDrawNow );
   658         iFocused = pNewCtrl;
   584         iFocused = pNewCtrl;
       
   585         ret = EKeyWasConsumed;
       
   586         }
       
   587     else if ( aKeyEvent.iCode == EKeyUpArrow && cur.Prev() )
       
   588         {
       
   589         pNewCtrl = cur.Control<CCoeControl>();
   659         pNewCtrl->SetFocus( ETrue, ENoDrawNow );
   590         pNewCtrl->SetFocus( ETrue, ENoDrawNow );
       
   591         iFocused = pNewCtrl;
   660         ret = EKeyWasConsumed;
   592         ret = EKeyWasConsumed;
   661         }
   593         }
   662 
   594 
   663     CNcsComposeViewContainer* container = 
   595     CNcsComposeViewContainer* container = 
   664             static_cast<CNcsComposeViewContainer*>( &iParent );
   596         static_cast<CNcsComposeViewContainer*>( &iParent );
   665     if ( pOldCtrl == iToField )
   597     if ( pOldCtrl == iToField )
   666         {
   598         {
   667         container->CommitL( EToField );
   599         container->CommitL( EToField );
   668         }
   600         }
   669     else if ( pOldCtrl == iCcField) 
   601     else if ( pOldCtrl == iCcField) 
   675         container->CommitL( EBccField );
   607         container->CommitL( EBccField );
   676         }
   608         }
   677     else if ( pOldCtrl == iSubjectField)
   609     else if ( pOldCtrl == iSubjectField)
   678         {
   610         {
   679         container->CommitL( ESubjectField );
   611         container->CommitL( ESubjectField );
   680         }
       
   681 
       
   682     // If the attachments label has changed focus
       
   683     if ( pOldCtrl == iAttachmentField || pNewCtrl == iAttachmentField )
       
   684         {
       
   685         DrawAttachmentFocusNow();
       
   686         }
   612         }
   687 
   613 
   688     // if focus was changed, update scroll bar
   614     // if focus was changed, update scroll bar
   689     if ( ret == EKeyWasConsumed )
   615     if ( ret == EKeyWasConsumed )
   690         {
   616         {
   754 // -----------------------------------------------------------------------------
   680 // -----------------------------------------------------------------------------
   755 // CNcsHeaderContainer::SizeChanged()
   681 // CNcsHeaderContainer::SizeChanged()
   756 // set size
   682 // set size
   757 // -----------------------------------------------------------------------------
   683 // -----------------------------------------------------------------------------
   758 void CNcsHeaderContainer::SizeChanged()
   684 void CNcsHeaderContainer::SizeChanged()
   759     {
   685 	{
   760     FUNC_LOG;
   686     FUNC_LOG;
       
   687 
   761     const TRect rect( Rect() );
   688     const TRect rect( Rect() );
   762 
   689 
   763     TInt currentLine( 0 );
   690     TInt currentLine( 0 );
   764     CCoeControlArray::TCursor cur = Components().Begin();
   691     CCoeControlArray::TCursor cur = Components().Begin();
   765     do
   692     do
   773             // during layout (e.g. when orientation is changed => edit field
   700             // during layout (e.g. when orientation is changed => edit field
   774             // length may change => it grows or shrinks)
   701             // length may change => it grows or shrinks)
   775             currentLine += ToNcsControl( cur )->LayoutLineCount();
   702             currentLine += ToNcsControl( cur )->LayoutLineCount();
   776             }
   703             }
   777         } while ( cur.Next() );
   704         } while ( cur.Next() );
   778 
   705         
   779     if ( iAacListBox->IsVisible() && !iAacListBox->IsPopupEmpty() )
   706 	if( iAacListBox->IsVisible() && !iAacListBox->IsPopupEmpty() )
   780         {
   707 		{
   781         iAacListBox->SetPopupMaxRect( CalculatePopupRect() );
   708 		iAacListBox->SetPopupMaxRect( CalculatePopupRect() );
   782         }
   709 		}
   783 	}
   710 	}
   784 
   711 
   785 // -----------------------------------------------------------------------------
   712 // -----------------------------------------------------------------------------
   786 // CNcsHeaderContainer::PositionChanged()
   713 // CNcsHeaderContainer::PositionChanged()
   787 // set size
   714 // set size
   839 // ---------------------------------------------------------------------------
   766 // ---------------------------------------------------------------------------
   840 // CNcsHeaderContainer::GetToLineHeight
   767 // CNcsHeaderContainer::GetToLineHeight
   841 // ---------------------------------------------------------------------------
   768 // ---------------------------------------------------------------------------
   842 //
   769 //
   843 TInt CNcsHeaderContainer::GetToLineHeight() const
   770 TInt CNcsHeaderContainer::GetToLineHeight() const
   844     {
   771 	{
   845     FUNC_LOG;
   772 	FUNC_LOG;
   846     TInt lineHeight = 0;
   773 	TInt lineHeight = 0;
   847 
   774 	
   848     if ( iToField )
   775 	if(iToField)
   849         {
   776 		{
   850         TRect lineRect;
   777 	    TRect lineRect;
   851         iToField->GetLineRect( lineRect );
   778 	    TRAPD(err, iToField->GetLineRectL(lineRect) );
   852         lineHeight = lineRect.Height();
   779 	   	if(err == KErrNone)
   853         }
   780 	        {
   854     return lineHeight;
   781 	        lineHeight = lineRect.iBr.iY - lineRect.iTl.iY;
   855     }
   782 	        }
   856 
   783 		}
       
   784 	return lineHeight;
       
   785 	}
       
   786       
   857 // ---------------------------------------------------------------------------
   787 // ---------------------------------------------------------------------------
   858 // CNcsHeaderContainer::GetTotalHeight
   788 // CNcsHeaderContainer::GetTotalHeight
   859 // ---------------------------------------------------------------------------
   789 // ---------------------------------------------------------------------------
   860 //
   790 //
   861 TInt CNcsHeaderContainer::GetTotalHeight() const
   791 TInt CNcsHeaderContainer::GetTotalHeight() const
   883     FUNC_LOG;   
   813     FUNC_LOG;   
   884     iAttachmentField->SetTextsLD( aAttachmentNames, aAttachmentSizes );
   814     iAttachmentField->SetTextsLD( aAttachmentNames, aAttachmentSizes );
   885     if( aAttachmentNames )
   815     if( aAttachmentNames )
   886         {
   816         {
   887         ShowAttachmentLabelL();
   817         ShowAttachmentLabelL();
   888         DrawAttachmentFocusNow();
       
   889         }
   818         }
   890     }
   819     }
   891 
   820 
   892 // -----------------------------------------------------------------------------
   821 // -----------------------------------------------------------------------------
   893 // CNcsHeaderContainer::FocusedAttachmentLabelIndex
   822 // CNcsHeaderContainer::FocusedAttachmentLabelIndex
   894 //
   823 //
   895 // -----------------------------------------------------------------------------
   824 // -----------------------------------------------------------------------------
   896 //
   825 //
   897 TInt CNcsHeaderContainer::FocusedAttachmentLabelIndex()
   826 TInt CNcsHeaderContainer::FocusedAttachmentLabelIndex() const
   898     {
   827     {
   899     FUNC_LOG;
   828     FUNC_LOG;
   900     return iAttachmentField->FocusedAttachmentLabelIndex();
   829     return iAttachmentField->FocusedAttachmentLabelIndex();
   901     }
   830     }
   902 
   831 
   919         if ( pOldCtrl )
   848         if ( pOldCtrl )
   920             {
   849             {
   921             pOldCtrl->SetFocus( EFalse, ENoDrawNow );
   850             pOldCtrl->SetFocus( EFalse, ENoDrawNow );
   922             }
   851             }
   923 
   852 
   924         iFocused = iAttachmentField;
       
   925         iAttachmentField->SetFocus( ETrue, ENoDrawNow );
   853         iAttachmentField->SetFocus( ETrue, ENoDrawNow );
   926         iFieldSizeObserver.UpdateFieldPosition( iAttachmentField );
   854         iFieldSizeObserver.UpdateFieldPosition( iAttachmentField );
   927         }
   855         }
   928     }
   856     }
   929 
   857 
   937     // check if we are focused and in that case
   865     // check if we are focused and in that case
   938     // unfocus attachment filed and focus previous control
   866     // unfocus attachment filed and focus previous control
   939     CCoeControl* pOldCtrl = FindFocused();
   867     CCoeControl* pOldCtrl = FindFocused();
   940     CCoeControl* pNewCtrl = NULL;
   868     CCoeControl* pNewCtrl = NULL;
   941 
   869 
       
   870     if ( iFocused == iAttachmentField )
       
   871         {
       
   872         iFocused = NULL;
       
   873         }
       
   874 
   942     if ( pOldCtrl == iAttachmentField )
   875     if ( pOldCtrl == iAttachmentField )
   943         {
   876         {
   944         CCoeControlArray::TCursor cur = Components().Find( pOldCtrl );
   877         CCoeControlArray::TCursor cur = Components().Find( pOldCtrl );
   945         pOldCtrl->SetFocus( EFalse, ENoDrawNow );
   878         pOldCtrl->SetFocus( EFalse, ENoDrawNow );
   946 
   879 
   947         if ( cur.Prev() )
   880         if ( cur.Prev() )
   948             {
   881             {
   949             pNewCtrl = cur.Control<CCoeControl>();
   882             pNewCtrl = cur.Control<CCoeControl>();
   950             iFocused = pNewCtrl;
       
   951             pNewCtrl->SetFocus( ETrue, ENoDrawNow );
   883             pNewCtrl->SetFocus( ETrue, ENoDrawNow );
   952             }
   884             }
   953         }
   885         }
   954     else
   886     else
   955         {
   887         {
   956         pNewCtrl = pOldCtrl; // no need to move focus
   888         pNewCtrl = pOldCtrl; // no need to move focus
   957         }
       
   958 
       
   959     if ( pOldCtrl == iAttachmentField || pNewCtrl == iAttachmentField )
       
   960         {
       
   961         DrawAttachmentFocusNow();
       
   962         }
   889         }
   963 
   890 
   964     iAttachmentField->MakeVisible( EFalse );
   891     iAttachmentField->MakeVisible( EFalse );
   965     Components().Remove( iAttachmentField );
   892     Components().Remove( iAttachmentField );
   966     TRAP_IGNORE( iFieldSizeObserver.UpdateFieldSizeL() );
   893     TRAP_IGNORE( iFieldSizeObserver.UpdateFieldSizeL() );
   979 //
   906 //
   980 void CNcsHeaderContainer::SetBccFieldVisibleL( 
   907 void CNcsHeaderContainer::SetBccFieldVisibleL( 
   981         TBool aVisible, TDrawNow aDrawNow, TBool aFocus ) 
   908         TBool aVisible, TDrawNow aDrawNow, TBool aFocus ) 
   982     {
   909     {
   983     FUNC_LOG;
   910     FUNC_LOG;
   984     if ( iBccField->IsVisible() == aVisible )
   911 	if ( iBccField->IsVisible() == aVisible )
   985         {
   912 		{
   986         return;
   913 		return;
   987         }
   914 		}
   988 
   915 
   989     if ( aVisible )
   916 	if ( aVisible )
   990         {
   917 		{
   991         CCoeControlArray::TCursor cur = Components().Find( iSubjectField );
   918 		CCoeControlArray::TCursor cur = Components().Find( iSubjectField );
   992         Components().InsertLC( cur, iBccField );
   919 		Components().InsertLC( cur, iBccField );
   993         CleanupStack::Pop( iBccField );
   920 		CleanupStack::Pop( iBccField );
   994 
   921 
   995         if ( aFocus )
   922 		if ( aFocus )
   996             {
   923 			{
   997             CCoeControl* focused = FindFocused();
   924 			CCoeControl* focused = FindFocused();
   998 
   925 
   999             if ( focused )
   926 			if ( focused )
  1000                 {
   927 				{
  1001                 focused->SetFocus( EFalse, aDrawNow );
   928 				focused->SetFocus( EFalse );
  1002                 }
   929 				}
  1003             iBccField->SetFocus( ETrue, aDrawNow );
   930 			iBccField->SetFocus( ETrue );
  1004             iFocused = iBccField;
   931             iFocused = iBccField;
  1005             iBccField->SelectAllTextL();
   932 			iBccField->SelectAllTextL();
  1006             }
   933 			}
  1007         }
   934 		}
  1008     else
   935 	else
  1009         {
   936 		{
  1010         if ( iBccField->IsFocused() )
   937 		if ( iBccField->IsFocused() )
  1011             {
   938 			{
  1012             CCoeControlArray::TCursor cur = Components().Find( iBccField );
   939 			CCoeControlArray::TCursor cur = Components().Find( iBccField );
  1013             ASSERT( cur.IsValid() );
   940 			ASSERT( cur.IsValid() );
  1014 
   941 			
  1015             iBccField->SetFocus( EFalse );
   942 			iBccField->SetFocus( EFalse );
  1016 
   943 
  1017             cur.Prev(); // Get the control before this field
   944 			cur.Prev(); // Get the control before this field
  1018             CCoeControl* focused = cur.Control<CCoeControl>();
   945 			cur.Control<CCoeControl>()->SetFocus( ETrue );
  1019             focused->SetFocus( ETrue );
   946 			}
  1020             iFocused = focused;
   947 		Components().Remove( iBccField );
  1021             }
   948         iFocused = iSubjectField;
  1022         Components().Remove( iBccField );
   949 		}
  1023         }
       
  1024 
   950 
  1025     TRAP_IGNORE( iFieldSizeObserver.UpdateFieldSizeL() );
   951     TRAP_IGNORE( iFieldSizeObserver.UpdateFieldSizeL() );
  1026 
   952 
  1027     if ( aDrawNow == EDrawNow )
   953 	if ( aDrawNow == EDrawNow )
  1028         {
   954 		{
  1029         DrawDeferred();
   955 	    DrawDeferred();
  1030         }
   956 		}
  1031     }
   957 	}
  1032 
   958 
  1033 // -----------------------------------------------------------------------------
   959 // -----------------------------------------------------------------------------
  1034 // CNcsHeaderContainer::SetCcFieldVisibleL()
   960 // CNcsHeaderContainer::SetCcFieldVisibleL()
  1035 // -----------------------------------------------------------------------------
   961 // -----------------------------------------------------------------------------
  1036 void CNcsHeaderContainer::SetCcFieldVisibleL( 
   962 void CNcsHeaderContainer::SetCcFieldVisibleL( 
  1037         TBool aVisible, TDrawNow aDrawNow, TBool aFocus ) 
   963         TBool aVisible, TDrawNow aDrawNow, TBool aFocus ) 
  1038     {
   964 	{
  1039     FUNC_LOG;
   965     FUNC_LOG;
  1040     if ( iCcField->IsVisible() == aVisible )
   966 	if ( iCcField->IsVisible() == aVisible )
  1041         {
   967 		{
  1042         return;
   968 		return;
  1043         }
   969 		}
  1044 
   970 
  1045     if ( aVisible )
   971 	if ( aVisible )
  1046         {
   972 		{
  1047         Components().InsertAfterLC( Components().Id( *iToField ), iCcField );
   973 		Components().InsertAfterLC( Components().Id( *iToField ), iCcField );
  1048         CleanupStack::Pop( iCcField );
   974 		CleanupStack::Pop( iCcField );
  1049 
   975 
  1050         if ( aFocus )
   976 		if ( aFocus )
  1051             {
   977 			{
  1052             CCoeControl* focused = FindFocused();
   978 			CCoeControl* focused = FindFocused();
  1053             if ( focused )
   979 			if ( focused )
  1054                 {
   980 				{
  1055                 focused->SetFocus( EFalse, aDrawNow );
   981 				focused->SetFocus( EFalse );
  1056                 }
   982 				}
  1057             iCcField->SetFocus( ETrue, aDrawNow );
   983 			iCcField->SetFocus( ETrue );
  1058             iFocused = iCcField;
   984             iFocused = iCcField;
  1059             iCcField->SelectAllTextL();
   985 			iCcField->SelectAllTextL();
  1060             }
   986 			}
  1061         }
   987 		}
  1062     else
   988 	else
  1063         {
   989 		{
  1064         if( iCcField->IsFocused() )
   990 		if( iCcField->IsFocused() )
  1065             {
   991 			{
  1066             iCcField->SetFocus( EFalse );
   992 			iCcField->SetFocus( EFalse );
  1067             iToField->SetFocus( ETrue );
   993 			iToField->SetFocus( ETrue );
  1068             iFocused = iToField;
   994 			}
  1069             }
   995 		Components().Remove( iCcField );
  1070         Components().Remove( iCcField );
   996         iFocused = iToField;
  1071         }
   997 		}
  1072 
   998     
  1073     TRAP_IGNORE( iFieldSizeObserver.UpdateFieldSizeL() );
   999 	TRAP_IGNORE( iFieldSizeObserver.UpdateFieldSizeL() );
  1074 
  1000 
  1075     if ( aDrawNow == EDrawNow )
  1001     if ( aDrawNow == EDrawNow )
  1076         {
  1002 		{
  1077         DrawDeferred();
  1003 	    DrawDeferred();
  1078         }
  1004 		}
  1079     }
  1005     }
  1080 
  1006 
  1081 // -----------------------------------------------------------------------------
  1007 // -----------------------------------------------------------------------------
  1082 // CNcsHeaderContainer::MopSupplyObject
  1008 // CNcsHeaderContainer::MopSupplyObject
  1083 // From CCoeControl.
  1009 // From CCoeControl.
  1196 // CNcsHeaderContainer::UpdatePopupContactListL()
  1122 // CNcsHeaderContainer::UpdatePopupContactListL()
  1197 // -----------------------------------------------------------------------------
  1123 // -----------------------------------------------------------------------------
  1198 //
  1124 //
  1199 void CNcsHeaderContainer::UpdatePopupContactListL( 
  1125 void CNcsHeaderContainer::UpdatePopupContactListL( 
  1200         const TDesC& aMatchString, TBool /*aListAll*/ )
  1126         const TDesC& aMatchString, TBool /*aListAll*/ )
  1201     {
  1127 	{
  1202     FUNC_LOG;
  1128     FUNC_LOG;
  1203 
  1129 
  1204     // do update only for address fields
  1130     // do update only for address fields
  1205     CCoeControl* focused = FindFocused();
  1131 	CCoeControl* focused = FindFocused();
  1206 
  1132 	
  1207     if ( !IsAddressInputField( focused ) )
  1133 	if ( !IsAddressInputField( focused ) )
  1208         {
  1134 	    {
  1209         return;
  1135 	    return;
  1210         }
  1136 	    }
  1211 
  1137 	    
  1212     if ( aMatchString.CompareC( KNullDesC ) == 0 || 
  1138 	if ( aMatchString.CompareC( KNullDesC ) == 0 || 
  1213             aMatchString.Compare( KAddressDelimeterSemiColon ) == 0 )
  1139 	     aMatchString.Compare( KAddressDelimeterSemiColon ) == 0 )
  1214         {
  1140 		{
  1215         ClosePopupContactListL();
  1141 		ClosePopupContactListL();
  1216         return;
  1142 		return;
  1217         }
  1143 		}
  1218 
  1144 	
  1219     if( !iAacListBox->IsVisible() )
  1145 	if( !iAacListBox->IsVisible() )
  1220         {
  1146 		{
  1221         iAacListBox->SetPopupMaxRect( CalculatePopupRect() );
  1147         iAacListBox->SetPopupMaxRect( CalculatePopupRect() );
  1222         iAacListBox->InitAndSearchL( aMatchString, 1 );
  1148         iAacListBox->InitAndSearchL( aMatchString, 1 );
  1223         iAacListBox->ActivateL();
  1149         iAacListBox->ActivateL();
  1224         }
  1150 		}
  1225     else
  1151 	else
  1226         {
  1152 		{
  1227         iAacListBox->SetSearchTextL( aMatchString );
  1153 		iAacListBox->SetSearchTextL( aMatchString );
  1228         }
  1154 		}
  1229     }
  1155 	}
  1230 
  1156 
  1231 // -----------------------------------------------------------------------------
  1157 // -----------------------------------------------------------------------------
  1232 // CNcsHeaderContainer::ClosePopupContactListL()
  1158 // CNcsHeaderContainer::ClosePopupContactListL()
  1233 // -----------------------------------------------------------------------------
  1159 // -----------------------------------------------------------------------------
  1234 //
  1160 //
  1235 void CNcsHeaderContainer::ClosePopupContactListL()
  1161 void CNcsHeaderContainer::ClosePopupContactListL()
  1236     {
  1162 	{
  1237     FUNC_LOG;
  1163     FUNC_LOG;
       
  1164 
  1238     if ( iAacListBox->IsVisible() )
  1165     if ( iAacListBox->IsVisible() )
  1239         {
  1166         {
  1240         iAacListBox->ClosePopupL();
  1167         iAacListBox->MakeVisible( EFalse );
  1241         }
  1168         ShowPopupMenuBarL( EFalse );
  1242 
  1169         
  1243     // The focused address field should be redrawn after the popup is
  1170         // The focused address field should be redrawn after the popup is
  1244     // closed to fix the field border.
  1171         // closed to fix the field border.
  1245     if ( iToField->IsFocused() )
  1172         if ( iToField->IsFocused() )
  1246         {
  1173             {
  1247         iToField->DrawDeferred();
  1174             iToField->DrawDeferred();
  1248         }
  1175             }
  1249     else if ( iCcField->IsFocused() )
  1176         else if ( iCcField->IsFocused() )
  1250         {
  1177             {
  1251         iCcField->DrawDeferred();
  1178             iCcField->DrawDeferred();
  1252         }
  1179             }
  1253     else if ( iBccField->IsFocused() )
  1180         else if ( iBccField->IsFocused() )
  1254         {
  1181             {
  1255         iBccField->DrawDeferred();
  1182             iBccField->DrawDeferred();
  1256         }
  1183             }
  1257     }
  1184         }
       
  1185 	}
  1258 
  1186 
  1259 // ---------------------------------------------------------------------------
  1187 // ---------------------------------------------------------------------------
  1260 // CNcsHeaderContainer::ShowPopupMenuBarL
  1188 // CNcsHeaderContainer::ShowPopupMenuBarL
  1261 // ---------------------------------------------------------------------------
  1189 // ---------------------------------------------------------------------------
  1262 //
  1190 //
  1340 	{
  1268 	{
  1341     FUNC_LOG;
  1269     FUNC_LOG;
  1342 	iSubjectField->SelectAllTextL();
  1270 	iSubjectField->SelectAllTextL();
  1343 	}
  1271 	}
  1344 
  1272 
  1345 // ---------------------------------------------------------------------------
  1273 // -----------------------------------------------------------------------------
  1346 // CNcsHeaderContainer::CalculatePopupRect
  1274 // CNcsHeaderContainer::CalculatePopupRect
  1347 // ---------------------------------------------------------------------------
  1275 // -----------------------------------------------------------------------------
  1348 //
       
  1349 TRect CNcsHeaderContainer::CalculatePopupRect()
  1276 TRect CNcsHeaderContainer::CalculatePopupRect()
  1350     {
  1277     {
  1351     FUNC_LOG;
  1278     FUNC_LOG;
  1352     // get focused control rect
  1279     // get focused control rect
  1353     TRect popupRect;
  1280     TRect popupRect;
  1359             static_cast<CNcsAddressInputField*>( focused );
  1286             static_cast<CNcsAddressInputField*>( focused );
  1360 
  1287 
  1361         TPoint editorPos = aifEditor->Editor()->PositionRelativeToScreen();
  1288         TPoint editorPos = aifEditor->Editor()->PositionRelativeToScreen();
  1362         TRect editorRect = aifEditor->Editor()->Rect();
  1289         TRect editorRect = aifEditor->Editor()->Rect();
  1363 
  1290 
  1364         // When layouts are available we'll use them. Until that these are now
  1291         popupRect.iTl = TPoint( editorPos.iX, 
  1365         // hardcoded!
  1292             editorPos.iY + aifEditor->CursorPosition() + 1 );
  1366         TInt tlXPos = 3;
  1293 
  1367         TInt tlYPos = editorPos.iY + aifEditor->CursorPosition() + 1;
  1294         popupRect.iBr = TPoint( editorPos.iX + editorRect.Width(),
  1368         
       
  1369         if ( Layout_Meta_Data::IsLandscapeOrientation() &&
       
  1370              iSplitScreenVKBEnabled )
       
  1371             {
       
  1372             tlXPos = iAvkonAppUi->ApplicationRect().Width() / 2;
       
  1373             tlYPos = 3;
       
  1374             }
       
  1375         
       
  1376         popupRect.iTl = TPoint( tlXPos, tlYPos );
       
  1377 
       
  1378         
       
  1379         popupRect.iBr = TPoint( iAvkonAppUi->ApplicationRect().iBr.iX  - 3,
       
  1380             iParent.PositionRelativeToScreen().iY + iParent.Rect().Height() );
  1295             iParent.PositionRelativeToScreen().iY + iParent.Rect().Height() );
  1381         }
  1296         }
  1382 
  1297 
  1383     return popupRect;
  1298     return popupRect;
  1384     }
  1299     }
  1390 	{
  1305 	{
  1391     FUNC_LOG;
  1306     FUNC_LOG;
  1392     __ASSERT_DEBUG( iAacListBox, Panic( ENcsBasicUi ) );
  1307     __ASSERT_DEBUG( iAacListBox, Panic( ENcsBasicUi ) );
  1393     __ASSERT_DEBUG( &iMailBox, Panic( ENcsBasicUi ) );
  1308     __ASSERT_DEBUG( &iMailBox, Panic( ENcsBasicUi ) );
  1394 
  1309 
  1395 	if ( iAacListBox->IsRemoteLookupItemSelected() )
  1310 	if( iAacListBox->IsRemoteLookupItemSelected() )
  1396 		{
  1311 		{
  1397 		CCoeControl* focused = FindFocused();
  1312 		CCoeControl* focused = FindFocused();
  1398 		
  1313 		
  1399 		if ( IsAddressInputField( focused ) )
  1314 		if ( IsAddressInputField( focused ) )
  1400 		    {
  1315 		    {
  1825 //
  1740 //
  1826 void CNcsHeaderContainer::IncludeAddressL(const CNcsEmailAddressObject& aEml )
  1741 void CNcsHeaderContainer::IncludeAddressL(const CNcsEmailAddressObject& aEml )
  1827     {
  1742     {
  1828     FUNC_LOG;
  1743     FUNC_LOG;
  1829 
  1744 
  1830 	CCoeControl* focused = FindFocused();
  1745     CCoeControl* focused = FindFocused();
  1831 	if ( IsAddressInputField( focused ) )
  1746     if ( IsAddressInputField( focused ) )
  1832 	    {
  1747         {
  1833     	CNcsAddressInputField* aifFocused = NULL;
  1748         CNcsAddressInputField* aifFocused = NULL;
  1834     	aifFocused = static_cast<CNcsAddressInputField*>( focused );
  1749         aifFocused = static_cast<CNcsAddressInputField*>( focused );
  1835     	aifFocused->AddAddressL( aEml );
  1750         aifFocused->AddAddressL( aEml );
  1836 	    }
  1751         }
  1837     DoScroll();
  1752     DoScroll();
  1838     }
  1753     }
  1839 
  1754 
  1840 // ---------------------------------------------------------------------------
  1755 // ---------------------------------------------------------------------------
  1841 // CNcsHeaderContainer::IncludeAddressL
  1756 // CNcsHeaderContainer::IncludeAddressL
  1849 // ---------------------------------------------------------------------------
  1764 // ---------------------------------------------------------------------------
  1850 // CNcsHeaderContainer::FocusToField
  1765 // CNcsHeaderContainer::FocusToField
  1851 // ---------------------------------------------------------------------------
  1766 // ---------------------------------------------------------------------------
  1852 //
  1767 //
  1853 void CNcsHeaderContainer::FocusToField()
  1768 void CNcsHeaderContainer::FocusToField()
  1854 	{
  1769     {
  1855     FUNC_LOG;
  1770     FUNC_LOG;
  1856     CCoeControl* oldCtrl = FindFocused();
  1771     CCoeControl* oldCtrl = FindFocused();
  1857     if ( !oldCtrl )
  1772     if ( oldCtrl )
  1858     	{
  1773         {
  1859     	return;
  1774         oldCtrl->SetFocus( EFalse, ENoDrawNow );
  1860     	}
  1775         }
  1861 	oldCtrl->SetFocus( EFalse, ENoDrawNow );
  1776 
  1862 	iToField->SetFocus( ETrue, ENoDrawNow );
  1777     iToField->SetFocus( ETrue, ENoDrawNow );
  1863 	}
  1778     iFocused = iToField;
       
  1779     }
  1864 
  1780 
  1865 // ---------------------------------------------------------------------------
  1781 // ---------------------------------------------------------------------------
  1866 // CNcsHeaderContainer::FocusAttachmentField
  1782 // CNcsHeaderContainer::FocusAttachmentField
  1867 // ---------------------------------------------------------------------------
  1783 // ---------------------------------------------------------------------------
  1868 //
  1784 //
  1869 void CNcsHeaderContainer::FocusAttachmentField()
  1785 void CNcsHeaderContainer::FocusAttachmentField()
  1870 	{
  1786     {
  1871     FUNC_LOG;
  1787     FUNC_LOG;
  1872     CCoeControl* oldCtrl = FindFocused();
  1788     CCoeControl* oldCtrl = FindFocused();
  1873     if ( !oldCtrl )
  1789     if ( oldCtrl )
  1874     	{
  1790         {
  1875     	return;
  1791         oldCtrl->SetFocus( EFalse, ENoDrawNow );
  1876     	}
  1792         }
  1877 	oldCtrl->SetFocus( EFalse, ENoDrawNow );
  1793 
  1878 	iAttachmentField->SetFocus( ETrue, ENoDrawNow );
  1794     iAttachmentField->SetFocus( ETrue, ENoDrawNow );
  1879 	}
  1795     iFocused = iAttachmentField;
       
  1796     }
       
  1797 
       
  1798 // ---------------------------------------------------------------------------
       
  1799 // Sets focus to the first visible header field from the bottom.
       
  1800 // ---------------------------------------------------------------------------
       
  1801 //
       
  1802 void CNcsHeaderContainer::SetFocusToBottom( TDrawNow aDrawNow )
       
  1803     {
       
  1804     FUNC_LOG;
       
  1805     CCoeControl* oldCtrl = FindFocused();
       
  1806     if ( oldCtrl )
       
  1807         {
       
  1808         oldCtrl->SetFocus( EFalse, aDrawNow );
       
  1809         }
       
  1810 
       
  1811     CCoeControlArray::TCursor cur = Components().End();
       
  1812     cur.Prev();
       
  1813     CCoeControl* newControl = cur.Control<CCoeControl>();
       
  1814     if ( newControl && newControl == iAttachmentField )
       
  1815         {
       
  1816         // set focus to the last attachment
       
  1817         TInt count = GetAttachmentCount();
       
  1818         iAttachmentField->SetFocusedAttachmentLabelIndex( count - 1 );
       
  1819         }
       
  1820     SetFocus( ETrue, aDrawNow );
       
  1821     }
  1880 
  1822 
  1881 // ---------------------------------------------------------------------------
  1823 // ---------------------------------------------------------------------------
  1882 // CNcsHeaderContainer::AreAddressFieldsEmpty
  1824 // CNcsHeaderContainer::AreAddressFieldsEmpty
  1883 // ---------------------------------------------------------------------------
  1825 // ---------------------------------------------------------------------------
  1884 //
  1826 //
  1920     FUNC_LOG;
  1862     FUNC_LOG;
  1921     TInt totalLineCount( 0 );
  1863     TInt totalLineCount( 0 );
  1922     CCoeControlArray::TCursor cur = Components().Begin();
  1864     CCoeControlArray::TCursor cur = Components().Begin();
  1923     do
  1865     do
  1924         {
  1866         {
  1925         totalLineCount += ToNcsControl( cur )->LayoutLineCount();
  1867         totalLineCount += ToNcsControl( cur )->LayoutLineCount();                       
  1926         } 
  1868         } 
  1927     while ( cur.Next() );
  1869     while ( cur.Next() );
  1928     
  1870     
  1929     return totalLineCount;
  1871     return totalLineCount;
  1930     }
  1872     }
  1931 
  1873 
       
  1874 
  1932 // ---------------------------------------------------------------------------
  1875 // ---------------------------------------------------------------------------
  1933 // CNcsHeaderContainer::IsAddressInputField
  1876 // CNcsHeaderContainer::IsAddressInputField
  1934 // ---------------------------------------------------------------------------
  1877 // ---------------------------------------------------------------------------
  1935 //
  1878 //
  1936 TBool CNcsHeaderContainer::IsAddressInputField(
  1879 TBool CNcsHeaderContainer::IsAddressInputField(
  2030         static_cast<CNcsComposeViewContainer*>( &iParent );
  1973         static_cast<CNcsComposeViewContainer*>( &iParent );
  2031     container->AppendAddressesL();
  1974     container->AppendAddressesL();
  2032     }
  1975     }
  2033 
  1976 
  2034 void CNcsHeaderContainer::FixSemicolonInAddressFieldsL()
  1977 void CNcsHeaderContainer::FixSemicolonInAddressFieldsL()
  2035     {
  1978 	{
  2036     iToField->FixSemicolonAtTheEndL();
  1979 		iToField->FixSemicolonAtTheEndL();
  2037     iCcField->FixSemicolonAtTheEndL();
  1980 		iCcField->FixSemicolonAtTheEndL();
  2038     iBccField->FixSemicolonAtTheEndL();
  1981 		iBccField->FixSemicolonAtTheEndL();
  2039     }
  1982 	}
  2040 
  1983 
  2041 TBool CNcsHeaderContainer::IsRemoteSearchInprogress() const
  1984 TBool CNcsHeaderContainer::IsRemoteSearchInprogress() const
  2042     {
  1985     {
  2043     return iRALInProgress;
  1986     return iRALInProgress;
  2044     }
  1987     }
  2054         static_cast<CNcsComposeViewContainer*>( &iParent );
  1997         static_cast<CNcsComposeViewContainer*>( &iParent );
  2055     if ( container && aField )
  1998     if ( container && aField )
  2056         {
  1999         {
  2057         if ( aField == iToField )
  2000         if ( aField == iToField )
  2058             {
  2001             {
       
  2002 			if( iToField->TextEditor()->SelectionLength() )
       
  2003 				{
       
  2004 				iToField->TextEditor()->HandleTextChangedL();
       
  2005 				}
  2059             container->CommitL( EToField );
  2006             container->CommitL( EToField );
  2060             }
  2007             }
  2061         else if ( aField == iCcField )
  2008         else if ( aField == iCcField )
  2062             {
  2009             {
       
  2010 			if( iCcField->TextEditor()->SelectionLength() )
       
  2011 				{
       
  2012 				iCcField->TextEditor()->HandleTextChangedL();
       
  2013 				}
  2063             container->CommitL( ECcField );
  2014             container->CommitL( ECcField );
  2064             }
  2015             }
  2065         else if ( aField == iBccField )
  2016         else if ( aField == iBccField )
  2066             {
  2017             {
       
  2018 			if( iBccField->TextEditor()->SelectionLength() )
       
  2019 				{
       
  2020 				iBccField->TextEditor()->HandleTextChangedL();
       
  2021 				}
  2067             container->CommitL( EBccField );
  2022             container->CommitL( EBccField );
  2068             }
  2023             }
  2069         else if ( aField == iSubjectField ) 
  2024         else if ( aField == iSubjectField ) 
  2070             {
  2025             {
       
  2026 			if( iSubjectField->Editor()->SelectionLength() )
       
  2027 				{
       
  2028 				iSubjectField->Editor()->HandleTextChangedL();
       
  2029 				}
  2071             container->CommitL( ESubjectField );
  2030             container->CommitL( ESubjectField );
  2072             }
  2031             }
  2073         }
  2032         }
  2074     }
  2033     }
  2075 
  2034 
  2076 // ---------------------------------------------------------------------------
  2035 // -----------------------------------------------------------------------------
  2077 // Scrolls editor to make cursor visible, if it is outside the visible area
  2036 // CNcsHeaderContainer::DoScroll
  2078 // ---------------------------------------------------------------------------
  2037 // -----------------------------------------------------------------------------
  2079 // 
  2038 // 
  2080 void CNcsHeaderContainer::DoScroll()
  2039 void CNcsHeaderContainer::DoScroll()
  2081     {
  2040     {
  2082     // scroll the screen if the cursor goes beyond the screen
  2041     // scroll the screen if the cursor goes beyond the screen
  2083     CNcsComposeViewContainer& parent = 
  2042     CNcsComposeViewContainer& parent = static_cast<CNcsComposeViewContainer&>( iParent );
  2084         static_cast<CNcsComposeViewContainer&>( iParent );
  2043     
  2085 
  2044     TInt screenPos( -Position().iY );
  2086     // Scrolling based on cursor line number can only be done when
  2045     TInt cursorPos( CursorPosition() );
  2087     // header composer and one of its fields is focused.
  2046     TInt lineHeight( Rect().Height() / LineCount() );
  2088     if ( IsFocused() )
  2047     TInt screenHeight( parent.Rect().Height() );
  2089         {
  2048 
  2090         const TRect rect = Rect();
  2049     if ( cursorPos - lineHeight < screenPos )
  2091         const TInt screenPos =  iOrigin.iY - rect.iTl.iY;
  2050         {
  2092         const TInt screenHeight = parent.VisibleAreaHeight();
  2051         screenPos = cursorPos - lineHeight;             
  2093 
  2052         }
  2094         const TInt lineNumber = CursorLineNumber();
  2053     else if( cursorPos + lineHeight > screenPos + screenHeight )
  2095         const TInt lineHeight = rect.Height() / LineCount();
  2054         {
  2096         const TInt linePos = lineNumber * lineHeight;
  2055         screenPos = cursorPos + lineHeight - screenHeight;
  2097 
  2056         }
  2098         TInt targetPos = screenPos;
  2057 
  2099         if ( linePos - lineHeight < screenPos )
  2058     parent.Scroll( screenPos );
  2100             {
       
  2101             targetPos = linePos - lineHeight;
       
  2102             }
       
  2103         else if ( linePos + lineHeight > screenPos + screenHeight )
       
  2104             {
       
  2105             targetPos = linePos + lineHeight - screenHeight;
       
  2106             }
       
  2107 
       
  2108         parent.Scroll( targetPos );
       
  2109         }
       
  2110     }
       
  2111 
       
  2112 // ---------------------------------------------------------------------------
       
  2113 // Scrolls focused editor line to the top of visible area.
       
  2114 // ---------------------------------------------------------------------------
       
  2115 //
       
  2116 void CNcsHeaderContainer::DoScrollFocusToTop()
       
  2117     {
       
  2118     CNcsComposeViewContainer& parent =
       
  2119         static_cast<CNcsComposeViewContainer&>( iParent );
       
  2120 
       
  2121     // Calculate the position of the focused editor line.
       
  2122     const TRect rect = Rect();
       
  2123     const TInt lineNumber = CursorLineNumber();
       
  2124     const TInt lineHeight = rect.Height() / LineCount();
       
  2125     const TInt targetPos = ( lineNumber - 1 ) * lineHeight;
       
  2126 
       
  2127     parent.Scroll( targetPos );
       
  2128     }
  2059     }
  2129 
  2060 
  2130 // ---------------------------------------------------------------------------
  2061 // ---------------------------------------------------------------------------
  2131 // CNcsHeaderContainer::SetPhysicsEmulationOngoing
  2062 // CNcsHeaderContainer::SetPhysicsEmulationOngoing
  2132 // ---------------------------------------------------------------------------
  2063 // ---------------------------------------------------------------------------
  2138     iBccField->SetPhysicsEmulationOngoing( aPhysOngoing );
  2069     iBccField->SetPhysicsEmulationOngoing( aPhysOngoing );
  2139     iSubjectField->SetPhysicsEmulationOngoing( aPhysOngoing );
  2070     iSubjectField->SetPhysicsEmulationOngoing( aPhysOngoing );
  2140     }
  2071     }
  2141 
  2072 
  2142 // ---------------------------------------------------------------------------
  2073 // ---------------------------------------------------------------------------
  2143 // CNcsHeaderContainer::HandleResourceChange
  2074 // CNcsHeaderContainer::AttachmentOpenL
  2144 // ---------------------------------------------------------------------------
  2075 // ---------------------------------------------------------------------------
  2145 //
  2076 //
  2146 void CNcsHeaderContainer::HandleResourceChange( TInt aType )
  2077 void CNcsHeaderContainer::AttachmentOpenL()
  2147     {
  2078     {
  2148     FUNC_LOG;
  2079     CNcsComposeViewContainer& parent = 
  2149     CCoeControl::HandleResourceChange( aType );
  2080           static_cast<CNcsComposeViewContainer&>( iParent );
  2150     if ( aType == KAknSplitInputEnabled || aType == KAknSplitInputDisabled )
  2081 
  2151         {
  2082     parent.HandleAttachmentOpenCommandL();
  2152         iSplitScreenVKBEnabled = ( aType == KAknSplitInputEnabled );
  2083     }
  2153         if ( iAacListBox->IsVisible() )
  2084 
  2154             {
  2085 // ---------------------------------------------------------------------------
  2155             iAacListBox->SetPopupMaxRect( CalculatePopupRect() );
  2086 // CNcsHeaderContainer::AttachmentRemoveL
  2156             }
  2087 // ---------------------------------------------------------------------------
  2157         }
  2088 //
  2158     }
  2089 void CNcsHeaderContainer::AttachmentRemoveL()
  2159 
  2090     {
  2160 // ---------------------------------------------------------------------------
  2091     CNcsComposeViewContainer& parent = 
  2161 // Set origin for header's top position.
  2092           static_cast<CNcsComposeViewContainer&>( iParent );
  2162 // ---------------------------------------------------------------------------
  2093 
  2163 //
  2094     parent.HandleAttachmentRemoveCommandL();
  2164 void CNcsHeaderContainer::SetOrigin( TPoint& aOrigin )
  2095     }
  2165     {
       
  2166     iOrigin = aOrigin;
       
  2167     }
       
  2168