emailuis/emailui/src/ncscomposeviewcontainer.cpp
branchRCL_3
changeset 73 c8382f7b54ef
parent 70 968773a0b6ef
child 80 726fba06891a
equal deleted inserted replaced
70:968773a0b6ef 73:c8382f7b54ef
   146     CleanupStack::Pop( iReadOnlyQuoteField );
   146     CleanupStack::Pop( iReadOnlyQuoteField );
   147 
   147 
   148     // Listen edwin events and size events from smart quote field
   148     // Listen edwin events and size events from smart quote field
   149     iReadOnlyQuoteField->AddEdwinObserverL( this );
   149     iReadOnlyQuoteField->AddEdwinObserverL( this );
   150     iReadOnlyQuoteField->SetEdwinSizeObserver( this );
   150     iReadOnlyQuoteField->SetEdwinSizeObserver( this );
   151    iReadOnlyQuoteField->EnableKineticScrollingL( iPhysics );
   151     iReadOnlyQuoteField->EnableKineticScrollingL( iPhysics );
   152 
   152 
   153     // Create the scroll bar
   153     // Create the scroll bar
   154     iScrollBar = new( ELeave ) CAknDoubleSpanScrollBar( this );
   154     iScrollBar = new( ELeave ) CAknDoubleSpanScrollBar( this );
   155     iScrollBar->ConstructL( ETrue, this, this, CEikScrollBar::EVertical,
   155     iScrollBar->ConstructL( ETrue, this, this, CEikScrollBar::EVertical,
   156         aRect.Height() );
   156         aRect.Height() );
   197     if ( iAsyncTextFormatter )
   197     if ( iAsyncTextFormatter )
   198         {
   198         {
   199         iAsyncTextFormatter->Cancel();
   199         iAsyncTextFormatter->Cancel();
   200         delete iAsyncTextFormatter;
   200         delete iAsyncTextFormatter;
   201         }
   201         }
   202     
   202 
   203     if ( iContactHandler )
   203     if ( iContactHandler )
   204         {
   204         {
   205         iContactHandler->ClearObservers();
   205         iContactHandler->ClearObservers();
   206         }
   206         }
   207 	delete iHeader;
   207     delete iHeader;
   208     delete iScrollBar;
   208     delete iScrollBar;
   209     delete iMessageField;
   209     delete iMessageField;
   210     delete iBgContext;
   210     delete iBgContext;
   211 	delete iLongTapDetector;
   211     delete iLongTapDetector;
   212     delete iReadOnlyQuoteField;
   212     delete iReadOnlyQuoteField;
   213     delete iReadOnlyQuote;
   213     delete iReadOnlyQuote;
   214 
   214 
   215     delete iPhysics;
   215     delete iPhysics;
   216     iPhysics = NULL;
   216     iPhysics = NULL;
   224 //
   224 //
   225 void CNcsComposeViewContainer::FocusChanged( TDrawNow aDrawNow )
   225 void CNcsComposeViewContainer::FocusChanged( TDrawNow aDrawNow )
   226     {
   226     {
   227     FUNC_LOG;
   227     FUNC_LOG;
   228 
   228 
   229 	if ( iFocused != iHeader &&
   229     if ( iFocused != iHeader &&
   230 	     iFocused != iMessageField &&
   230          iFocused != iMessageField &&
   231 	     iFocused != iReadOnlyQuoteField )
   231          iFocused != iReadOnlyQuoteField )
   232         {
   232         {
   233 		iFocused = iHeader;
   233         iFocused = iHeader;
   234         }
   234         }
   235     if ( iFocused == iHeader )
   235 
   236         {
   236     iFocused->SetFocus( IsFocused(), aDrawNow );
   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();
   237     iView.HandleContainerChangeRequiringToolbarRefresh();
   250 
   238 
   251 	if ( aDrawNow )
   239     if ( aDrawNow )
   252 	    {
   240         {
   253 		DrawNow();
   241         DrawNow();
   254 	    }
   242         }
   255 
       
   256     }
   243     }
   257 // -----------------------------------------------------------------------------
   244 // -----------------------------------------------------------------------------
   258 // CNcsComposeViewContainer::SetMskL()
   245 // CNcsComposeViewContainer::SetMskL()
   259 //
   246 //
   260 // -----------------------------------------------------------------------------
   247 // -----------------------------------------------------------------------------
   272 //
   259 //
   273 void CNcsComposeViewContainer::HandlePointerEventL( 
   260 void CNcsComposeViewContainer::HandlePointerEventL( 
   274         const TPointerEvent& aPointerEvent )
   261         const TPointerEvent& aPointerEvent )
   275     {
   262     {
   276     FUNC_LOG;
   263     FUNC_LOG;
   277 	TBool clearSelection(EFalse);
   264     TBool clearSelection(EFalse);
   278     if ( aPointerEvent.iType != TPointerEvent::EButton1Down &&
   265     if ( aPointerEvent.iType != TPointerEvent::EButton1Down &&
   279          iHeader->NeedsLongTapL( aPointerEvent.iPosition ) )
   266             iHeader->NeedsLongTapL( aPointerEvent.iPosition ) )
   280         {
   267         {
   281     	iLongTapDetector->PointerEventL( aPointerEvent );
   268         iLongTapDetector->PointerEventL( aPointerEvent );
   282         }
   269         }
   283 	   
   270 
   284     switch( aPointerEvent.iType )
   271     switch( aPointerEvent.iType )
   285     	{
   272         {
   286     	case TPointerEvent::EButton1Down:
   273         case TPointerEvent::EButton1Down:
   287     		{
   274             {
   288             // Save current and original position so that those can be used in
   275             // Save current and original position so that those can be used in
   289             // drag/scrolling calculations
   276             // drag/scrolling calculations
   290             iPreviousPosition = iOriginalPosition = 
   277             iPreviousPosition = iOriginalPosition = aPointerEvent.iPosition;
   291                 aPointerEvent.iPosition;
       
   292             iIsDragging = EFalse;
   278             iIsDragging = EFalse;
   293             iIsFlicking = EFalse;
   279             iIsFlicking = EFalse;
   294 
   280 
   295             if( iPhysics )
   281             if( iPhysics )
   296                 {
   282                 {
   297                 iPhysics->StopPhysics();
   283                 iPhysics->StopPhysics();
   298                 iPhysics->ResetFriction();
   284                 iPhysics->ResetFriction();
   299                 iStartTime.HomeTime();
   285                 iStartTime.HomeTime();
   300                 UpdatePhysicsL();
   286                 UpdatePhysicsL();
   301                 }            
   287                 }
   302 
   288 
   303             if ( iHeader->Rect().Contains( aPointerEvent.iPosition ) )
   289             if ( iHeader->Rect().Contains( aPointerEvent.iPosition ) )
   304                 {
   290                 {
   305                 if ( iFocused == iMessageField )
   291                 if ( iFocused == iMessageField )
   306                     {
   292                     {
   307 					if( iMessageField->SelectionLength() )
   293                     if( iMessageField->SelectionLength() )
   308 						{
   294                         {
   309 						iMessageField->ClearSelectionL();
   295                         iMessageField->ClearSelectionL();
   310 						}
   296                         }
   311                     iMessageField->SetFocus( EFalse, ENoDrawNow );
   297                     iMessageField->SetFocus( EFalse, ENoDrawNow );
   312                     iFocused = iHeader;
   298                     iFocused = iHeader;
   313                     iHeader->SetFocus( ETrue,ENoDrawNow );
   299                     iHeader->SetFocus( ETrue, ENoDrawNow );
   314                     }
   300                     }
   315                 else if ( iFocused == iReadOnlyQuoteField )
   301                 else if ( iFocused == iReadOnlyQuoteField )
   316                     {
   302                     {
   317                     iReadOnlyQuoteField->SetFocus( EFalse, ENoDrawNow );
   303                     iReadOnlyQuoteField->SetFocus( EFalse, ENoDrawNow );
   318                     iFocused = iHeader;
   304                     iFocused = iHeader;
   393 
   379 
   394             // Get current pointer position
   380             // Get current pointer position
   395             TPoint position = aPointerEvent.iPosition;
   381             TPoint position = aPointerEvent.iPosition;
   396 
   382 
   397 
   383 
   398            if( iPhysics )
   384             if ( iPhysics )
   399                {
   385                 {
   400 			   if ( iIsDragging )
   386                 if ( iIsDragging )
   401 				   {
   387                     {
   402                     TPoint delta( 0, iPreviousPosition.iY - position.iY );
   388                     TPoint delta( 0, iPreviousPosition.iY - position.iY );
   403                     if ( !( iMessageField->SelectionLength() || iReadOnlyQuoteField->SelectionLength() ) )
   389                     if ( !( iMessageField->SelectionLength() || iReadOnlyQuoteField->SelectionLength() ) )
   404                     		iPhysics->RegisterPanningPosition( delta );
   390                         iPhysics->RegisterPanningPosition( delta );
   405 				   }
   391                     }
   406                 }
   392                 }
   407             else
   393             else
   408                 {
   394                 {
   409     			TInt topPosition( -iHeader->Position().iY );
   395                 TInt topPosition( iHeaderPos.iY - iHeader->Position().iY );
   410     						
   396                 TInt totalHeight( ContentTotalHeight() );
   411     			TInt totalHeight( ContentTotalHeight() );
   397                 TInt areaHeight( VisibleAreaHeight() );
   412 
   398                 TInt scrollOffset( 0 );
   413     			TInt areaHeight( Rect().Size().iHeight );
   399 
   414     			TInt scrollOffset( 0 );
   400                 if ( totalHeight > areaHeight )
   415     			
   401                     {
   416 				if( totalHeight > areaHeight )
   402                     // Calculate new scroll offset based on current and
   417 					{
   403                     // previous Y-positions
   418 					// Calculate new scroll offset based on current and
   404                     scrollOffset = topPosition + 
   419 					// previous Y-positions
   405                             ( iPreviousPosition.iY - position.iY );
   420 					scrollOffset = topPosition + 
   406                     // Ensure that thumb position is in correct range
   421                         ( iPreviousPosition.iY - position.iY );
   407                     scrollOffset = Max( scrollOffset, 0 );
   422 					// Ensure that thumb position is in correct range
   408                     scrollOffset = Min( scrollOffset, 
   423 					scrollOffset = Max( scrollOffset, 0 );
   409                             totalHeight - areaHeight );
   424 					scrollOffset = Min( scrollOffset, 
   410                     }
   425                                         totalHeight - areaHeight );
   411 
   426 					}
   412                 Scroll( scrollOffset );
   427 
   413                 }
   428 				Scroll( scrollOffset );
   414 
   429 				}
   415             // Save current position as previous pos for future calculations
   430            
   416             iPreviousPosition = position;  
   431 			// Save current position as previous pos for future calculations
   417 
   432 			iPreviousPosition = position;  
   418             break;
   433 			
   419             }
   434 			break;
   420 
   435     		}
       
   436     		
       
   437     	default:
   421     	default:
   438     		{
   422     		{
   439     		// unknown event, ignored
   423     		// unknown event, ignored
   440     		break;
   424     		break;
   441     		}
   425     		}
   544 
   528 
   545     return ret;
   529     return ret;
   546     }
   530     }
   547 
   531 
   548 // -----------------------------------------------------------------------------
   532 // -----------------------------------------------------------------------------
   549 // CNcsComposeViewContainer::UpdateScreenPositionL()
   533 // CNcsComposeViewContainer::UpdateScreenPosition()
   550 // If the user scrolled down in the message field
   534 // If the user scrolled down in the message field
   551 // we want to scroll up the header and grow the message field.
   535 // we want to scroll up the header and grow the message field.
   552 // -----------------------------------------------------------------------------
   536 // -----------------------------------------------------------------------------
   553 //
   537 //
   554 void CNcsComposeViewContainer::UpdateScreenPositionL( 
   538 void CNcsComposeViewContainer::UpdateScreenPosition( 
   555         const TUint& /*aKeyCode*/ )
   539         const TUint& /*aKeyCode*/ )
   556     {
   540     {
   557     FUNC_LOG;
   541     FUNC_LOG;
   558 
   542 
   559     // get screen rectangle
   543     // get screen rectangle
   560     const TRect screenRect( Rect() );
   544     const TRect screenRect = iCmailPaneRect;
   561 
   545 
   562     TPoint msgPos( iMessageField->Position() );
   546     TPoint msgPos( iMessageField->Position() );
   563     TPoint quotePos( iReadOnlyQuoteField->Position() );
   547     TPoint quotePos( iReadOnlyQuoteField->Position() );
   564 
   548 
   565     // find out cursor position in absolute coordinates
   549     // find out cursor position in absolute coordinates
   566     TRect lineRect;
   550     TRect lineRect;
   567     if ( iFocused == iMessageField )
   551     if ( iFocused == iMessageField )
   568         {
   552         {
   569         iMessageField->GetLineRectL( lineRect );
   553         iMessageField->GetLineRect( lineRect );
   570         lineRect.Move( msgPos );
   554         lineRect.Move( msgPos );
   571         }
   555         }
   572     else if ( iFocused == iReadOnlyQuoteField )
   556     else if ( iFocused == iReadOnlyQuoteField )
   573         {
   557         {
   574         iReadOnlyQuoteField->GetLineRectL( lineRect );
   558         iReadOnlyQuoteField->GetLineRect( lineRect );
   575         lineRect.Move( quotePos );
   559         lineRect.Move( quotePos );
   576         }
   560         }
   577     else
   561     else
   578         {
   562         {
   579         // This function should be used only when focus is in body or
   563         // This function should be used only when focus is in body or
   580         // read-only quote
   564         // read-only quote
   581         return;
   565         return;
   582         }
   566         }
   583     TPoint linePos = lineRect.iTl;
   567     TPoint linePos = lineRect.iTl;
   584 
   568 
   585     TInt minTargetY = lineRect.Height();
   569     TInt minTargetY = screenRect.iTl.iY + lineRect.Height();
   586     TInt maxTargetY = screenRect.Height() - lineRect.Height() * 2;
   570     TInt maxTargetY = screenRect.iBr.iY - lineRect.Height() * 2;
   587 
   571 
   588     TInt moveY = 0;
   572     TInt moveY = 0;
   589     // if cursor goes out of screen then move the controls
   573     // if cursor goes out of screen then move the controls
   590     if ( linePos.iY > maxTargetY )
   574     if ( linePos.iY > maxTargetY )
   591         {
   575         {
   596         moveY = minTargetY - linePos.iY;
   580         moveY = minTargetY - linePos.iY;
   597         }
   581         }
   598 
   582 
   599     // Check we don't scroll too low
   583     // Check we don't scroll too low
   600     if ( quotePos.iY + moveY + iReadOnlyQuoteField->Size().iHeight < 
   584     if ( quotePos.iY + moveY + iReadOnlyQuoteField->Size().iHeight < 
   601          screenRect.Height() )
   585          screenRect.iBr.iY )
   602         {
   586         {
   603         moveY = screenRect.Height() - quotePos.iY - 
   587         moveY = screenRect.iBr.iY - quotePos.iY - 
   604             iReadOnlyQuoteField->Size().iHeight;
   588             iReadOnlyQuoteField->Size().iHeight;
   605         }
   589         }
   606 
   590 
   607     // Check we don't scroll too high
   591     // Check we don't scroll too high
   608     TPoint headerPos = iHeader->Position();
   592     TPoint headerPos = iHeader->Position();
   609     if ( headerPos.iY + moveY > 0 )
   593     if ( headerPos.iY + moveY > iHeaderPos.iY )
   610         {
   594         {
   611         moveY = -headerPos.iY;
   595         moveY = iHeaderPos.iY - headerPos.iY;
   612         }
   596         }
   613 
   597 
   614     if ( moveY )
   598     if ( moveY )
   615         {
   599         {
   616         headerPos.iY += moveY;
   600         headerPos.iY += moveY;
   617         iHeader->SetPosition( headerPos );
   601         iHeader->SetPosition( headerPos );
   618 
   602 
       
   603         iSeparatorLineYPos += moveY;
       
   604 
   619         msgPos.iY += moveY;
   605         msgPos.iY += moveY;
   620         iMessageField->SetPosition( msgPos );
   606         iMessageField->SetPosition( msgPos );
   621 
   607 
   622         quotePos.iY += moveY;
   608         quotePos.iY += moveY;
   623         iReadOnlyQuoteField->SetPosition( quotePos );
   609         iReadOnlyQuoteField->SetPosition( quotePos );
   624 
   610 
   625         iSeparatorLineYPos += moveY;
   611         const TInt bottom = Rect().iBr.iY;
       
   612         if ( iMessageField->IsFocused() )
       
   613             {
       
   614             iMessageField->SetCursorVisible( msgPos.iY <= bottom );
       
   615             }
       
   616         else if ( iReadOnlyQuoteField->IsFocused() )
       
   617             {
       
   618             iReadOnlyQuoteField->SetCursorVisible( quotePos.iY <= bottom );
       
   619             }
       
   620 
   626         UpdateScrollBar();
   621         UpdateScrollBar();
   627         }
   622         }
   628     }
   623     }
   629 
   624 
   630 // -----------------------------------------------------------------------------
   625 // -----------------------------------------------------------------------------
   655 
   650 
   656         TPoint quotePos( iReadOnlyQuoteField->Position() );
   651         TPoint quotePos( iReadOnlyQuoteField->Position() );
   657         quotePos.iY = iMessageField->Rect().iBr.iY;
   652         quotePos.iY = iMessageField->Rect().iBr.iY;
   658         iReadOnlyQuoteField->SetPosition( quotePos );
   653         iReadOnlyQuoteField->SetPosition( quotePos );
   659 
   654 
       
   655         const TInt bottom = Rect().iBr.iY;
       
   656         if ( iMessageField->IsFocused() )
       
   657             {
       
   658             iMessageField->SetCursorVisible( bodyPos.iY <= bottom );
       
   659             }
       
   660         else if ( iReadOnlyQuoteField->IsFocused() )
       
   661             {
       
   662             iReadOnlyQuoteField->SetCursorVisible( quotePos.iY <= bottom );
       
   663             }
       
   664 
       
   665         TInt scrollSpan = Max( ContentTotalHeight(), VisibleAreaHeight() + 1 );
       
   666         iScrollBarModel.SetScrollSpan( scrollSpan );
   660         UpdateScrollBar();
   667         UpdateScrollBar();
   661         DrawDeferred();
   668         DrawDeferred();
   662         }
   669         }
   663 
   670 
   664     }
   671     }
   666 // -----------------------------------------------------------------------------
   673 // -----------------------------------------------------------------------------
   667 // CNcsComposeViewContainer::ChangeFocusL()
   674 // CNcsComposeViewContainer::ChangeFocusL()
   668 // Handles key events
   675 // Handles key events
   669 // -----------------------------------------------------------------------------
   676 // -----------------------------------------------------------------------------
   670 //
   677 //
   671 
       
   672 TKeyResponse CNcsComposeViewContainer::ChangeFocusL( 
   678 TKeyResponse CNcsComposeViewContainer::ChangeFocusL( 
   673         const TKeyEvent& aKeyEvent )
   679         const TKeyEvent& aKeyEvent )
   674     {
   680     {
   675     FUNC_LOG;
   681     FUNC_LOG;
   676 
   682 
   689             {
   695             {
   690             iFocused = iHeader;
   696             iFocused = iHeader;
   691             iHeader->SetFocus( ETrue, ENoDrawNow );
   697             iHeader->SetFocus( ETrue, ENoDrawNow );
   692             iMessageField->SetFocus( EFalse, ENoDrawNow );
   698             iMessageField->SetFocus( EFalse, ENoDrawNow );
   693             iHeader->MakeVisible( ETrue );
   699             iHeader->MakeVisible( ETrue );
   694             iHeader->ShowCursor( ETrue );
       
   695             CommitL( EBodyField );
   700             CommitL( EBodyField );
   696             ret = EKeyWasConsumed;
   701             ret = EKeyWasConsumed;
   697             }
   702             }
   698         else if ( aKeyEvent.iCode == EKeyDownArrow && 
   703         else if ( aKeyEvent.iCode == EKeyDownArrow && 
   699                   iReadOnlyQuoteField->TextLength() )
   704                   iReadOnlyQuoteField->TextLength() )
   715         ret = EKeyWasConsumed;
   720         ret = EKeyWasConsumed;
   716         }
   721         }
   717 
   722 
   718     if ( ret == EKeyWasConsumed )
   723     if ( ret == EKeyWasConsumed )
   719         {
   724         {
   720         UpdateScreenPositionL( aKeyEvent.iCode );
   725         UpdateScreenPosition( aKeyEvent.iCode );
   721         }
   726         }
   722 
   727 
       
   728     DrawDeferred();
   723     return ret;
   729     return ret;
   724     }
   730     }
   725 
   731 
   726 // -----------------------------------------------------------------------------
   732 // -----------------------------------------------------------------------------
   727 // CNcsComposeViewContainer::UpdateFieldSizeL()
   733 // CNcsComposeViewContainer::UpdateFieldSizeL()
   745     return EFalse;
   751     return EFalse;
   746     }
   752     }
   747 
   753 
   748 // -----------------------------------------------------------------------------
   754 // -----------------------------------------------------------------------------
   749 // CNcsComposeViewContainer::SizeChanged()
   755 // CNcsComposeViewContainer::SizeChanged()
   750 // set size
   756 // Handles container size change.
   751 // -----------------------------------------------------------------------------
   757 // -----------------------------------------------------------------------------
   752 //
   758 //
   753 void CNcsComposeViewContainer::SizeChanged()
   759 void CNcsComposeViewContainer::SizeChanged()
   754     {
   760     {
   755     FUNC_LOG;
   761     FUNC_LOG;
   757     const TRect rect( Rect() );
   763     const TRect rect( Rect() );
   758     iScrollBar->SetRect( NcsUtility::ListCmailScrollbarRect( rect ) );
   764     iScrollBar->SetRect( NcsUtility::ListCmailScrollbarRect( rect ) );
   759     TRect cmailPaneRect( NcsUtility::ListCmailPaneRect( rect ) );
   765     TRect cmailPaneRect( NcsUtility::ListCmailPaneRect( rect ) );
   760 
   766 
   761     const TInt headerLineCount( iHeader->LayoutLineCount() );
   767     const TInt headerLineCount( iHeader->LayoutLineCount() );
   762     const TPoint headerPos( 
   768     iHeaderPos = NcsUtility::HeaderControlPosition( cmailPaneRect, 0 );
   763             NcsUtility::HeaderControlPosition( cmailPaneRect, 0 ) );
   769     iHeader->SetOrigin( iHeaderPos );
   764     cmailPaneRect.Move( 0, iHeader->Position().iY - headerPos.iY );
   770     const TPoint currentHeaderPos = iHeader->Position();
       
   771     if ( currentHeaderPos.iY > iHeaderPos.iY )
       
   772         {
       
   773         cmailPaneRect.Move( 0, currentHeaderPos.iY - iHeaderPos.iY );
       
   774         }
   765     iCmailPaneRect = cmailPaneRect;
   775     iCmailPaneRect = cmailPaneRect;
   766 
   776 
   767     NcsUtility::LayoutHeaderControl( 
   777     NcsUtility::LayoutHeaderControl( 
   768             iHeader, cmailPaneRect, 0, headerLineCount );
   778             iHeader, cmailPaneRect, 0, headerLineCount );
   769 
   779 
   799             TRAP_IGNORE( iReadOnlyQuoteField->FormatAllTextNowL() );
   809             TRAP_IGNORE( iReadOnlyQuoteField->FormatAllTextNowL() );
   800             }
   810             }
   801         iReadOnlyQuoteField->UpdateFontSize();
   811         iReadOnlyQuoteField->UpdateFontSize();
   802         readOnlyQuoteFieldHeight = iReadOnlyQuoteField->Rect().Height();
   812         readOnlyQuoteFieldHeight = iReadOnlyQuoteField->Rect().Height();
   803         }
   813         }
   804 
   814     else
   805     iBgContext->SetRect( Rect() );
   815         {
   806     iMessageField->SetRealRect( Rect() );
   816         // Set quote field immediatelly bellow message field with zero height.
   807     iReadOnlyQuoteField->SetRealRect( Rect() );
   817         TRect quoteRect = iMessageField->Rect();
       
   818         quoteRect.iTl = quoteRect.iBr;
       
   819         iReadOnlyQuoteField->SetRect( quoteRect );
       
   820         }
       
   821 
       
   822     iBgContext->SetRect( rect );
       
   823     iMessageField->SetRealRect( rect );
       
   824     iReadOnlyQuoteField->SetRealRect( rect );
   808 
   825 
   809     TInt messageLineHeigth = 
   826     TInt messageLineHeigth = 
   810         NcsUtility::HeaderCaptionPaneRect( cmailPaneRect ).Height();
   827         NcsUtility::HeaderCaptionPaneRect( cmailPaneRect ).Height();
   811     iSeparatorHeight = NcsUtility::SeparatorSizeInThisResolution().iHeight;
   828     iSeparatorHeight = NcsUtility::SeparatorSizeInThisResolution().iHeight;
   812     iMessageEditorMinHeigth = 
   829     iMessageEditorMinHeigth = 
   829     else
   846     else
   830         {
   847         {
   831         iMessageEditorMinHeigth = messageLineHeigth;
   848         iMessageEditorMinHeigth = messageLineHeigth;
   832         }
   849         }
   833 
   850 
   834 	// update some layout variables
   851     // update some layout variables
   835     iHeaderHeight = iHeader->Rect().Height();
   852     iHeaderHeight = iHeader->Rect().Height();
   836     TRect bodyRect = iMessageField->Rect();
   853     TRect bodyRect = iMessageField->Rect();
       
   854     iReadOnlyQuoteField->SetPosition( 
       
   855         TPoint( bodyRect.iTl.iX, bodyRect.iBr.iY ) );
   837     TRect quoteRect = iReadOnlyQuoteField->Rect();
   856     TRect quoteRect = iReadOnlyQuoteField->Rect();
   838 
   857 
   839     iTotalComposerHeight = iHeaderHeight + iSeparatorHeight * 2 + 
   858     iTotalComposerHeight = iHeaderHeight + iSeparatorHeight + 
   840 							   bodyRect.Height() + quoteRect.Height();
   859         bodyRect.Height() + quoteRect.Height();
   841     
   860 
   842     iVisibleAreaHeight = Rect().Height();
   861     iVisibleAreaHeight = iCmailPaneRect.Height();
   843         
   862 
       
   863     // Scroll span is set always to be larger than the window size to
       
   864     // keep the scroll bar visible.
       
   865     TInt scrollSpan = Max( iTotalComposerHeight, iVisibleAreaHeight + 1 );
       
   866     iScrollBarModel.SetScrollSpan( scrollSpan );
       
   867     iScrollBarModel.SetWindowSize( iVisibleAreaHeight );
       
   868     if ( iHeader->IsFocused() )
       
   869         {
       
   870         iHeader->DoScroll();
       
   871         }
       
   872     else
       
   873         {
       
   874         UpdateScreenPosition();
       
   875         }
   844     UpdateScrollBar();
   876     UpdateScrollBar();
   845 
       
   846     iScrollBarModel.SetScrollSpan( iTotalComposerHeight );
       
   847     iScrollBarModel.SetWindowSize( iVisibleAreaHeight );
       
   848     DrawDeferred();
   877     DrawDeferred();
   849     }
   878     }
   850 
   879 
   851 // -----------------------------------------------------------------------------
   880 // -----------------------------------------------------------------------------
   852 // CNcsComposeViewContainer::Draw() const
   881 // CNcsComposeViewContainer::Draw() const
   957     if ( iReadOnlyQuote && iProcessedField == iMessageField )
   986     if ( iReadOnlyQuote && iProcessedField == iMessageField )
   958         {
   987         {
   959         iProcessedField = iReadOnlyQuoteField;
   988         iProcessedField = iReadOnlyQuoteField;
   960         if ( iReadOnlyQuote )
   989         if ( iReadOnlyQuote )
   961             {
   990             {
   962 			TInt dummySeparatorPos;
   991             TInt dummySeparatorPos;
   963 			NcsUtility::LayoutBodyEdwin( iReadOnlyQuoteField, iCmailPaneRect, 
   992             NcsUtility::LayoutBodyEdwin( iReadOnlyQuoteField, iCmailPaneRect, 
   964 					iHeader->LayoutLineCount() + iMessageField->LineCount(),
   993                     iHeader->LayoutLineCount() + iMessageField->LineCount(),
   965 					iReadOnlyQuoteField->LineCount(), dummySeparatorPos );
   994                     iReadOnlyQuoteField->LineCount(), dummySeparatorPos );
   966             iReadOnlyQuoteField->SetAlignment( EAknEditorAlignBidi );
   995             iReadOnlyQuoteField->SetAlignment( EAknEditorAlignBidi );
   967             
   996 
   968 			RMemReadStream inputStream;
   997             RMemReadStream inputStream;
   969             inputStream.Open( iReadOnlyQuote->Ptr(), iReadOnlyQuote->Size() );
   998             inputStream.Open( iReadOnlyQuote->Ptr(), iReadOnlyQuote->Size() );
   970             TRAP_IGNORE( iReadOnlyQuoteField->RichText()->ImportTextL( 0, inputStream,
   999             TRAP_IGNORE( iReadOnlyQuoteField->RichText()->ImportTextL( 0, inputStream,
   971                     CPlainText::EOrganiseByParagraph ) );
  1000                     CPlainText::EOrganiseByParagraph ) );
   972             inputStream.Close();
  1001             inputStream.Close();
   973             
  1002             
  1138             {
  1167             {
  1139             iAutoSaver.ReportActivity();
  1168             iAutoSaver.ReportActivity();
  1140 
  1169 
  1141             // Update screen position and scroll bar when text changed
  1170             // Update screen position and scroll bar when text changed
  1142             // or cursor moved
  1171             // or cursor moved
  1143             UpdateScreenPositionL();
  1172             UpdateScreenPosition();
  1144             UpdateScrollBar();
  1173             UpdateScrollBar();
  1145             DrawDeferred();
  1174             DrawDeferred();
  1146             }
  1175             }
  1147         }
  1176         }
  1148     }
  1177     }
  1154 TBool CNcsComposeViewContainer::HandleEdwinSizeEventL( CEikEdwin* aEdwin,
  1183 TBool CNcsComposeViewContainer::HandleEdwinSizeEventL( CEikEdwin* aEdwin,
  1155         TEdwinSizeEvent /*aEventType*/, TSize aDesirableEdwinSize )
  1184         TEdwinSizeEvent /*aEventType*/, TSize aDesirableEdwinSize )
  1156     {
  1185     {
  1157     FUNC_LOG;
  1186     FUNC_LOG;
  1158     TBool ret = ETrue;
  1187     TBool ret = ETrue;
  1159     
       
  1160     const TRect rect( Rect() );
       
  1161     TRect cmailPaneRect( NcsUtility::ListCmailPaneRect( rect ) );
       
  1162 
  1188 
  1163     if ( aDesirableEdwinSize.iHeight < iPrevDesiredHeigth )
  1189     if ( aDesirableEdwinSize.iHeight < iPrevDesiredHeigth )
  1164         {
  1190         {
  1165         if ( aDesirableEdwinSize.iHeight < iMessageEditorMinHeigth )
  1191         if ( aDesirableEdwinSize.iHeight < iMessageEditorMinHeigth )
  1166             {
  1192             {
  1174             {
  1200             {
  1175             if ( !iSwitchOffFormattingText )
  1201             if ( !iSwitchOffFormattingText )
  1176                 {
  1202                 {
  1177                 aEdwin->SetSize( aDesirableEdwinSize );
  1203                 aEdwin->SetSize( aDesirableEdwinSize );
  1178                 }
  1204                 }
  1179             }        
  1205             }
  1180         }
  1206         }
  1181     else
  1207     else
  1182         {
  1208         {
  1183         if ( !iSwitchOffFormattingText )
  1209         if ( !iSwitchOffFormattingText )
  1184             {
  1210             {
  1185             aEdwin->SetSize( aDesirableEdwinSize );
  1211             aEdwin->SetSize( aDesirableEdwinSize );
  1186             }
  1212             }
  1187         }
  1213         }
       
  1214 
  1188     if ( aEdwin == iMessageField )
  1215     if ( aEdwin == iMessageField )
  1189         {
  1216         {
  1190         // move the quote field below the body field
  1217         // move the quote field below the body field
  1191         TPoint quotePos = iMessageField->Position();
  1218         TPoint quotePos = iMessageField->Position();
  1192         quotePos.iY += iMessageField->Size().iHeight;
  1219         quotePos.iY += iMessageField->Size().iHeight;
  1193         iReadOnlyQuoteField->SetPosition( quotePos );
  1220         iReadOnlyQuoteField->SetPosition( quotePos );
  1194 		UpdateScreenPositionL(); 
  1221         UpdateScreenPosition(); 
  1195         }
  1222         }
       
  1223 
       
  1224     // Update scroll span and position.
       
  1225     TInt scrollSpan = Max( ContentTotalHeight(), VisibleAreaHeight() + 1 );
       
  1226     iScrollBarModel.SetScrollSpan( scrollSpan );
       
  1227     UpdateScrollBar();
  1196 
  1228 
  1197     iPrevDesiredHeigth = aDesirableEdwinSize.iHeight;
  1229     iPrevDesiredHeigth = aDesirableEdwinSize.iHeight;
  1198 
  1230 
  1199     return ret;
  1231     return ret;
  1200     }
  1232     }
  1221 void CNcsComposeViewContainer::UpdateScrollBar()
  1253 void CNcsComposeViewContainer::UpdateScrollBar()
  1222     {
  1254     {
  1223     FUNC_LOG;
  1255     FUNC_LOG;
  1224 
  1256 
  1225     TRect headerRect = iHeader->Rect();
  1257     TRect headerRect = iHeader->Rect();
  1226     TInt visiblePosition = -headerRect.iTl.iY;
  1258     TInt visiblePosition = iHeaderPos.iY - headerRect.iTl.iY;
  1227 
  1259 
  1228     iScrollBarModel.SetFocusPosition( visiblePosition );
  1260     iScrollBarModel.SetFocusPosition( visiblePosition );
  1229 
  1261 
  1230     iScrollBar->SetModel( &iScrollBarModel );
  1262     iScrollBar->SetModel( &iScrollBarModel );
  1231     iScrollBar->MakeVisible( IsVisible() );
  1263     iScrollBar->MakeVisible( !iHeader->IsPopupActive() );
       
  1264     }
       
  1265 
       
  1266 // -----------------------------------------------------------------------------
       
  1267 // CNcsComposeViewContainer::UpdateScrollBarVisibility()
       
  1268 // -----------------------------------------------------------------------------
       
  1269 //
       
  1270 void CNcsComposeViewContainer::UpdateScrollBarVisibility( TBool aVisible )
       
  1271     {
       
  1272     FUNC_LOG;
       
  1273     iScrollBar->MakeVisible( aVisible );
  1232     }
  1274     }
  1233 
  1275 
  1234 // -----------------------------------------------------------------------------
  1276 // -----------------------------------------------------------------------------
  1235 // CNcsComposeViewContainer::SetFocusToMessageFieldL()
  1277 // CNcsComposeViewContainer::SetFocusToMessageFieldL()
  1236 // -----------------------------------------------------------------------------
  1278 // -----------------------------------------------------------------------------
  1243         {
  1285         {
  1244         iHeader->SetFocus( EFalse, ENoDrawNow );
  1286         iHeader->SetFocus( EFalse, ENoDrawNow );
  1245         iMessageField->SetCursorPosL( 0, EFalse );
  1287         iMessageField->SetCursorPosL( 0, EFalse );
  1246         iMessageField->SetFocus( ETrue, ENoDrawNow );
  1288         iMessageField->SetFocus( ETrue, ENoDrawNow );
  1247         iFocused = iMessageField;
  1289         iFocused = iMessageField;
  1248         UpdateScreenPositionL();
  1290         UpdateScreenPosition();
  1249         DrawDeferred();
  1291         DrawDeferred();
  1250         }
  1292         }
  1251     }
  1293     }
  1252 
  1294 
  1253 // -----------------------------------------------------------------------------
  1295 // -----------------------------------------------------------------------------
  1758 // -----------------------------------------------------------------------------
  1800 // -----------------------------------------------------------------------------
  1759 //
  1801 //
  1760 void CNcsComposeViewContainer::HideAttachmentLabel()
  1802 void CNcsComposeViewContainer::HideAttachmentLabel()
  1761     {
  1803     {
  1762     FUNC_LOG;
  1804     FUNC_LOG;
  1763 
  1805     iHeader->HideAttachmentLabel();
  1764 	iHeader->HideAttachmentLabel();
       
  1765 
       
  1766     }
  1806     }
  1767 
  1807 
  1768 // -----------------------------------------------------------------------------
  1808 // -----------------------------------------------------------------------------
  1769 // CNcsComposeViewContainer::SetCcFieldVisibleL
  1809 // CNcsComposeViewContainer::SetCcFieldVisibleL
  1770 //
  1810 //
  1964 // -----------------------------------------------------------------------------
  2004 // -----------------------------------------------------------------------------
  1965 //
  2005 //
  1966 TInt CNcsComposeViewContainer::ContentTotalHeight()
  2006 TInt CNcsComposeViewContainer::ContentTotalHeight()
  1967     {
  2007     {
  1968     FUNC_LOG;	
  2008     FUNC_LOG;	
  1969 	TInt totalHeight( iHeader->Size().iHeight + 
  2009     TInt totalHeight( iHeader->Size().iHeight + 
  1970 	                  iSeparatorHeight * 2 + 
  2010         iSeparatorHeight + iMessageField->Size().iHeight );
  1971 					  iMessageField->Size().iHeight );
  2011 
  1972 
  2012     if ( iReadOnlyQuoteField->IsVisible() )
  1973 	if( iReadOnlyQuoteField->IsVisible() )
  2013         {
  1974 		{
  2014         totalHeight += iReadOnlyQuoteField->Size().iHeight;
  1975 		totalHeight += iReadOnlyQuoteField->Size().iHeight;
  2015         }
  1976 		}	
  2016 
  1977 	
  2017     return totalHeight;
  1978 	return totalHeight;
  2018     }
       
  2019 
       
  2020 // -----------------------------------------------------------------------------
       
  2021 // Returns the height of visible composer area.
       
  2022 // -----------------------------------------------------------------------------
       
  2023 //
       
  2024 TInt CNcsComposeViewContainer::VisibleAreaHeight()
       
  2025     {
       
  2026     return iVisibleAreaHeight;
  1979     }
  2027     }
  1980 
  2028 
  1981 // -----------------------------------------------------------------------------
  2029 // -----------------------------------------------------------------------------
  1982 // CNcsComposeViewContainer::CommitL()
  2030 // CNcsComposeViewContainer::CommitL()
  1983 //
       
  1984 // -----------------------------------------------------------------------------
  2031 // -----------------------------------------------------------------------------
  1985 //
  2032 //
  1986 void CNcsComposeViewContainer::CommitL( TFieldToCommit aFieldToCommit )
  2033 void CNcsComposeViewContainer::CommitL( TFieldToCommit aFieldToCommit )
  1987     {
  2034     {
  1988     FUNC_LOG;
  2035     FUNC_LOG;
  2027 void CNcsComposeViewContainer::UpdatePhysicsL()
  2074 void CNcsComposeViewContainer::UpdatePhysicsL()
  2028     {
  2075     {
  2029     FUNC_LOG;
  2076     FUNC_LOG;
  2030     if ( iPhysics )
  2077     if ( iPhysics )
  2031         {
  2078         {
  2032         const TSize viewSize( Rect().Size() );
  2079         const TSize viewSize( iCmailPaneRect.Size() );
  2033         // We must ensure that world size is at least the size of the view
  2080         // We must ensure that world size is at least the size of the view
  2034         const TSize worldSize( viewSize.iWidth, 
  2081         const TSize worldSize( viewSize.iWidth, 
  2035                 Max( ContentTotalHeight(), viewSize.iHeight ) );
  2082                 Max( ContentTotalHeight(), viewSize.iHeight ) );
  2036         iPhysics->InitPhysicsL( worldSize, viewSize, EFalse );
  2083         iPhysics->InitPhysicsL( worldSize, viewSize, EFalse );
  2037         }
  2084         }
  2042 // -----------------------------------------------------------------------------
  2089 // -----------------------------------------------------------------------------
  2043 //
  2090 //
  2044 void CNcsComposeViewContainer::Scroll( TInt aTargetPos, TBool aDrawNow )
  2091 void CNcsComposeViewContainer::Scroll( TInt aTargetPos, TBool aDrawNow )
  2045     {
  2092     {
  2046     FUNC_LOG;
  2093     FUNC_LOG;
  2047 	TPoint headerPos( iHeader->Position() );
  2094     TPoint headerPos = iHeader->Position();
  2048 	TInt moveY = -headerPos.iY - aTargetPos;
  2095     const TInt currentPos = iHeaderPos.iY - headerPos.iY;
  2049 	
  2096     TInt moveY = currentPos - aTargetPos;
       
  2097 
  2050     if ( aDrawNow )
  2098     if ( aDrawNow )
  2051     	{
  2099         {
  2052 		moveY = iTotalMoveY + moveY;
  2100         moveY = iTotalMoveY + moveY;
  2053 		iTotalMoveY = 0;
  2101         iTotalMoveY = 0;
  2054 		if ( moveY )
  2102         if ( moveY )
  2055 			{
  2103             {
  2056 			headerPos.iY += moveY;
  2104             headerPos.iY += moveY;
  2057 			iHeader->SetPosition( headerPos );
  2105             iHeader->SetPosition( headerPos );
  2058 
  2106 
  2059 			// set header invisible if it is not in visible area
  2107             // set header invisible if it is not in visible area
  2060 			// this is done to prevent drawing of header when it is not necessary
  2108             // this is done to prevent drawing of header when it is not necessary
  2061             if ( headerPos.iY + iHeaderHeight <= KHeaderVisibilityThreshold && iHeader->IsVisible() )
  2109             if ( headerPos.iY + iHeaderHeight <= KHeaderVisibilityThreshold && iHeader->IsVisible() )
  2062                 {            
  2110                 {
  2063                 iHeader->MakeVisible( EFalse );
  2111                 iHeader->MakeVisible( EFalse );
  2064                 }
  2112                 }
  2065             // set header visible if it is in visible area
  2113             // set header visible if it is in visible area
  2066             else if ( headerPos.iY + iHeaderHeight > KHeaderVisibilityThreshold && !iHeader->IsVisible() ) 
  2114             else if ( headerPos.iY + iHeaderHeight > KHeaderVisibilityThreshold && !iHeader->IsVisible() ) 
  2067                 {
  2115                 {
  2068                 iHeader->MakeVisible( ETrue );
  2116                 iHeader->MakeVisible( ETrue );
  2069                 }
  2117                 }
  2070     
  2118 
  2071 			TPoint msgPos( iMessageField->Position() );
  2119             TPoint msgPos( iMessageField->Position() );
  2072 			msgPos.iY += moveY;
  2120             msgPos.iY += moveY;
  2073 			iMessageField->SetPosition( msgPos );
  2121             iMessageField->SetPosition( msgPos );
  2074 	
  2122 
  2075 			if( iReadOnlyQuoteField->IsVisible() )
  2123             TPoint quotePos( iReadOnlyQuoteField->Position() );
  2076 				{
  2124             quotePos.iY += moveY;
  2077 				TPoint readOnlyPos( iReadOnlyQuoteField->Position() );
  2125             iReadOnlyQuoteField->SetPosition( quotePos );
  2078 				readOnlyPos.iY += moveY;
  2126 
  2079 				iReadOnlyQuoteField->SetPosition( readOnlyPos );
  2127             const TInt bottom = Rect().iBr.iY;
  2080 				}
  2128             if ( iMessageField->IsFocused() )
  2081 	
  2129                 {
  2082 			iSeparatorLineYPos += moveY;
  2130                 iMessageField->SetCursorVisible( msgPos.iY <= bottom );
  2083 
  2131                 }
  2084 			UpdateScrollBar();
  2132             else if ( iReadOnlyQuoteField->IsFocused() )
  2085 			DrawDeferred();
  2133                 {
  2086 			}
  2134                 iReadOnlyQuoteField->SetCursorVisible( quotePos.iY <= bottom );
  2087     	}
  2135                 }
       
  2136 
       
  2137             iSeparatorLineYPos += moveY;
       
  2138 
       
  2139             UpdateScrollBar();
       
  2140             DrawDeferred();
       
  2141             }
       
  2142         }
  2088     else
  2143     else
  2089     	{
  2144         {
  2090 		iTotalMoveY += moveY;
  2145         iTotalMoveY += moveY;
  2091     	}    	
  2146         }
  2092     }
  2147     }
  2093 
  2148 
  2094 // -----------------------------------------------------------------------------
  2149 // -----------------------------------------------------------------------------
  2095 // CNcsComposeViewContainer::ViewPositionChanged
  2150 // CNcsComposeViewContainer::ViewPositionChanged
  2096 // From MAknPhysicsObserver
  2151 // From MAknPhysicsObserver
  2131 // -----------------------------------------------------------------------------
  2186 // -----------------------------------------------------------------------------
  2132 //
  2187 //
  2133 TPoint CNcsComposeViewContainer::ViewPosition() const
  2188 TPoint CNcsComposeViewContainer::ViewPosition() const
  2134     {
  2189     {
  2135     FUNC_LOG;
  2190     FUNC_LOG;
  2136     return TPoint(0, -iHeader->Position().iY  + iVisibleAreaHeight / 2 );
  2191     TInt y = iHeaderPos.iY - iHeader->Position().iY + iVisibleAreaHeight / 2;
  2137     }
  2192     return TPoint( 0, y );
  2138 
  2193     }
  2139 
  2194 
  2140 // -----------------------------------------------------------------------------
  2195 // -----------------------------------------------------------------------------
  2141 // CNcsComposeViewContainer::IsRemoteSearchInprogress
  2196 // CNcsComposeViewContainer::IsRemoteSearchInprogress
  2142 // -----------------------------------------------------------------------------
  2197 // -----------------------------------------------------------------------------
  2143 //
  2198 //