emailuis/emailui/src/ncscomposeviewcontainer.cpp
branchRCL_3
changeset 25 3533d4323edc
child 26 968773a0b6ef
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007 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:  compose view container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "emailtrace.h"
       
    22 #include <s32mem.h>
       
    23 #include <txtrich.h>
       
    24 #include <AknIconUtils.h>
       
    25 #include <StringLoader.h>
       
    26 #include <avkon.hrh>
       
    27 #include <AknsDrawUtils.h>
       
    28 #include <aknview.h>
       
    29 #include <AknUtils.h>
       
    30 #include <FreestyleEmailUi.rsg>
       
    31 #include <eikclbd.h>
       
    32 #include <aknViewAppUi.h>
       
    33 #include <aknnotewrappers.h> //CAknInformationNote
       
    34 #include <txtetext.h>
       
    35 #include <aknphysics.h>
       
    36 
       
    37 #include "ncscomposeviewcontainer.h"
       
    38 #include "ncsheadercontainer.h"
       
    39 #include "ncsaddressinputfield.h"
       
    40 #include "ncssubjectfield.h"
       
    41 #include "ncsconstants.h"
       
    42 #include "ncseditor.h"
       
    43 #include "ncspopuplistbox.h"
       
    44 #include "ncscomposeview.h"
       
    45 #include "ncsutility.h"
       
    46 #include "ncsemailaddressobject.h"
       
    47 #include "FreestyleEmailUiUtilities.h"
       
    48 #include "FreestyleEmailUiConstants.h"
       
    49 #include "FreestyleEmailUiSendAttachmentsListControl.h"
       
    50 #include "FreestyleEmailUiSendAttachmentsListVisualiser.h"
       
    51 #include "FreestyleEmailUiSendAttachmentsListModel.h"
       
    52 #include "FreestyleEmailUi.hrh"
       
    53 #include "FSAutoSaver.h"
       
    54 #include "FreestyleEmailUiCLSItem.h"
       
    55 #include "FSAsyncTextFormatter.h"
       
    56 
       
    57 const TInt KHeaderVisibilityThreshold = -100;
       
    58 
       
    59 // ========================= MEMBER FUNCTIONS ==================================
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // constructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CNcsComposeViewContainer::CNcsComposeViewContainer(
       
    66     CNcsComposeView& aView,
       
    67     CFsAutoSaver& aAutoSaver,
       
    68 	CFSMailBox& aMailBox ):
       
    69 	iView( aView ), iAmountMesFieldMovedUp( 0 ),
       
    70 	iAutoSaver( aAutoSaver ), iMailBox( aMailBox )
       
    71     {
       
    72     FUNC_LOG;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CNcsComposeViewContainer::NewL()
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CNcsComposeViewContainer* CNcsComposeViewContainer::NewL( 
       
    81     CNcsComposeView& aView, const TRect& aRect, CFSMailBox& aMailBox, 
       
    82     CFsAutoSaver& aAutoSaver, TInt aFlags )
       
    83     {
       
    84     FUNC_LOG;
       
    85 
       
    86     CNcsComposeViewContainer* self = new ( ELeave ) CNcsComposeViewContainer(
       
    87         aView, aAutoSaver, aMailBox );
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL( aRect, aFlags );
       
    90     CleanupStack::Pop( self );
       
    91 
       
    92     return self;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CNcsComposeViewContainer::ConstructL()
       
    97 // Symbian 2nd phase constructor can leave.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CNcsComposeViewContainer::ConstructL( const TRect& aRect, TInt aFlags )
       
   101     {
       
   102     FUNC_LOG;
       
   103 
       
   104     SetMopParent( &iView );
       
   105     CreateWindowL();
       
   106 
       
   107     if ( CAknPhysics::FeatureEnabled() )
       
   108         {
       
   109         iPhysics = CAknPhysics::NewL( *this, this );
       
   110         }
       
   111 
       
   112     // Setup the control array
       
   113     InitComponentArrayL();
       
   114     CCoeControlArray& controls = Components();
       
   115     controls.SetControlsOwnedExternally( ETrue );
       
   116 
       
   117     // Create the header field
       
   118     iHeader = CNcsHeaderContainer::NewL( *this, iMailBox, aFlags, iPhysics );
       
   119     controls.AppendLC( iHeader );
       
   120     CleanupStack::Pop( iHeader );
       
   121 
       
   122     // Create 'message body' field, default text is empty for that field
       
   123     iMessageField = new ( ELeave ) CNcsEditor( this, EFalse, ENcsEditorBody );
       
   124     iMessageField->SetContainerWindowL( *this );
       
   125     iMessageField->ConstructL( this, 0, 0 );
       
   126     iMessageField->SetAlignment( EAknEditorAlignBidi );
       
   127     iMessageField->SetAknEditorInputMode( EAknEditorTextInputMode );
       
   128     iMessageField->EnableKineticScrollingL( iPhysics );
       
   129     controls.AppendLC( iMessageField );
       
   130     CleanupStack::Pop( iMessageField );
       
   131 
       
   132     iMessageField->SetNcsFontType( NcsUtility::ENcsBodytextFont );
       
   133 
       
   134     // Listen edwin events and size events from message body field
       
   135     iMessageField->AddEdwinObserverL( this );
       
   136     iMessageField->SetEdwinSizeObserver( this );
       
   137 
       
   138     // Create read-only field to be used for original message quote when
       
   139     // protocol doesn't allow editing the original message
       
   140     iReadOnlyQuoteField = new( ELeave ) CNcsEditor( this, EFalse );
       
   141     iReadOnlyQuoteField->SetContainerWindowL( *this );
       
   142     iReadOnlyQuoteField->ConstructL( this, 0, 0 );
       
   143     iReadOnlyQuoteField->SetAlignment( EAknEditorAlignBidi );
       
   144     iReadOnlyQuoteField->SetReadOnly( ETrue );
       
   145     controls.AppendLC( iReadOnlyQuoteField );
       
   146     CleanupStack::Pop( iReadOnlyQuoteField );
       
   147 
       
   148     // Listen edwin events and size events from smart quote field
       
   149     iReadOnlyQuoteField->AddEdwinObserverL( this );
       
   150     iReadOnlyQuoteField->SetEdwinSizeObserver( this );
       
   151    iReadOnlyQuoteField->EnableKineticScrollingL( iPhysics );
       
   152 
       
   153     // Create the scroll bar
       
   154     iScrollBar = new( ELeave ) CAknDoubleSpanScrollBar( this );
       
   155     iScrollBar->ConstructL( ETrue, this, this, CEikScrollBar::EVertical,
       
   156         aRect.Height() );
       
   157     iScrollBar->MakeVisible( EFalse );
       
   158     iScrollBar->SetModelL( &iScrollBarModel );
       
   159     controls.AppendLC( iScrollBar );
       
   160     CleanupStack::Pop( iScrollBar );
       
   161 
       
   162     iMessageField->SetupEditorL();
       
   163     iReadOnlyQuoteField->SetupEditorL();
       
   164 
       
   165     iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
   166         KAknsIIDQsnBgAreaMain, Rect(), EFalse );
       
   167 
       
   168     SetRect( aRect );
       
   169 
       
   170     iLongTapDetector = CAknLongTapDetector::NewL( this );
       
   171 
       
   172     // activate auto save functionality
       
   173     iAutoSaver.Enable( ETrue );
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CNcsComposeViewContainer::StopAsyncTextFormatter
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CNcsComposeViewContainer::StopAsyncTextFormatter()
       
   181     {
       
   182     if ( iAsyncTextFormatter )
       
   183         {
       
   184         iAsyncTextFormatter->Cancel();
       
   185         }
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CNcsComposeViewContainer::~CNcsComposeViewContainer
       
   190 // Destructor
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 CNcsComposeViewContainer::~CNcsComposeViewContainer()
       
   194     {
       
   195     FUNC_LOG;
       
   196     
       
   197     if ( iAsyncTextFormatter )
       
   198         {
       
   199         iAsyncTextFormatter->Cancel();
       
   200         delete iAsyncTextFormatter;
       
   201         }
       
   202     
       
   203     if ( iContactHandler )
       
   204         {
       
   205         iContactHandler->ClearObservers();
       
   206         }
       
   207 	delete iHeader;
       
   208     delete iScrollBar;
       
   209     delete iMessageField;
       
   210     delete iBgContext;
       
   211 	delete iLongTapDetector;
       
   212     delete iReadOnlyQuoteField;
       
   213     delete iReadOnlyQuote;
       
   214 
       
   215     delete iPhysics;
       
   216     iPhysics = NULL;
       
   217     }
       
   218 
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CNcsComposeViewContainer::FocusChanged
       
   222 //
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void CNcsComposeViewContainer::FocusChanged( TDrawNow aDrawNow )
       
   226     {
       
   227     FUNC_LOG;
       
   228 
       
   229 	if ( iFocused != iHeader &&
       
   230 	     iFocused != iMessageField &&
       
   231 	     iFocused != iReadOnlyQuoteField )
       
   232         {
       
   233 		iFocused = iHeader;
       
   234         }
       
   235     if ( iFocused == iHeader )
       
   236         {
       
   237         iHeader->ShowCursor( IsFocused() );
       
   238         iFocused->SetFocus( ETrue, aDrawNow );
       
   239         }
       
   240     else if ( iFocused == iMessageField )
       
   241         {
       
   242         iFocused->SetFocus( IsFocused(), aDrawNow );
       
   243         }
       
   244     else 
       
   245         {
       
   246         iFocused->SetFocus( ETrue, aDrawNow );
       
   247         }
       
   248 
       
   249     iView.HandleContainerChangeRequiringToolbarRefresh();
       
   250 
       
   251 	if ( aDrawNow )
       
   252 	    {
       
   253 		DrawNow();
       
   254 	    }
       
   255 
       
   256     }
       
   257 // -----------------------------------------------------------------------------
       
   258 // CNcsComposeViewContainer::SetMskL()
       
   259 //
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CNcsComposeViewContainer::SetMskL()
       
   263     {
       
   264     FUNC_LOG;
       
   265     iHeader->SetMskL();
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CNcsComposeViewContainer::HandlePointerEventL()
       
   270 //
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 void CNcsComposeViewContainer::HandlePointerEventL( 
       
   274         const TPointerEvent& aPointerEvent )
       
   275     {
       
   276     FUNC_LOG;
       
   277 	TBool clearSelection(EFalse);
       
   278     if ( aPointerEvent.iType != TPointerEvent::EButton1Down &&
       
   279          iHeader->NeedsLongTapL( aPointerEvent.iPosition ) )
       
   280         {
       
   281     	iLongTapDetector->PointerEventL( aPointerEvent );
       
   282         }
       
   283 	   
       
   284     switch( aPointerEvent.iType )
       
   285     	{
       
   286     	case TPointerEvent::EButton1Down:
       
   287     		{
       
   288             // Save current and original position so that those can be used in
       
   289             // drag/scrolling calculations
       
   290             iPreviousPosition = iOriginalPosition = 
       
   291                 aPointerEvent.iPosition;
       
   292             iIsDragging = EFalse;
       
   293             iIsFlicking = EFalse;
       
   294 
       
   295             if( iPhysics )
       
   296                 {
       
   297                 iPhysics->StopPhysics();
       
   298                 iPhysics->ResetFriction();
       
   299                 iStartTime.HomeTime();
       
   300                 UpdatePhysicsL();
       
   301                 }            
       
   302 
       
   303             if ( iHeader->Rect().Contains( aPointerEvent.iPosition ) )
       
   304                 {
       
   305                 if ( iFocused == iMessageField )
       
   306                     {
       
   307 					if( iMessageField->SelectionLength() )
       
   308 						{
       
   309 						iMessageField->ClearSelectionL();
       
   310 						}
       
   311                     iMessageField->SetFocus( EFalse, ENoDrawNow );
       
   312                     iFocused = iHeader;
       
   313                     iHeader->SetFocus( ETrue,ENoDrawNow );
       
   314                     }
       
   315                 else if ( iFocused == iReadOnlyQuoteField )
       
   316                     {
       
   317                     iReadOnlyQuoteField->SetFocus( EFalse, ENoDrawNow );
       
   318                     iFocused = iHeader;
       
   319                     iHeader->SetFocus( ETrue, ENoDrawNow );
       
   320                     }
       
   321                 }
       
   322             else if ( iReadOnlyQuoteField->Rect().Contains( 
       
   323                         aPointerEvent.iPosition ) )
       
   324                 {
       
   325                 if ( iFocused == iMessageField )
       
   326                     {
       
   327                     iMessageField->SetFocus( EFalse, ENoDrawNow );
       
   328                     iFocused = iReadOnlyQuoteField;
       
   329                     iReadOnlyQuoteField->SetFocus( ETrue, ENoDrawNow );
       
   330                     iReadOnlyQuoteField->SetCursorPosL( 0, EFalse );
       
   331                     }
       
   332                 else if ( iFocused == iHeader )
       
   333                     {
       
   334                     iHeader->SetFocus( EFalse, ENoDrawNow );
       
   335                     iFocused = iReadOnlyQuoteField;
       
   336                     iReadOnlyQuoteField->SetFocus( ETrue, ENoDrawNow );
       
   337                     iReadOnlyQuoteField->SetCursorPosL( 0, EFalse );
       
   338                     }
       
   339                 }
       
   340             else 
       
   341                 {
       
   342                 if ( iFocused == iHeader )
       
   343                     {
       
   344                     iHeader->SetFocus( EFalse, ENoDrawNow );
       
   345                     iFocused = iMessageField;
       
   346                     iMessageField->SetFocus( ETrue, ENoDrawNow );
       
   347                     }
       
   348                 else if ( iFocused == iReadOnlyQuoteField )
       
   349                     {
       
   350                     iReadOnlyQuoteField->SetFocus( EFalse, ENoDrawNow );
       
   351                     iFocused = iMessageField;
       
   352                     iMessageField->SetFocus( ETrue, ENoDrawNow );
       
   353                     }
       
   354                 else
       
   355                     {
       
   356 				    // Changes made in predictive input mode can be approved
       
   357 					// only if ClearSelection is called AFTER
       
   358 					// CCoeControl::HandlePointerEventL,
       
   359 					// so iMessageField->ClearSelection() has been moved
       
   360 					clearSelection = ETrue;
       
   361                     }
       
   362                 }
       
   363 
       
   364 			break;
       
   365     		}
       
   366     	
       
   367     	case TPointerEvent::EButton1Up:    		
       
   368     		{
       
   369             if( iIsDragging && iPhysics )
       
   370                 {
       
   371                 TPoint drag( iOriginalPosition - aPointerEvent.iPosition );
       
   372                 iPhysics->StartPhysics( drag, iStartTime );
       
   373                 iIsFlicking = ETrue;
       
   374                 iIsDragging = EFalse;
       
   375                 }
       
   376     		break;
       
   377     		}
       
   378     	
       
   379     	case TPointerEvent::EDrag:
       
   380     		{
       
   381             if ( !iIsDragging )
       
   382                 {
       
   383                 TInt drag( iOriginalPosition.iY - aPointerEvent.iPosition.iY );
       
   384                 if ( Abs( drag ) > iPhysics->DragThreshold() )
       
   385                     {
       
   386 					// If user started dragging, cancel hotspot actions
       
   387 					iIsDragging = ETrue;
       
   388 					iMessageField->SetPhysicsEmulationOngoing( ETrue );
       
   389 					iReadOnlyQuoteField->SetPhysicsEmulationOngoing( ETrue );
       
   390 					iHeader->SetPhysicsEmulationOngoing( ETrue );
       
   391                     }
       
   392                 }
       
   393 
       
   394             // Get current pointer position
       
   395             TPoint position = aPointerEvent.iPosition;
       
   396 
       
   397 
       
   398            if( iPhysics )
       
   399                {
       
   400 			   if ( iIsDragging )
       
   401 				   {
       
   402                     TPoint delta( 0, iPreviousPosition.iY - position.iY );
       
   403                     if ( !iMessageField->SelectionLength() )
       
   404                     		iPhysics->RegisterPanningPosition( delta );
       
   405 				   }
       
   406                 }
       
   407             else
       
   408                 {
       
   409     			TInt topPosition( -iHeader->Position().iY );
       
   410     						
       
   411     			TInt totalHeight( ContentTotalHeight() );
       
   412 
       
   413     			TInt areaHeight( Rect().Size().iHeight );
       
   414     			TInt scrollOffset( 0 );
       
   415     			
       
   416 				if( totalHeight > areaHeight )
       
   417 					{
       
   418 					// Calculate new scroll offset based on current and
       
   419 					// previous Y-positions
       
   420 					scrollOffset = topPosition + 
       
   421                         ( iPreviousPosition.iY - position.iY );
       
   422 					// Ensure that thumb position is in correct range
       
   423 					scrollOffset = Max( scrollOffset, 0 );
       
   424 					scrollOffset = Min( scrollOffset, 
       
   425                                         totalHeight - areaHeight );
       
   426 					}
       
   427 
       
   428 				Scroll( scrollOffset );
       
   429 				}
       
   430            
       
   431 			// Save current position as previous pos for future calculations
       
   432 			iPreviousPosition = position;  
       
   433 			
       
   434 			break;
       
   435     		}
       
   436     		
       
   437     	default:
       
   438     		{
       
   439     		// unknown event, ignored
       
   440     		break;
       
   441     		}
       
   442     	}
       
   443     	
       
   444     if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
       
   445          iHeader->NeedsLongTapL( aPointerEvent.iPosition ) )
       
   446         {
       
   447         iLongTapDetector->PointerEventL( aPointerEvent );
       
   448         }
       
   449 
       
   450     CCoeControl::HandlePointerEventL( aPointerEvent );
       
   451 	if (clearSelection)
       
   452 		{
       
   453 		iMessageField->ClearSelectionL();
       
   454 		}
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CNcsComposeViewContainer::OfferKeyEventL()
       
   459 // Handles key events
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 TKeyResponse CNcsComposeViewContainer::OfferKeyEventL( 
       
   463         const TKeyEvent& aKeyEvent, TEventCode aType )
       
   464     {
       
   465     FUNC_LOG;
       
   466 
       
   467     if( iPhysics )
       
   468         {
       
   469         iPhysics->StopPhysics();
       
   470         iPhysics->ResetFriction();
       
   471         }
       
   472 
       
   473     TKeyResponse ret( EKeyWasNotConsumed );
       
   474 
       
   475     //we are allowing to change MSK label 
       
   476     SwitchChangeMskOff( EFalse );
       
   477     
       
   478     if ( aKeyEvent.iCode == EKeyYes )
       
   479         {
       
   480         // check that at least one of the address fields has an address
       
   481         if ( !iHeader->AreAddressFieldsEmpty() )
       
   482             {
       
   483             iView.HandleCommandL( ENcsCmdSend );
       
   484             }
       
   485         else
       
   486             {
       
   487             AppendAddressesL();
       
   488             }
       
   489         ret = EKeyWasConsumed;
       
   490         }
       
   491     else if ( aKeyEvent.iCode == EKeyOK )
       
   492     	{
       
   493         if ( iHeader->IsPopupActive() )
       
   494             {
       
   495             DoPopupSelectL();
       
   496             ret = EKeyWasConsumed;
       
   497             }
       
   498         else if ( AppendAddressesL() )
       
   499             {
       
   500             ret = EKeyWasConsumed;
       
   501             }
       
   502         }
       
   503     else if ( aKeyEvent.iScanCode == 'S' &&
       
   504               aKeyEvent.iModifiers & EModifierCtrl &&
       
   505               aType == EEventKey )
       
   506         {
       
   507         iView.HandleCommandL( ENcsCmdSaveDraft );
       
   508         ret = EKeyWasConsumed;
       
   509         }
       
   510     else if ( aKeyEvent.iCode == EKeyUpArrow || 
       
   511               aKeyEvent.iCode == EKeyDownArrow )
       
   512         {
       
   513         ret = iFocused->OfferKeyEventL( aKeyEvent, aType );
       
   514 
       
   515         if ( ret == EKeyWasNotConsumed )
       
   516             {
       
   517             ret = ChangeFocusL( aKeyEvent );
       
   518             }
       
   519 
       
   520         if ( ret != EKeyWasConsumed )
       
   521             {
       
   522             DrawDeferred();
       
   523             }
       
   524         }
       
   525 
       
   526     if ( ret == EKeyWasNotConsumed )
       
   527         {
       
   528         if ( iFocused )
       
   529             ret = iFocused->OfferKeyEventL( aKeyEvent, aType );
       
   530 
       
   531         iView.HandleContainerChangeRequiringToolbarRefresh();
       
   532         
       
   533         // Report user activity to auto saver if editor field handled the
       
   534         // event. In case of message field (body text), EKeyWasConsumed
       
   535         // condition does not come true because AknFep consumes EKeyEvent
       
   536         // and calls HandleEdwinEventL. This OfferKeyEventL gets only
       
   537         // EEventKeyUp and EEventKeyDown events. Thus, when typing body text,
       
   538         // autosaver is notified in HandleEdwinEventL()
       
   539         if ( ( ret == EKeyWasConsumed ) && ( iFocused != iMessageField ) )
       
   540             {
       
   541             iAutoSaver.ReportActivity();
       
   542             }
       
   543         }
       
   544 
       
   545     return ret;
       
   546     }
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // CNcsComposeViewContainer::UpdateScreenPositionL()
       
   550 // If the user scrolled down in the message field
       
   551 // we want to scroll up the header and grow the message field.
       
   552 // -----------------------------------------------------------------------------
       
   553 //
       
   554 void CNcsComposeViewContainer::UpdateScreenPositionL( 
       
   555         const TUint& /*aKeyCode*/ )
       
   556     {
       
   557     FUNC_LOG;
       
   558 
       
   559     // get screen rectangle
       
   560     const TRect screenRect( Rect() );
       
   561 
       
   562     TPoint msgPos( iMessageField->Position() );
       
   563     TPoint quotePos( iReadOnlyQuoteField->Position() );
       
   564 
       
   565     // find out cursor position in absolute coordinates
       
   566     TRect lineRect;
       
   567     if ( iFocused == iMessageField )
       
   568         {
       
   569         iMessageField->GetLineRectL( lineRect );
       
   570         lineRect.Move( msgPos );
       
   571         }
       
   572     else if ( iFocused == iReadOnlyQuoteField )
       
   573         {
       
   574         iReadOnlyQuoteField->GetLineRectL( lineRect );
       
   575         lineRect.Move( quotePos );
       
   576         }
       
   577     else
       
   578         {
       
   579         // This function should be used only when focus is in body or
       
   580         // read-only quote
       
   581         return;
       
   582         }
       
   583     TPoint linePos = lineRect.iTl;
       
   584 
       
   585     TInt minTargetY = lineRect.Height();
       
   586     TInt maxTargetY = screenRect.Height() - lineRect.Height() * 2;
       
   587 
       
   588     TInt moveY = 0;
       
   589     // if cursor goes out of screen then move the controls
       
   590     if ( linePos.iY > maxTargetY )
       
   591         {
       
   592         moveY = maxTargetY - linePos.iY;
       
   593         }
       
   594     else if ( linePos.iY < minTargetY )
       
   595         {
       
   596         moveY = minTargetY - linePos.iY;
       
   597         }
       
   598 
       
   599     // Check we don't scroll too low
       
   600     if ( quotePos.iY + moveY + iReadOnlyQuoteField->Size().iHeight < 
       
   601          screenRect.Height() )
       
   602         {
       
   603         moveY = screenRect.Height() - quotePos.iY - 
       
   604             iReadOnlyQuoteField->Size().iHeight;
       
   605         }
       
   606 
       
   607     // Check we don't scroll too high
       
   608     TPoint headerPos = iHeader->Position();
       
   609     if ( headerPos.iY + moveY > 0 )
       
   610         {
       
   611         moveY = -headerPos.iY;
       
   612         }
       
   613 
       
   614     if ( moveY )
       
   615         {
       
   616         headerPos.iY += moveY;
       
   617         iHeader->SetPosition( headerPos );
       
   618 
       
   619         msgPos.iY += moveY;
       
   620         iMessageField->SetPosition( msgPos );
       
   621 
       
   622         quotePos.iY += moveY;
       
   623         iReadOnlyQuoteField->SetPosition( quotePos );
       
   624 
       
   625         iSeparatorLineYPos += moveY;
       
   626         UpdateScrollBar();
       
   627         }
       
   628     }
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // CNcsComposeViewContainer::UpdateFieldPosition
       
   632 //
       
   633 // -----------------------------------------------------------------------------
       
   634 //
       
   635 void CNcsComposeViewContainer::UpdateFieldPosition( CCoeControl* aAnchor )
       
   636     {
       
   637     FUNC_LOG;
       
   638 
       
   639     // We may not be completely constructed
       
   640     if ( iHeader && iMessageField && iReadOnlyQuoteField )
       
   641         {
       
   642         // First, move all the controls in the header
       
   643         iHeader->UpdateFieldPosition( aAnchor );
       
   644 
       
   645         // Then, move the body field below the header
       
   646         TRect headerRect = iHeader->Rect();
       
   647 
       
   648         const TSize separatorSize( 
       
   649             NcsUtility::SeparatorSizeInThisResolution() );
       
   650         iSeparatorLineYPos = headerRect.iBr.iY;
       
   651 
       
   652         TPoint bodyPos( iMessageField->Position() );
       
   653         bodyPos.iY = iSeparatorLineYPos + separatorSize.iHeight;
       
   654         iMessageField->SetPosition( bodyPos );
       
   655 
       
   656         TPoint quotePos( iReadOnlyQuoteField->Position() );
       
   657         quotePos.iY = iMessageField->Rect().iBr.iY;
       
   658         iReadOnlyQuoteField->SetPosition( quotePos );
       
   659 
       
   660         UpdateScrollBar();
       
   661         DrawDeferred();
       
   662         }
       
   663 
       
   664     }
       
   665 
       
   666 // -----------------------------------------------------------------------------
       
   667 // CNcsComposeViewContainer::ChangeFocusL()
       
   668 // Handles key events
       
   669 // -----------------------------------------------------------------------------
       
   670 //
       
   671 
       
   672 TKeyResponse CNcsComposeViewContainer::ChangeFocusL( 
       
   673         const TKeyEvent& aKeyEvent )
       
   674     {
       
   675     FUNC_LOG;
       
   676 
       
   677     TKeyResponse ret( EKeyWasNotConsumed );
       
   678 
       
   679     if ( iFocused == iReadOnlyQuoteField && aKeyEvent.iCode == EKeyUpArrow )
       
   680         {
       
   681         iFocused = iMessageField;
       
   682         iReadOnlyQuoteField->SetFocus( EFalse, ENoDrawNow );
       
   683         iMessageField->SetFocus( ETrue, ENoDrawNow );
       
   684         ret = EKeyWasConsumed;
       
   685         }
       
   686     else if ( iFocused == iMessageField )
       
   687         {
       
   688         if ( aKeyEvent.iCode == EKeyUpArrow )
       
   689             {
       
   690             iFocused = iHeader;
       
   691             iHeader->SetFocus( ETrue, ENoDrawNow );
       
   692             iMessageField->SetFocus( EFalse, ENoDrawNow );
       
   693             iHeader->MakeVisible( ETrue );
       
   694             iHeader->ShowCursor( ETrue );
       
   695             CommitL( EBodyField );
       
   696             ret = EKeyWasConsumed;
       
   697             }
       
   698         else if ( aKeyEvent.iCode == EKeyDownArrow && 
       
   699                   iReadOnlyQuoteField->TextLength() )
       
   700             {
       
   701             // Focus move to read-only quote only if there is some text in it.
       
   702             iFocused = iReadOnlyQuoteField;
       
   703             iReadOnlyQuoteField->SetFocus( ETrue, ENoDrawNow );
       
   704             iMessageField->SetFocus( EFalse, ENoDrawNow );
       
   705             iReadOnlyQuoteField->SetCursorPosL( 0, EFalse );
       
   706             ret = EKeyWasConsumed;
       
   707             }
       
   708         }
       
   709     else if ( iFocused == iHeader && aKeyEvent.iCode == EKeyDownArrow )
       
   710         {
       
   711         iFocused = iMessageField;
       
   712         iHeader->SetFocus( EFalse, ENoDrawNow );
       
   713         iMessageField->SetFocus( ETrue, ENoDrawNow );
       
   714         iMessageField->SetCursorPosL( 0, EFalse );
       
   715         ret = EKeyWasConsumed;
       
   716         }
       
   717 
       
   718     if ( ret == EKeyWasConsumed )
       
   719         {
       
   720         UpdateScreenPositionL( aKeyEvent.iCode );
       
   721         }
       
   722 
       
   723     return ret;
       
   724     }
       
   725 
       
   726 // -----------------------------------------------------------------------------
       
   727 // CNcsComposeViewContainer::UpdateFieldSizeL()
       
   728 // This is called through MNcsFieldSizeObserver when the rects have changed
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 TBool CNcsComposeViewContainer::UpdateFieldSizeL( TBool aDoScroll )
       
   732     {
       
   733     FUNC_LOG;
       
   734 
       
   735     // We may not have finished construction
       
   736     if ( iHeader && iMessageField && iReadOnlyQuoteField && !aDoScroll )
       
   737         {
       
   738         SizeChanged();
       
   739         }
       
   740     if ( iHeader && aDoScroll )
       
   741         {
       
   742         iHeader->DoScroll();
       
   743         }
       
   744 
       
   745     return EFalse;
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CNcsComposeViewContainer::SizeChanged()
       
   750 // set size
       
   751 // -----------------------------------------------------------------------------
       
   752 //
       
   753 void CNcsComposeViewContainer::SizeChanged()
       
   754     {
       
   755     FUNC_LOG;
       
   756 
       
   757     const TRect rect( Rect() );
       
   758     iScrollBar->SetRect( NcsUtility::ListCmailScrollbarRect( rect ) );
       
   759     TRect cmailPaneRect( NcsUtility::ListCmailPaneRect( rect ) );
       
   760 
       
   761     const TInt headerLineCount( iHeader->LayoutLineCount() );
       
   762     const TPoint headerPos( 
       
   763             NcsUtility::HeaderControlPosition( cmailPaneRect, 0 ) );
       
   764     cmailPaneRect.Move( 0, iHeader->Position().iY - headerPos.iY );
       
   765     iCmailPaneRect = cmailPaneRect;
       
   766 
       
   767     NcsUtility::LayoutHeaderControl( 
       
   768             iHeader, cmailPaneRect, 0, headerLineCount );
       
   769 
       
   770     // do not used stored headerLineCount, because relayout above may grow or
       
   771     // shrink edit fields
       
   772     NcsUtility::LayoutBodyEdwin( 
       
   773             iMessageField, cmailPaneRect, iHeader->LayoutLineCount(), 
       
   774             iMessageField->LineCount(), iSeparatorLineYPos );
       
   775     iMessageField->SetAlignment( EAknEditorAlignBidi );
       
   776     
       
   777     // we don't need format again when format was already done
       
   778     // during creation of forward/reply message
       
   779     if ( !iSwitchOffFormattingText )
       
   780         {
       
   781         TRAP_IGNORE( iMessageField->FormatAllTextNowL() );
       
   782         }
       
   783 
       
   784     iMessageField->UpdateFontSize();
       
   785 
       
   786     TInt readOnlyQuoteFieldHeight( 0 );
       
   787     if ( iReadOnlyQuoteField->TextLength() )
       
   788         {
       
   789         TInt dummySeparatorPos;
       
   790         NcsUtility::LayoutBodyEdwin(
       
   791                 iReadOnlyQuoteField, cmailPaneRect, 
       
   792                 iHeader->LayoutLineCount() + iMessageField->LineCount(), 
       
   793                 iReadOnlyQuoteField->LineCount(), dummySeparatorPos );
       
   794         iReadOnlyQuoteField->SetAlignment( EAknEditorAlignBidi );
       
   795         // we don't need format again when format was already done
       
   796 		// during creation of forward/reply message
       
   797         if ( !iSwitchOffFormattingText )
       
   798             {
       
   799             TRAP_IGNORE( iReadOnlyQuoteField->FormatAllTextNowL() );
       
   800             }
       
   801         iReadOnlyQuoteField->UpdateFontSize();
       
   802         readOnlyQuoteFieldHeight = iReadOnlyQuoteField->Rect().Height();
       
   803         }
       
   804 
       
   805     iBgContext->SetRect( Rect() );
       
   806     iMessageField->SetRealRect( Rect() );
       
   807     iReadOnlyQuoteField->SetRealRect( Rect() );
       
   808 
       
   809     TInt messageLineHeigth = 
       
   810         NcsUtility::HeaderCaptionPaneRect( cmailPaneRect ).Height();
       
   811     iSeparatorHeight = NcsUtility::SeparatorSizeInThisResolution().iHeight;
       
   812     iMessageEditorMinHeigth = 
       
   813         cmailPaneRect.Height() - iHeader->Size().iHeight -
       
   814         iSeparatorHeight -
       
   815         readOnlyQuoteFieldHeight;
       
   816     
       
   817     iMessageEditorMinHeigth -= iMessageEditorMinHeigth % messageLineHeigth;
       
   818     if ( iMessageEditorMinHeigth > messageLineHeigth )
       
   819         {
       
   820         TSize newSize( iMessageField->Size().iWidth,
       
   821                        Max( iMessageField->Size().iHeight, 
       
   822                             iMessageEditorMinHeigth ) );
       
   823 
       
   824         if ( !iSwitchOffFormattingText ) 
       
   825             {
       
   826             iMessageField->SetSize( newSize );
       
   827             }
       
   828         }
       
   829     else
       
   830         {
       
   831         iMessageEditorMinHeigth = messageLineHeigth;
       
   832         }
       
   833 
       
   834 	// update some layout variables
       
   835     iHeaderHeight = iHeader->Rect().Height();
       
   836     TRect bodyRect = iMessageField->Rect();
       
   837     TRect quoteRect = iReadOnlyQuoteField->Rect();
       
   838 
       
   839     iTotalComposerHeight = iHeaderHeight + iSeparatorHeight * 2 + 
       
   840 							   bodyRect.Height() + quoteRect.Height();
       
   841     
       
   842     iVisibleAreaHeight = Rect().Height();
       
   843         
       
   844     UpdateScrollBar();
       
   845 
       
   846     iScrollBarModel.SetScrollSpan( iTotalComposerHeight );
       
   847     iScrollBarModel.SetWindowSize( iVisibleAreaHeight );
       
   848     DrawDeferred();
       
   849     }
       
   850 
       
   851 // -----------------------------------------------------------------------------
       
   852 // CNcsComposeViewContainer::Draw() const
       
   853 // Draws the display
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 void CNcsComposeViewContainer::Draw( const TRect& aRect ) const
       
   857     {
       
   858     FUNC_LOG;
       
   859 
       
   860     CWindowGc& gc = SystemGc();
       
   861     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   862     if ( skin )
       
   863         {
       
   864         AknsDrawUtils::Background( skin, iBgContext, this, gc, aRect );
       
   865         }
       
   866     }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // CNcsComposeViewContainer::SetBodyContentL()
       
   870 // -----------------------------------------------------------------------------
       
   871 //
       
   872 void CNcsComposeViewContainer::SetBodyContentL( const TDesC& aMessage,
       
   873     const TDesC& aReadOnlyQuote )
       
   874     {
       
   875     FUNC_LOG;
       
   876     delete iReadOnlyQuote;
       
   877     iReadOnlyQuote = NULL;
       
   878     if ( aReadOnlyQuote.Length() )
       
   879         {
       
   880         iReadOnlyQuote = aReadOnlyQuote.AllocL();
       
   881         }
       
   882 
       
   883     RMemReadStream inputStream( aMessage.Ptr(), aMessage.Size() );
       
   884     CleanupClosePushL( inputStream );
       
   885     iMessageField->RichText()->ImportTextL( 0, inputStream,
       
   886         CPlainText::EOrganiseByParagraph );
       
   887     CleanupStack::PopAndDestroy( &inputStream );
       
   888 
       
   889     // Activating the field will set the control to the end of the text
       
   890     iMessageField->ActivateL();
       
   891     iMessageField->SetCursorPosL( 0, EFalse );
       
   892 	iMessageField->FormatAllTextNowL();
       
   893 
       
   894     inputStream.Open( aReadOnlyQuote.Ptr(), aReadOnlyQuote.Size() );
       
   895     CleanupClosePushL( inputStream );
       
   896     iReadOnlyQuoteField->RichText()->ImportTextL( 0, inputStream,
       
   897         CPlainText::EOrganiseByParagraph );
       
   898     CleanupStack::PopAndDestroy( &inputStream );
       
   899 
       
   900     // Activating the field will set the control to the end of the text
       
   901     iReadOnlyQuoteField->ActivateL();
       
   902     iReadOnlyQuoteField->SetCursorPosL( 0, EFalse );
       
   903 
       
   904     // Recalculate the size of the body field
       
   905     SizeChanged();
       
   906     }
       
   907 
       
   908 // -----------------------------------------------------------------------------
       
   909 // CNcsComposeViewContainer::SetBodyContentAsyncL()
       
   910 // -----------------------------------------------------------------------------
       
   911 //
       
   912 void CNcsComposeViewContainer::SetBodyContentAsyncL( const TDesC& aMessage,
       
   913     const TDesC& aReadOnlyQuote )
       
   914     {
       
   915     FUNC_LOG;
       
   916     delete iReadOnlyQuote;
       
   917     iReadOnlyQuote = NULL;
       
   918     if ( aReadOnlyQuote.Length() )
       
   919         {
       
   920         iReadOnlyQuote = aReadOnlyQuote.AllocL();
       
   921         }
       
   922 
       
   923     RMemReadStream inputStream( aMessage.Ptr(), aMessage.Size() );
       
   924     CleanupClosePushL( inputStream );
       
   925     iMessageField->RichText()->ImportTextL( 0, inputStream,
       
   926         CPlainText::EOrganiseByParagraph );
       
   927     CleanupStack::PopAndDestroy( &inputStream );
       
   928     
       
   929 
       
   930     // Activating the field will set the control to the end of the text
       
   931     iMessageField->ActivateL();
       
   932     iMessageField->SetCursorPosL( 0, EFalse );
       
   933     
       
   934     iProcessedField = iMessageField;
       
   935     
       
   936 	iAsyncTextFormatter = CFSAsyncTextFormatter::NewL();
       
   937     iAsyncTextFormatter->StartFormatting( iMessageField->TextLayout(), this );
       
   938         
       
   939     // callback from AO: FormatAllTextCompleteL
       
   940 }
       
   941 
       
   942 // -----------------------------------------------------------------------------
       
   943 // CNcsComposeViewContainer::FormatAllTextCancelled()
       
   944 // -----------------------------------------------------------------------------
       
   945 //
       
   946 void CNcsComposeViewContainer::FormatAllTextCancelled()
       
   947 	{
       
   948 	iView.SetBodyContentComplete();
       
   949 	}
       
   950 
       
   951 // -----------------------------------------------------------------------------
       
   952 // CNcsComposeViewContainer::FormatAllTextComplete()
       
   953 // -----------------------------------------------------------------------------
       
   954 //
       
   955 void CNcsComposeViewContainer::FormatAllTextComplete()
       
   956 	{
       
   957     if ( iReadOnlyQuote && iProcessedField == iMessageField )
       
   958         {
       
   959         iProcessedField = iReadOnlyQuoteField;
       
   960         if ( iReadOnlyQuote )
       
   961             {
       
   962 			TInt dummySeparatorPos;
       
   963 			NcsUtility::LayoutBodyEdwin( iReadOnlyQuoteField, iCmailPaneRect, 
       
   964 					iHeader->LayoutLineCount() + iMessageField->LineCount(),
       
   965 					iReadOnlyQuoteField->LineCount(), dummySeparatorPos );
       
   966             iReadOnlyQuoteField->SetAlignment( EAknEditorAlignBidi );
       
   967             
       
   968 			RMemReadStream inputStream;
       
   969             inputStream.Open( iReadOnlyQuote->Ptr(), iReadOnlyQuote->Size() );
       
   970             TRAP_IGNORE( iReadOnlyQuoteField->RichText()->ImportTextL( 0, inputStream,
       
   971                     CPlainText::EOrganiseByParagraph ) );
       
   972             inputStream.Close();
       
   973             
       
   974             // Activating the field will set the control to the end of the text
       
   975             TRAP_IGNORE( iReadOnlyQuoteField->ActivateL() );
       
   976             TRAP_IGNORE( iReadOnlyQuoteField->SetCursorPosL( 0, EFalse ) );
       
   977             
       
   978             if ( !iAsyncTextFormatter )
       
   979                 {
       
   980                 TRAP_IGNORE( iAsyncTextFormatter = CFSAsyncTextFormatter::NewL() );
       
   981                 }
       
   982             iAsyncTextFormatter->StartFormatting( 
       
   983                     iReadOnlyQuoteField->TextLayout(), this );
       
   984             }
       
   985         }
       
   986     else
       
   987         {
       
   988         // Recalculate the size of the body field
       
   989         iSwitchOffFormattingText = ETrue;
       
   990         SizeChanged();
       
   991         iSwitchOffFormattingText = EFalse;
       
   992         
       
   993         iView.SetBodyContentComplete();
       
   994         }
       
   995     }
       
   996 
       
   997 // -----------------------------------------------------------------------------
       
   998 // CNcsComposeViewContainer::GetBodyContentLC()
       
   999 // -----------------------------------------------------------------------------
       
  1000 //
       
  1001 HBufC* CNcsComposeViewContainer::GetBodyContentLC()
       
  1002     {
       
  1003     FUNC_LOG;
       
  1004     HBufC* body = NULL;
       
  1005 
       
  1006     TInt messageLength = iMessageField->TextLength();
       
  1007     HBufC* message = HBufC::NewLC( messageLength );
       
  1008     TPtr messagePtr = message->Des();
       
  1009     iMessageField->GetText( messagePtr );
       
  1010 
       
  1011     CleanupStack::Pop();
       
  1012     CleanupStack::PushL( message );
       
  1013     messageLength = message->Length();
       
  1014 
       
  1015     // Append read-only quote if present
       
  1016     if ( iReadOnlyQuote )
       
  1017         {
       
  1018         TInt quoteLength = iReadOnlyQuote->Length();
       
  1019         TInt length = messageLength + KIMSLineFeed().Length() + quoteLength;
       
  1020         body = message->ReAllocL( length );
       
  1021         CleanupStack::Pop( message );
       
  1022         CleanupStack::PushL( body );
       
  1023 
       
  1024         TPtr bodyPtr = body->Des();
       
  1025         bodyPtr.Append( KIMSLineFeed() );
       
  1026         bodyPtr.Append( *iReadOnlyQuote );
       
  1027         }
       
  1028     else
       
  1029         {
       
  1030         body = message;
       
  1031         }
       
  1032 
       
  1033     return body;
       
  1034     }
       
  1035 
       
  1036 // -----------------------------------------------------------------------------
       
  1037 // CNcsComposeViewContainer::BodyText()
       
  1038 // -----------------------------------------------------------------------------
       
  1039 //
       
  1040 CRichText& CNcsComposeViewContainer::BodyText()
       
  1041     {
       
  1042     FUNC_LOG;
       
  1043     return *iMessageField->RichText();
       
  1044     }
       
  1045 
       
  1046 // -----------------------------------------------------------------------------
       
  1047 // CNcsComposeViewContainer::HandleScrollEventL()
       
  1048 // -----------------------------------------------------------------------------
       
  1049 //
       
  1050 void CNcsComposeViewContainer::HandleScrollEventL( 
       
  1051         CEikScrollBar* aScrollBar, TEikScrollEvent /*aEventType*/ )
       
  1052     {
       
  1053     FUNC_LOG;
       
  1054     
       
  1055     if( iPhysics )
       
  1056         {
       
  1057         iPhysics->StopPhysics();
       
  1058         iPhysics->ResetFriction();
       
  1059         }
       
  1060         
       
  1061     ClosePopupContactListL();
       
  1062 
       
  1063     Scroll( aScrollBar->ThumbPosition() );
       
  1064     }
       
  1065 
       
  1066 // -----------------------------------------------------------------------------
       
  1067 // CNcsComposeViewContainer::OperationCompleteL
       
  1068 // -----------------------------------------------------------------------------
       
  1069 //
       
  1070 void CNcsComposeViewContainer::OperationCompleteL( TContactHandlerCmd /*aCmd*/,
       
  1071     const RPointerArray<CFSEmailUiClsItem>& aContacts )
       
  1072 	{
       
  1073     FUNC_LOG;
       
  1074 	if ( aContacts.Count() )
       
  1075 		{
       
  1076 		RPointerArray<CNcsEmailAddressObject> ncsObjects;
       
  1077 		CleanupResetAndDestroyClosePushL( ncsObjects );
       
  1078 
       
  1079 		for ( TInt i = 0 ; i < aContacts.Count() ; i++ )
       
  1080 			{
       
  1081 			CNcsEmailAddressObject* object = 
       
  1082                 CNcsEmailAddressObject::NewL( aContacts[i]->DisplayName(),
       
  1083 					aContacts[i]->EmailAddress() );
       
  1084 			if ( aContacts[i]->MultipleEmails() )
       
  1085 				{
       
  1086 
       
  1087 				object->SetDisplayFull( ETrue );
       
  1088 				}
       
  1089 			CleanupStack::PushL( object );
       
  1090 			ncsObjects.AppendL( object );
       
  1091 			CleanupStack::Pop( object );
       
  1092 			}
       
  1093 
       
  1094 		if ( iAppendAddresses == EAppendTo )
       
  1095 			{
       
  1096 			AppendToFieldAddressesL( ncsObjects );
       
  1097 			}
       
  1098 		// if Cc field is focused insert addresses in there
       
  1099 		else if ( iAppendAddresses == EAppendCc )
       
  1100 			{
       
  1101 			AppendCcFieldAddressesL( ncsObjects );
       
  1102 			}
       
  1103 		// if Bcc field is focused insert addresses in there
       
  1104 		else if ( iAppendAddresses == EAppendBcc )
       
  1105 			{
       
  1106 			AppendBccFieldAddressesL( ncsObjects );
       
  1107 			}
       
  1108 
       
  1109 		CleanupStack::PopAndDestroy( &ncsObjects );
       
  1110 		}
       
  1111 	iView.HandleContainerChangeRequiringToolbarRefresh();
       
  1112 	}
       
  1113 
       
  1114 // -----------------------------------------------------------------------------
       
  1115 // CNcsComposeViewContainer::OperationErrorL
       
  1116 // -----------------------------------------------------------------------------
       
  1117 //
       
  1118 void CNcsComposeViewContainer::OperationErrorL( 
       
  1119         TContactHandlerCmd, TInt /*aError*/ )
       
  1120 	{
       
  1121     FUNC_LOG;
       
  1122 	//Nothing to do
       
  1123 	}
       
  1124 
       
  1125 // -----------------------------------------------------------------------------
       
  1126 // CNcsComposeViewContainer::HandleEdwinEventL
       
  1127 // -----------------------------------------------------------------------------
       
  1128 //
       
  1129 void CNcsComposeViewContainer::HandleEdwinEventL( CEikEdwin* aEdwin,
       
  1130     TEdwinEvent aEventType )
       
  1131     {
       
  1132     FUNC_LOG;
       
  1133     if (( aEdwin == iMessageField || aEdwin == iReadOnlyQuoteField ) && 
       
  1134          ( !iPhysics || iPhysics->OngoingPhysicsAction() == CAknPhysics::EAknPhysicsActionNone ))
       
  1135         {
       
  1136         if ( aEventType == MEikEdwinObserver::EEventTextUpdate ||
       
  1137              aEventType == MEikEdwinObserver::EEventNavigation )
       
  1138             {
       
  1139             iAutoSaver.ReportActivity();
       
  1140 
       
  1141             // Update screen position and scroll bar when text changed
       
  1142             // or cursor moved
       
  1143             UpdateScreenPositionL();
       
  1144             UpdateScrollBar();
       
  1145             DrawDeferred();
       
  1146             }
       
  1147         }
       
  1148     }
       
  1149 
       
  1150 // -----------------------------------------------------------------------------
       
  1151 // CNcsComposeViewContainer::HandleEdwinSizeEventL
       
  1152 // -----------------------------------------------------------------------------
       
  1153 //
       
  1154 TBool CNcsComposeViewContainer::HandleEdwinSizeEventL( CEikEdwin* aEdwin,
       
  1155         TEdwinSizeEvent /*aEventType*/, TSize aDesirableEdwinSize )
       
  1156     {
       
  1157     FUNC_LOG;
       
  1158     TBool ret = ETrue;
       
  1159     
       
  1160     const TRect rect( Rect() );
       
  1161     TRect cmailPaneRect( NcsUtility::ListCmailPaneRect( rect ) );
       
  1162 
       
  1163     if ( aDesirableEdwinSize.iHeight < iPrevDesiredHeigth )
       
  1164         {
       
  1165         if ( aDesirableEdwinSize.iHeight < iMessageEditorMinHeigth )
       
  1166             {
       
  1167             Scroll( 0 );
       
  1168             }
       
  1169         }
       
  1170 
       
  1171     if ( aEdwin == iMessageField ) 
       
  1172         {
       
  1173         if ( aDesirableEdwinSize.iHeight >= iMessageEditorMinHeigth )
       
  1174             {
       
  1175             if ( !iSwitchOffFormattingText )
       
  1176                 {
       
  1177                 aEdwin->SetSize( aDesirableEdwinSize );
       
  1178                 }
       
  1179             }        
       
  1180         }
       
  1181     else
       
  1182         {
       
  1183         if ( !iSwitchOffFormattingText )
       
  1184             {
       
  1185             aEdwin->SetSize( aDesirableEdwinSize );
       
  1186             }
       
  1187         }
       
  1188     if ( aEdwin == iMessageField )
       
  1189         {
       
  1190         // move the quote field below the body field
       
  1191         TPoint quotePos = iMessageField->Position();
       
  1192         quotePos.iY += iMessageField->Size().iHeight;
       
  1193         iReadOnlyQuoteField->SetPosition( quotePos );
       
  1194 		UpdateScreenPositionL(); 
       
  1195         }
       
  1196 
       
  1197     iPrevDesiredHeigth = aDesirableEdwinSize.iHeight;
       
  1198 
       
  1199     return ret;
       
  1200     }
       
  1201 
       
  1202 // -----------------------------------------------------------------------------
       
  1203 // CNcsComposeViewContainer::MopSupplyObject
       
  1204 // From CCoeControl.
       
  1205 // -----------------------------------------------------------------------------
       
  1206 //
       
  1207 TTypeUid::Ptr CNcsComposeViewContainer::MopSupplyObject( TTypeUid aId )
       
  1208     {
       
  1209     FUNC_LOG;
       
  1210     if ( aId.iUid == MAknsControlContext::ETypeId )
       
  1211         {
       
  1212         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
  1213         }
       
  1214     return CCoeControl::MopSupplyObject( aId );
       
  1215     }
       
  1216 
       
  1217 // -----------------------------------------------------------------------------
       
  1218 // CNcsComposeViewContainer::UpdateScrollBar()
       
  1219 // -----------------------------------------------------------------------------
       
  1220 //
       
  1221 void CNcsComposeViewContainer::UpdateScrollBar()
       
  1222     {
       
  1223     FUNC_LOG;
       
  1224 
       
  1225     TRect headerRect = iHeader->Rect();
       
  1226     TInt visiblePosition = -headerRect.iTl.iY;
       
  1227 
       
  1228     iScrollBarModel.SetFocusPosition( visiblePosition );
       
  1229 
       
  1230     iScrollBar->SetModel( &iScrollBarModel );
       
  1231     iScrollBar->MakeVisible( IsVisible() );
       
  1232     }
       
  1233 
       
  1234 // -----------------------------------------------------------------------------
       
  1235 // CNcsComposeViewContainer::SetFocusToMessageFieldL()
       
  1236 // -----------------------------------------------------------------------------
       
  1237 //
       
  1238 void CNcsComposeViewContainer::SetFocusToMessageFieldL()
       
  1239     {
       
  1240     FUNC_LOG;
       
  1241 
       
  1242     if( iFocused != iMessageField )
       
  1243         {
       
  1244         iHeader->SetFocus( EFalse, ENoDrawNow );
       
  1245         iMessageField->SetCursorPosL( 0, EFalse );
       
  1246         iMessageField->SetFocus( ETrue, ENoDrawNow );
       
  1247         iFocused = iMessageField;
       
  1248         UpdateScreenPositionL();
       
  1249         DrawDeferred();
       
  1250         }
       
  1251     }
       
  1252 
       
  1253 // -----------------------------------------------------------------------------
       
  1254 // CNcsComposeViewContainer::AddQuickTextL()
       
  1255 // -----------------------------------------------------------------------------
       
  1256 //
       
  1257 void CNcsComposeViewContainer::AddQuickTextL( const TDesC& aText )
       
  1258     {
       
  1259     FUNC_LOG;
       
  1260 
       
  1261     // If in 'To' field, go to msg. field
       
  1262     if( !iMessageField->IsFocused() )
       
  1263     	{
       
  1264     	SetFocusToMessageFieldL();
       
  1265     	}
       
  1266 	TInt pos = iMessageField->CursorPos();
       
  1267 	TCursorSelection selIns( pos, pos );
       
  1268 	iMessageField->InsertDeleteCharsL( pos, aText, selIns );
       
  1269 	// Fix for error EFTG-7Y63XG, moving cursor to the end of inserted text
       
  1270 	pos += aText.Length();
       
  1271 	iMessageField->SetCursorPosL( pos, EFalse );
       
  1272 	DrawDeferred();
       
  1273 
       
  1274     }
       
  1275 
       
  1276 // -----------------------------------------------------------------------------
       
  1277 // CNcsComposeViewContainer::SelectAllToFieldTextL
       
  1278 //
       
  1279 // -----------------------------------------------------------------------------
       
  1280 //
       
  1281 void CNcsComposeViewContainer::SelectAllToFieldTextL()
       
  1282 	{
       
  1283     FUNC_LOG;
       
  1284 
       
  1285 	iHeader->SelectAllToFieldTextL();
       
  1286 
       
  1287 	}
       
  1288 
       
  1289 // -----------------------------------------------------------------------------
       
  1290 // CNcsComposeViewContainer::SelectAllCcFieldTextL
       
  1291 //
       
  1292 // -----------------------------------------------------------------------------
       
  1293 //
       
  1294 void CNcsComposeViewContainer::SelectAllCcFieldTextL()
       
  1295 	{
       
  1296     FUNC_LOG;
       
  1297 
       
  1298 	iHeader->SelectAllCcFieldTextL();
       
  1299 
       
  1300 	}
       
  1301 
       
  1302 // -----------------------------------------------------------------------------
       
  1303 // CNcsComposeViewContainer::SelectAllBccFieldTextL
       
  1304 //
       
  1305 // -----------------------------------------------------------------------------
       
  1306 //
       
  1307 void CNcsComposeViewContainer::SelectAllBccFieldTextL()
       
  1308 	{
       
  1309     FUNC_LOG;
       
  1310 
       
  1311 	iHeader->SelectAllBccFieldTextL();
       
  1312 
       
  1313 	}
       
  1314 
       
  1315 // -----------------------------------------------------------------------------
       
  1316 // CNcsComposeViewContainer::SelectAllSubjectFieldTextL
       
  1317 //
       
  1318 // -----------------------------------------------------------------------------
       
  1319 //
       
  1320 void CNcsComposeViewContainer::SelectAllSubjectFieldTextL()
       
  1321 	{
       
  1322     FUNC_LOG;
       
  1323 
       
  1324 	iHeader->SelectAllSubjectFieldTextL();
       
  1325 
       
  1326 	}
       
  1327 
       
  1328 // -----------------------------------------------------------------------------
       
  1329 // CNcsComposeViewContainer::IsSubjectFieldEmpty
       
  1330 //
       
  1331 // -----------------------------------------------------------------------------
       
  1332 //
       
  1333 TBool CNcsComposeViewContainer::IsSubjectFieldEmpty()
       
  1334     {
       
  1335     FUNC_LOG;
       
  1336     return iHeader->IsSubjectFieldEmpty();
       
  1337     }
       
  1338 
       
  1339 // -----------------------------------------------------------------------------
       
  1340 // CNcsComposeViewContainer::AppendAddressesL
       
  1341 //
       
  1342 // -----------------------------------------------------------------------------
       
  1343 //
       
  1344 TBool CNcsComposeViewContainer::AppendAddressesL()
       
  1345 	{
       
  1346     FUNC_LOG;
       
  1347 
       
  1348     iContactHandler = CFsDelayedLoader::InstanceL()->GetContactHandlerL();
       
  1349     if ( iContactHandler )
       
  1350         {
       
  1351         iContactHandler->GetAddressesFromPhonebookL( this );
       
  1352         }
       
  1353     
       
  1354 	if ( IsFocusCc() )
       
  1355 		{
       
  1356 		iAppendAddresses = EAppendCc;
       
  1357 		}
       
  1358 	else if ( IsFocusBcc() )
       
  1359 		{
       
  1360 		iAppendAddresses = EAppendBcc;
       
  1361 		}
       
  1362 	else
       
  1363 		{
       
  1364 		iAppendAddresses = EAppendTo;
       
  1365 		}
       
  1366 
       
  1367     return ETrue;
       
  1368 	}
       
  1369 
       
  1370 // -----------------------------------------------------------------------------
       
  1371 // CNcsComposeViewContainer::HandleAttachmentsOpenCommand
       
  1372 // If attachment header field is focused and open key is pressed
       
  1373 // -----------------------------------------------------------------------------
       
  1374 //
       
  1375 void CNcsComposeViewContainer::HandleAttachmentsOpenCommandL()
       
  1376 	{
       
  1377     FUNC_LOG;
       
  1378 
       
  1379 	iView.HandleCommandL( EFsEmailUiCmdOpenAttachment );
       
  1380 
       
  1381 	}
       
  1382 
       
  1383 // -----------------------------------------------------------------------------
       
  1384 // CNcsComposeViewContainer::LaunchStylusPopupMenu
       
  1385 // Called when long tap happens in the attachments field
       
  1386 // -----------------------------------------------------------------------------
       
  1387 //
       
  1388 void CNcsComposeViewContainer::LaunchStylusPopupMenu( const TPoint& aPenEventScreenLocation )
       
  1389     {
       
  1390     FUNC_LOG;
       
  1391     iView.LaunchStylusPopupMenu( aPenEventScreenLocation );
       
  1392     }
       
  1393 
       
  1394 // -----------------------------------------------------------------------------
       
  1395 // CNcsComposeViewContainer::GetToFieldAddressesL
       
  1396 //
       
  1397 // -----------------------------------------------------------------------------
       
  1398 //
       
  1399 const RPointerArray<CNcsEmailAddressObject>& 
       
  1400 CNcsComposeViewContainer::GetToFieldAddressesL( TBool aParseNow )
       
  1401     {
       
  1402     return iHeader->GetToFieldAddressesL( aParseNow );
       
  1403     }
       
  1404 
       
  1405 // -----------------------------------------------------------------------------
       
  1406 // CNcsComposeViewContainer::GetCcFieldAddressesL
       
  1407 //
       
  1408 // -----------------------------------------------------------------------------
       
  1409 //
       
  1410 const RPointerArray<CNcsEmailAddressObject>& 
       
  1411 CNcsComposeViewContainer::GetCcFieldAddressesL( TBool aParseNow )
       
  1412     {
       
  1413     return iHeader->GetCcFieldAddressesL( aParseNow );
       
  1414     }
       
  1415 
       
  1416 // -----------------------------------------------------------------------------
       
  1417 // CNcsComposeViewContainer::GetBccFieldAddressesL
       
  1418 //
       
  1419 // -----------------------------------------------------------------------------
       
  1420 //
       
  1421 const RPointerArray<CNcsEmailAddressObject>& 
       
  1422 CNcsComposeViewContainer::GetBccFieldAddressesL( TBool aParseNow )
       
  1423     {
       
  1424     return iHeader->GetBccFieldAddressesL( aParseNow );
       
  1425     }
       
  1426 
       
  1427 // -----------------------------------------------------------------------------
       
  1428 // CNcsComposeViewContainer::GetSubjectLC
       
  1429 //
       
  1430 // -----------------------------------------------------------------------------
       
  1431 //
       
  1432 HBufC* CNcsComposeViewContainer::GetSubjectLC() const
       
  1433     {
       
  1434     FUNC_LOG;
       
  1435 	return iHeader->GetSubjectLC();
       
  1436     }
       
  1437 
       
  1438 // -----------------------------------------------------------------------------
       
  1439 // CNcsComposeViewContainer::IsBccFieldVisible
       
  1440 //
       
  1441 // -----------------------------------------------------------------------------
       
  1442 //
       
  1443 TBool CNcsComposeViewContainer::IsBccFieldVisible() const
       
  1444     {
       
  1445     FUNC_LOG;
       
  1446     return iHeader->IsBccFieldVisible();
       
  1447     }
       
  1448 
       
  1449 // -----------------------------------------------------------------------------
       
  1450 // CNcsComposeViewContainer::IsCcFieldVisible
       
  1451 //
       
  1452 // -----------------------------------------------------------------------------
       
  1453 //
       
  1454 TBool CNcsComposeViewContainer::IsCcFieldVisible() const
       
  1455     {
       
  1456     FUNC_LOG;
       
  1457     return iHeader->IsCcFieldVisible();
       
  1458     }
       
  1459 
       
  1460 
       
  1461 // -----------------------------------------------------------------------------
       
  1462 // CNcsComposeViewContainer::IsFocusAttachments
       
  1463 //
       
  1464 // -----------------------------------------------------------------------------
       
  1465 //
       
  1466 TBool CNcsComposeViewContainer::IsFocusAttachments() const
       
  1467     {
       
  1468     FUNC_LOG;
       
  1469     return iHeader->IsFocusAttachments();
       
  1470     }
       
  1471 
       
  1472 // -----------------------------------------------------------------------------
       
  1473 // CNcsComposeViewContainer::IsFocusTo
       
  1474 //
       
  1475 // -----------------------------------------------------------------------------
       
  1476 //
       
  1477 TBool CNcsComposeViewContainer::IsFocusTo() const
       
  1478     {
       
  1479     FUNC_LOG;
       
  1480     return iHeader->IsFocusTo();
       
  1481     }
       
  1482 
       
  1483 // -----------------------------------------------------------------------------
       
  1484 // CNcsComposeViewContainer::IsFocusCc
       
  1485 //
       
  1486 // -----------------------------------------------------------------------------
       
  1487 //
       
  1488 TBool CNcsComposeViewContainer::IsFocusCc() const
       
  1489     {
       
  1490     FUNC_LOG;
       
  1491     return iHeader->IsFocusCc();
       
  1492     }
       
  1493 
       
  1494 // -----------------------------------------------------------------------------
       
  1495 // CNcsComposeViewContainer::IsFocusBcc
       
  1496 //
       
  1497 // -----------------------------------------------------------------------------
       
  1498 //
       
  1499 TBool CNcsComposeViewContainer::IsFocusBcc() const
       
  1500     {
       
  1501     FUNC_LOG;
       
  1502     return iHeader->IsFocusBcc();
       
  1503     }
       
  1504 
       
  1505 // -----------------------------------------------------------------------------
       
  1506 // CNcsComposeViewContainer::GetCcFieldLength
       
  1507 //
       
  1508 // -----------------------------------------------------------------------------
       
  1509 //
       
  1510 TInt CNcsComposeViewContainer::GetCcFieldLength() const
       
  1511     {
       
  1512     FUNC_LOG;
       
  1513 	return iHeader->GetCcFieldLength();
       
  1514     }
       
  1515 
       
  1516 // -----------------------------------------------------------------------------
       
  1517 // CNcsComposeViewContainer::GetBccFieldLength
       
  1518 //
       
  1519 // -----------------------------------------------------------------------------
       
  1520 //
       
  1521 TInt CNcsComposeViewContainer::GetBccFieldLength() const
       
  1522     {
       
  1523     FUNC_LOG;
       
  1524 	return iHeader->GetBccFieldLength();
       
  1525     }
       
  1526 
       
  1527 // -----------------------------------------------------------------------------
       
  1528 // CNcsComposeViewContainer::GetToFieldLength
       
  1529 //
       
  1530 // -----------------------------------------------------------------------------
       
  1531 //
       
  1532 TInt CNcsComposeViewContainer::GetToFieldLength() const
       
  1533     {
       
  1534     FUNC_LOG;
       
  1535 	return iHeader->GetToFieldLength();
       
  1536     }
       
  1537 
       
  1538 // -----------------------------------------------------------------------------
       
  1539 // CNcsComposeViewContainer::GetSubjectFieldLength
       
  1540 //
       
  1541 // -----------------------------------------------------------------------------
       
  1542 //
       
  1543 TInt CNcsComposeViewContainer::GetSubjectFieldLength() const
       
  1544     {
       
  1545     FUNC_LOG;
       
  1546 	return iHeader->GetSubjectFieldLength();
       
  1547     }
       
  1548 
       
  1549 // -----------------------------------------------------------------------------
       
  1550 // CNcsComposeViewContainer::GetMessageFieldLength
       
  1551 //
       
  1552 // -----------------------------------------------------------------------------
       
  1553 //
       
  1554 TInt CNcsComposeViewContainer::GetMessageFieldLength() const
       
  1555     {
       
  1556     FUNC_LOG;
       
  1557 	return iMessageField->TextLength();
       
  1558     }
       
  1559 
       
  1560 // -----------------------------------------------------------------------------
       
  1561 // CNcsComposeViewContainer::GetAttachmentCount
       
  1562 //
       
  1563 // -----------------------------------------------------------------------------
       
  1564 //
       
  1565 TInt CNcsComposeViewContainer::GetAttachmentCount() const
       
  1566     {
       
  1567     FUNC_LOG;
       
  1568     TInt count = iView.AttachmentsListControl()->Model()->Count();
       
  1569 	return count;
       
  1570     }
       
  1571 
       
  1572 // -----------------------------------------------------------------------------
       
  1573 // CNcsComposeViewContainer::HasRemoteAttachments
       
  1574 //
       
  1575 // -----------------------------------------------------------------------------
       
  1576 //
       
  1577 TBool CNcsComposeViewContainer::HasRemoteAttachments() const
       
  1578     {
       
  1579     FUNC_LOG;
       
  1580     TBool ret = iView.AttachmentsListControl()->Model()->HasRemoteAttachments();
       
  1581     return ret;
       
  1582     }
       
  1583 
       
  1584 // -----------------------------------------------------------------------------
       
  1585 // CNcsComposeViewContainer::GetLookupTextLC
       
  1586 //
       
  1587 // -----------------------------------------------------------------------------
       
  1588 //
       
  1589 HBufC* CNcsComposeViewContainer::GetLookupTextLC() const
       
  1590     {
       
  1591     FUNC_LOG;
       
  1592 	return iHeader->GetLookupTextLC();
       
  1593     }
       
  1594 
       
  1595 // -----------------------------------------------------------------------------
       
  1596 // CNcsComposeViewContainer::GetToFieldSelectionLength
       
  1597 //
       
  1598 // -----------------------------------------------------------------------------
       
  1599 //
       
  1600 TInt CNcsComposeViewContainer::GetToFieldSelectionLength() const
       
  1601     {
       
  1602     FUNC_LOG;
       
  1603 	return iHeader->GetToFieldSelectionLength();
       
  1604     }
       
  1605 
       
  1606 // -----------------------------------------------------------------------------
       
  1607 // CNcsComposeViewContainer::GetCcFieldSelectionLength
       
  1608 //
       
  1609 // -----------------------------------------------------------------------------
       
  1610 //
       
  1611 TInt CNcsComposeViewContainer::GetCcFieldSelectionLength() const
       
  1612     {
       
  1613     FUNC_LOG;
       
  1614 	return iHeader->GetCcFieldSelectionLength();
       
  1615     }
       
  1616 
       
  1617 // -----------------------------------------------------------------------------
       
  1618 // CNcsComposeViewContainer::GetBccFieldSelectionLength
       
  1619 //
       
  1620 // -----------------------------------------------------------------------------
       
  1621 //
       
  1622 TInt CNcsComposeViewContainer::GetBccFieldSelectionLength() const
       
  1623     {
       
  1624     FUNC_LOG;
       
  1625 	return iHeader->GetBccFieldSelectionLength();
       
  1626     }
       
  1627 
       
  1628 // -----------------------------------------------------------------------------
       
  1629 // CNcsComposeViewContainer::SetMenuBar
       
  1630 //
       
  1631 // -----------------------------------------------------------------------------
       
  1632 //
       
  1633 void CNcsComposeViewContainer::SetMenuBar( CEikButtonGroupContainer* aMenuBar )
       
  1634     {
       
  1635     FUNC_LOG;
       
  1636 
       
  1637 	iHeader->SetMenuBar(aMenuBar);
       
  1638     }
       
  1639 
       
  1640 // -----------------------------------------------------------------------------
       
  1641 // CNcsComposeViewContainer::SetToFieldAddressesL
       
  1642 //
       
  1643 // -----------------------------------------------------------------------------
       
  1644 //
       
  1645 void CNcsComposeViewContainer::SetToFieldAddressesL( 
       
  1646         RPointerArray<CNcsEmailAddressObject>& aAddress )
       
  1647     {
       
  1648     FUNC_LOG;
       
  1649 
       
  1650     iHeader->SetToFieldAddressesL(aAddress);
       
  1651     }
       
  1652 
       
  1653 // -----------------------------------------------------------------------------
       
  1654 // CNcsComposeViewContainer::SetCcFieldAddressesL
       
  1655 //
       
  1656 // -----------------------------------------------------------------------------
       
  1657 //
       
  1658 void CNcsComposeViewContainer::SetCcFieldAddressesL( 
       
  1659         RPointerArray<CNcsEmailAddressObject>& aAddress )
       
  1660     {
       
  1661     FUNC_LOG;
       
  1662 
       
  1663     iHeader->SetCcFieldAddressesL( aAddress );
       
  1664     }
       
  1665 
       
  1666 // -----------------------------------------------------------------------------
       
  1667 // CNcsComposeViewContainer::SetBccFieldAddressesL
       
  1668 //
       
  1669 // -----------------------------------------------------------------------------
       
  1670 //
       
  1671 void CNcsComposeViewContainer::SetBccFieldAddressesL( 
       
  1672         RPointerArray<CNcsEmailAddressObject>& aAddress )
       
  1673     {
       
  1674     FUNC_LOG;
       
  1675 
       
  1676     iHeader->SetBccFieldAddressesL( aAddress );
       
  1677 
       
  1678     }
       
  1679 
       
  1680 // -----------------------------------------------------------------------------
       
  1681 // CNcsComposeViewContainer::AppendToFieldAddressesL
       
  1682 //
       
  1683 // -----------------------------------------------------------------------------
       
  1684 //
       
  1685 void CNcsComposeViewContainer::AppendToFieldAddressesL( RPointerArray<CNcsEmailAddressObject>& aAddresses )
       
  1686     {
       
  1687     FUNC_LOG;
       
  1688     FixSemicolonL();
       
  1689     iHeader->AppendToFieldAddressesL(aAddresses);
       
  1690 
       
  1691     }
       
  1692 
       
  1693 // -----------------------------------------------------------------------------
       
  1694 // CNcsComposeViewContainer::AppendCcFieldAddressesL
       
  1695 //
       
  1696 // -----------------------------------------------------------------------------
       
  1697 //
       
  1698 void CNcsComposeViewContainer::AppendCcFieldAddressesL( RPointerArray<CNcsEmailAddressObject>& aAddress )
       
  1699     {
       
  1700     FUNC_LOG;
       
  1701     FixSemicolonL();
       
  1702     iHeader->AppendCcFieldAddressesL( aAddress );
       
  1703 
       
  1704     }
       
  1705 
       
  1706 // -----------------------------------------------------------------------------
       
  1707 // CNcsComposeViewContainer::AppendBccFieldAddressesL
       
  1708 //
       
  1709 // -----------------------------------------------------------------------------
       
  1710 //
       
  1711 void CNcsComposeViewContainer::AppendBccFieldAddressesL( RPointerArray<CNcsEmailAddressObject>& aAddress )
       
  1712     {
       
  1713     FUNC_LOG;
       
  1714     FixSemicolonL();
       
  1715     iHeader->AppendBccFieldAddressesL( aAddress );
       
  1716 
       
  1717     }
       
  1718 
       
  1719 // -----------------------------------------------------------------------------
       
  1720 // CNcsComposeViewContainer::SetSubjectL
       
  1721 //
       
  1722 // -----------------------------------------------------------------------------
       
  1723 //
       
  1724 void CNcsComposeViewContainer::SetSubjectL( const TDesC& aSubject )
       
  1725     {
       
  1726     FUNC_LOG;
       
  1727 
       
  1728     iHeader->SetSubjectL( aSubject );
       
  1729 
       
  1730     }
       
  1731 
       
  1732 // -----------------------------------------------------------------------------
       
  1733 // CNcsComposeViewContainer::SetAttachmentLabelTextsLD
       
  1734 //
       
  1735 // -----------------------------------------------------------------------------
       
  1736 //
       
  1737 void CNcsComposeViewContainer::SetAttachmentLabelTextsLD( 
       
  1738     CDesCArray* aAttachmentNames, CDesCArray* aAttachmentSizes )
       
  1739     {
       
  1740     FUNC_LOG;   
       
  1741     iHeader->SetAttachmentLabelTextsLD( aAttachmentNames, aAttachmentSizes );
       
  1742     }
       
  1743 
       
  1744 // -----------------------------------------------------------------------------
       
  1745 // CNcsComposeViewContainer::FocusedAttachmentLabelIndex
       
  1746 //
       
  1747 // -----------------------------------------------------------------------------
       
  1748 //
       
  1749 TInt CNcsComposeViewContainer::FocusedAttachmentLabelIndex()
       
  1750     {
       
  1751     FUNC_LOG;   
       
  1752     return iHeader->FocusedAttachmentLabelIndex();
       
  1753     }
       
  1754 
       
  1755 // -----------------------------------------------------------------------------
       
  1756 // CNcsComposeViewContainer::HideAttachmentLabel
       
  1757 //
       
  1758 // -----------------------------------------------------------------------------
       
  1759 //
       
  1760 void CNcsComposeViewContainer::HideAttachmentLabel()
       
  1761     {
       
  1762     FUNC_LOG;
       
  1763 
       
  1764 	iHeader->HideAttachmentLabel();
       
  1765 
       
  1766     }
       
  1767 
       
  1768 // -----------------------------------------------------------------------------
       
  1769 // CNcsComposeViewContainer::SetCcFieldVisibleL
       
  1770 //
       
  1771 // -----------------------------------------------------------------------------
       
  1772 //
       
  1773 void CNcsComposeViewContainer::SetCcFieldVisibleL( TBool aVisible, TBool aFocus )
       
  1774 	{
       
  1775     FUNC_LOG;
       
  1776 
       
  1777 	if ( aFocus )
       
  1778 		{
       
  1779 		iMessageField->SetCursorPosL( 0,EFalse );
       
  1780 		iMessageField->SetFocus( EFalse );
       
  1781 		iHeader->MakeVisible( ETrue );
       
  1782 		iHeader->SetFocus( ETrue );
       
  1783 		iFocused = iHeader;
       
  1784 		}
       
  1785 	iHeader->SetCcFieldVisibleL( aVisible, EDrawNow, aFocus );
       
  1786 
       
  1787 	}
       
  1788 
       
  1789 // -----------------------------------------------------------------------------
       
  1790 // CNcsComposeViewContainer::SetBccFieldVisibleL
       
  1791 //
       
  1792 // -----------------------------------------------------------------------------
       
  1793 //
       
  1794 void CNcsComposeViewContainer::SetBccFieldVisibleL( TBool aVisible, TBool aFocus )
       
  1795 	{
       
  1796     FUNC_LOG;
       
  1797 
       
  1798 	if ( aFocus )
       
  1799 		{
       
  1800 		iMessageField->SetCursorPosL( 0, EFalse );
       
  1801 		iMessageField->SetFocus( EFalse );
       
  1802 		iHeader->MakeVisible( ETrue );
       
  1803 		iHeader->SetFocus( ETrue );
       
  1804 		iFocused = iHeader;
       
  1805 		}
       
  1806 	iHeader->SetBccFieldVisibleL( aVisible, EDrawNow, aFocus );
       
  1807 
       
  1808 	}
       
  1809 
       
  1810 // -----------------------------------------------------------------------------
       
  1811 // CNcsComposeViewContainer::IncludeAddressL
       
  1812 //
       
  1813 // -----------------------------------------------------------------------------
       
  1814 //
       
  1815 void CNcsComposeViewContainer::IncludeAddressL(const CNcsEmailAddressObject& eml)
       
  1816     {
       
  1817     FUNC_LOG;
       
  1818 
       
  1819 	iHeader->IncludeAddressL(eml);
       
  1820 
       
  1821     }
       
  1822 
       
  1823 // -----------------------------------------------------------------------------
       
  1824 // CNcsComposeViewContainer::IncludeAddressL
       
  1825 //
       
  1826 // -----------------------------------------------------------------------------
       
  1827 //
       
  1828 void CNcsComposeViewContainer::IncludeAddressL()
       
  1829     {
       
  1830     FUNC_LOG;
       
  1831 
       
  1832 	iHeader->IncludeAddressL();
       
  1833 
       
  1834     }
       
  1835 
       
  1836 // -----------------------------------------------------------------------------
       
  1837 // CNcsComposeViewContainer::ClosePopupContactListL
       
  1838 //
       
  1839 // -----------------------------------------------------------------------------
       
  1840 //
       
  1841 void CNcsComposeViewContainer::ClosePopupContactListL()
       
  1842     {
       
  1843     FUNC_LOG;
       
  1844 
       
  1845 	iHeader->ClosePopupContactListL();
       
  1846 
       
  1847     }
       
  1848 
       
  1849 // -----------------------------------------------------------------------------
       
  1850 // CNcsComposeViewContainer::DeleteSelectionL
       
  1851 //
       
  1852 // -----------------------------------------------------------------------------
       
  1853 //
       
  1854 void CNcsComposeViewContainer::DeleteSelectionL()
       
  1855     {
       
  1856     FUNC_LOG;
       
  1857 
       
  1858 	iHeader->DeleteSelectionL();
       
  1859 
       
  1860     }
       
  1861 
       
  1862 // -----------------------------------------------------------------------------
       
  1863 // CNcsComposeViewContainer::SetFocusToToField
       
  1864 //
       
  1865 // -----------------------------------------------------------------------------
       
  1866 //
       
  1867 void CNcsComposeViewContainer::SetFocusToToField()
       
  1868 	{
       
  1869     FUNC_LOG;
       
  1870 
       
  1871 	iHeader->FocusToField();
       
  1872 
       
  1873 	}
       
  1874 
       
  1875 // -----------------------------------------------------------------------------
       
  1876 // CNcsComposeViewContainer::SetFocusToAttachmentField
       
  1877 //
       
  1878 // -----------------------------------------------------------------------------
       
  1879 //
       
  1880 void CNcsComposeViewContainer::SetFocusToAttachmentField()
       
  1881 	{
       
  1882     FUNC_LOG;
       
  1883 
       
  1884 	if ( iFocused == iMessageField )
       
  1885     	{
       
  1886 		iFocused = iHeader;
       
  1887 		iHeader->SetFocus( ETrue, EDrawNow );
       
  1888 		iMessageField->SetFocus( EFalse, EDrawNow );
       
  1889 		iHeader->MakeVisible( ETrue );
       
  1890     	}
       
  1891 	iHeader->FocusAttachmentField();
       
  1892 	}
       
  1893 
       
  1894 // -----------------------------------------------------------------------------
       
  1895 // CNcsComposeViewContainer::AreAddressFieldsEmpty
       
  1896 //
       
  1897 // -----------------------------------------------------------------------------
       
  1898 //
       
  1899 TBool CNcsComposeViewContainer::AreAddressFieldsEmpty()
       
  1900 	{
       
  1901     FUNC_LOG;
       
  1902 	return iHeader->AreAddressFieldsEmpty();
       
  1903 	}
       
  1904 
       
  1905 // -----------------------------------------------------------------------------
       
  1906 // CNcsComposeViewContainer::DoPopupSelectL
       
  1907 //
       
  1908 // -----------------------------------------------------------------------------
       
  1909 //
       
  1910 void CNcsComposeViewContainer::DoPopupSelectL()
       
  1911 	{
       
  1912     FUNC_LOG;
       
  1913 
       
  1914 	iHeader->DoPopupSelectL();
       
  1915 
       
  1916 	}
       
  1917 
       
  1918 // -----------------------------------------------------------------------------
       
  1919 // CNcsComposeViewContainer::HandleLayoutChangeL
       
  1920 //
       
  1921 // -----------------------------------------------------------------------------
       
  1922 //
       
  1923 void CNcsComposeViewContainer::HandleLayoutChangeL()
       
  1924     {
       
  1925     FUNC_LOG;
       
  1926     SetRect( iView.ClientRect() );
       
  1927     if ( iHeader )
       
  1928         {
       
  1929         iHeader->HandleDynamicVariantSwitchL();
       
  1930         }
       
  1931     // force recalculation of the position of every component
       
  1932     UpdateFieldPosition( NULL );
       
  1933     UpdateScrollBar();
       
  1934     }
       
  1935 
       
  1936 // -----------------------------------------------------------------------------
       
  1937 // CNcsComposeViewContainer::HandleSkinChangeL
       
  1938 //
       
  1939 // -----------------------------------------------------------------------------
       
  1940 //
       
  1941 void CNcsComposeViewContainer::HandleSkinChangeL()
       
  1942     {
       
  1943     FUNC_LOG;
       
  1944     if ( iHeader )
       
  1945         {
       
  1946         iHeader->HandleSkinChangeL();
       
  1947         }
       
  1948 
       
  1949     if ( iMessageField )
       
  1950         {
       
  1951         iMessageField->UpdateFontSize();
       
  1952         }
       
  1953 
       
  1954     if ( iScrollBar )
       
  1955         {
       
  1956         iScrollBar->HandleResourceChange( KAknsMessageSkinChange );
       
  1957         iScrollBar->DrawNow();
       
  1958         }
       
  1959     }
       
  1960 
       
  1961 // -----------------------------------------------------------------------------
       
  1962 // CNcsComposeViewContainer::ContentTotalHeight
       
  1963 // Return the total height of the components shown in the view
       
  1964 // -----------------------------------------------------------------------------
       
  1965 //
       
  1966 TInt CNcsComposeViewContainer::ContentTotalHeight()
       
  1967     {
       
  1968     FUNC_LOG;	
       
  1969 	TInt totalHeight( iHeader->Size().iHeight + 
       
  1970 	                  iSeparatorHeight * 2 + 
       
  1971 					  iMessageField->Size().iHeight );
       
  1972 
       
  1973 	if( iReadOnlyQuoteField->IsVisible() )
       
  1974 		{
       
  1975 		totalHeight += iReadOnlyQuoteField->Size().iHeight;
       
  1976 		}	
       
  1977 	
       
  1978 	return totalHeight;
       
  1979     }
       
  1980 
       
  1981 // -----------------------------------------------------------------------------
       
  1982 // CNcsComposeViewContainer::CommitL()
       
  1983 //
       
  1984 // -----------------------------------------------------------------------------
       
  1985 //
       
  1986 void CNcsComposeViewContainer::CommitL( TFieldToCommit aFieldToCommit )
       
  1987     {
       
  1988     FUNC_LOG;
       
  1989     iView.CommitL( ETrue, aFieldToCommit );
       
  1990     iView.HandleContainerChangeRequiringToolbarRefresh();
       
  1991     }
       
  1992 
       
  1993 // -----------------------------------------------------------------------------
       
  1994 // CNcsComposeViewContainer::SwitchChangeMskOff
       
  1995 // sets up iSwitchChangeMskOff falg, which disables changes of MSK label if
       
  1996 // any popup dialog is open
       
  1997 // -----------------------------------------------------------------------------
       
  1998 void CNcsComposeViewContainer::SwitchChangeMskOff(TBool aTag)
       
  1999     {
       
  2000     FUNC_LOG;
       
  2001     iHeader->SwitchChangeMskOff( aTag );
       
  2002     }
       
  2003 
       
  2004 // -----------------------------------------------------------------------------
       
  2005 // CNcsHeaderContainer::HandleLongTapEventL()
       
  2006 // Handles key events
       
  2007 // -----------------------------------------------------------------------------
       
  2008 void CNcsComposeViewContainer::HandleLongTapEventL( 
       
  2009         const TPoint& aPenEventLocation, 
       
  2010         const TPoint& aPenEventScreenLocation )
       
  2011     {
       
  2012     FUNC_LOG;
       
  2013     iHeader->HandleLongTap( aPenEventLocation, aPenEventScreenLocation );
       
  2014     }
       
  2015 
       
  2016 
       
  2017 void CNcsComposeViewContainer::FixSemicolonL()
       
  2018 	{
       
  2019     FUNC_LOG;
       
  2020 	iHeader->FixSemicolonInAddressFieldsL();
       
  2021 	}
       
  2022 
       
  2023 // ---------------------------------------------------------------------------
       
  2024 // CNcsComposeViewContainer::UpdatePhysicsL()
       
  2025 // ---------------------------------------------------------------------------
       
  2026 //
       
  2027 void CNcsComposeViewContainer::UpdatePhysicsL()
       
  2028     {
       
  2029     FUNC_LOG;
       
  2030     if ( iPhysics )
       
  2031         {
       
  2032         const TSize viewSize( Rect().Size() );
       
  2033         // We must ensure that world size is at least the size of the view
       
  2034         const TSize worldSize( viewSize.iWidth, 
       
  2035                 Max( ContentTotalHeight(), viewSize.iHeight ) );
       
  2036         iPhysics->InitPhysicsL( worldSize, viewSize, EFalse );
       
  2037         }
       
  2038     }
       
  2039 
       
  2040 // -----------------------------------------------------------------------------
       
  2041 // CNcsComposeViewContainer::Scroll()
       
  2042 // -----------------------------------------------------------------------------
       
  2043 //
       
  2044 void CNcsComposeViewContainer::Scroll( TInt aTargetPos, TBool aDrawNow )
       
  2045     {
       
  2046     FUNC_LOG;
       
  2047 	TPoint headerPos( iHeader->Position() );
       
  2048 	TInt moveY = -headerPos.iY - aTargetPos;
       
  2049 	
       
  2050     if ( aDrawNow )
       
  2051     	{
       
  2052 		moveY = iTotalMoveY + moveY;
       
  2053 		iTotalMoveY = 0;
       
  2054 		if ( moveY )
       
  2055 			{
       
  2056 			headerPos.iY += moveY;
       
  2057 			iHeader->SetPosition( headerPos );
       
  2058 
       
  2059 			// set header invisible if it is not in visible area
       
  2060 			// this is done to prevent drawing of header when it is not necessary
       
  2061             if ( headerPos.iY + iHeaderHeight <= KHeaderVisibilityThreshold && iHeader->IsVisible() )
       
  2062                 {            
       
  2063                 iHeader->MakeVisible( EFalse );
       
  2064                 }
       
  2065             // set header visible if it is in visible area
       
  2066             else if ( headerPos.iY + iHeaderHeight > KHeaderVisibilityThreshold && !iHeader->IsVisible() ) 
       
  2067                 {
       
  2068                 iHeader->MakeVisible( ETrue );
       
  2069                 }
       
  2070     
       
  2071 			TPoint msgPos( iMessageField->Position() );
       
  2072 			msgPos.iY += moveY;
       
  2073 			iMessageField->SetPosition( msgPos );
       
  2074 	
       
  2075 			if( iReadOnlyQuoteField->IsVisible() )
       
  2076 				{
       
  2077 				TPoint readOnlyPos( iReadOnlyQuoteField->Position() );
       
  2078 				readOnlyPos.iY += moveY;
       
  2079 				iReadOnlyQuoteField->SetPosition( readOnlyPos );
       
  2080 				}
       
  2081 	
       
  2082 			iSeparatorLineYPos += moveY;
       
  2083 
       
  2084 			UpdateScrollBar();
       
  2085 			DrawDeferred();
       
  2086 			}
       
  2087     	}
       
  2088     else
       
  2089     	{
       
  2090 		iTotalMoveY += moveY;
       
  2091     	}    	
       
  2092     }
       
  2093 
       
  2094 // -----------------------------------------------------------------------------
       
  2095 // CNcsComposeViewContainer::ViewPositionChanged
       
  2096 // From MAknPhysicsObserver
       
  2097 // -----------------------------------------------------------------------------
       
  2098 //
       
  2099 void CNcsComposeViewContainer::ViewPositionChanged(
       
  2100     const TPoint& aNewPosition, TBool aDrawNow, TUint /*aFlags*/ )
       
  2101     {
       
  2102     FUNC_LOG;
       
  2103     TInt scrollOffset = aNewPosition.iY - iVisibleAreaHeight / 2;
       
  2104 
       
  2105     // when the composer view is overlapped by other view for instance task switcher or screensaver
       
  2106     // physics sends a faulty event to move the composer view down. 
       
  2107     // This action is ignored here.	
       
  2108     if (aNewPosition.iY != 0)
       
  2109         {
       
  2110         Scroll( scrollOffset, aDrawNow );
       
  2111         }
       
  2112     }
       
  2113 
       
  2114 // -----------------------------------------------------------------------------
       
  2115 // CNcsComposeViewContainer::PhysicEmulationEnded
       
  2116 // From MAknPhysicsObserver
       
  2117 // -----------------------------------------------------------------------------
       
  2118 //
       
  2119 void CNcsComposeViewContainer::PhysicEmulationEnded()
       
  2120     {
       
  2121     FUNC_LOG;
       
  2122     iIsFlicking = EFalse;
       
  2123     iMessageField->SetPhysicsEmulationOngoing( EFalse );
       
  2124     iReadOnlyQuoteField->SetPhysicsEmulationOngoing( EFalse );
       
  2125     iHeader->SetPhysicsEmulationOngoing( EFalse );
       
  2126     }
       
  2127 
       
  2128 // -----------------------------------------------------------------------------
       
  2129 // CNcsComposeViewContainer::ViewPosition
       
  2130 // From MAknPhysicsObserver
       
  2131 // -----------------------------------------------------------------------------
       
  2132 //
       
  2133 TPoint CNcsComposeViewContainer::ViewPosition() const
       
  2134     {
       
  2135     FUNC_LOG;
       
  2136     return TPoint(0, -iHeader->Position().iY  + iVisibleAreaHeight / 2 );
       
  2137     }
       
  2138 
       
  2139 
       
  2140 // -----------------------------------------------------------------------------
       
  2141 // CNcsComposeViewContainer::IsRemoteSearchInprogress
       
  2142 // -----------------------------------------------------------------------------
       
  2143 //
       
  2144 TBool CNcsComposeViewContainer::IsRemoteSearchInprogress() const
       
  2145     {
       
  2146     FUNC_LOG;
       
  2147     return iHeader->IsRemoteSearchInprogress();
       
  2148     }