emailuis/emailui/src/ncscomposeviewcontainer.cpp
branchRCL_3
changeset 17 67369d1b217f
parent 16 b5fbb9b25d57
child 23 dcf0eedfc1a3
equal deleted inserted replaced
16:b5fbb9b25d57 17:67369d1b217f
    50 #include "FreestyleEmailUiSendAttachmentsListVisualiser.h"
    50 #include "FreestyleEmailUiSendAttachmentsListVisualiser.h"
    51 #include "FreestyleEmailUiSendAttachmentsListModel.h"
    51 #include "FreestyleEmailUiSendAttachmentsListModel.h"
    52 #include "FreestyleEmailUi.hrh"
    52 #include "FreestyleEmailUi.hrh"
    53 #include "FSAutoSaver.h"
    53 #include "FSAutoSaver.h"
    54 #include "FreestyleEmailUiCLSItem.h"
    54 #include "FreestyleEmailUiCLSItem.h"
    55 
    55 #include "FSAsyncTextFormatter.h"
    56 
    56 
    57 const TInt KHeaderVisibilityThreshold = -100;
    57 const TInt KHeaderVisibilityThreshold = -100;
    58 
    58 
    59 // ========================= MEMBER FUNCTIONS ==================================
    59 // ========================= MEMBER FUNCTIONS ==================================
    60 
    60 
   167 
   167 
   168     SetRect( aRect );
   168     SetRect( aRect );
   169 
   169 
   170     iLongTapDetector = CAknLongTapDetector::NewL( this );
   170     iLongTapDetector = CAknLongTapDetector::NewL( this );
   171 
   171 
   172     ActivateL();
       
   173     DrawDeferred();
       
   174 
       
   175     // activate auto save functionality
   172     // activate auto save functionality
   176     iAutoSaver.Enable( ETrue );
   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         }
   177     }
   186     }
   178 
   187 
   179 // ---------------------------------------------------------------------------
   188 // ---------------------------------------------------------------------------
   180 // CNcsComposeViewContainer::~CNcsComposeViewContainer
   189 // CNcsComposeViewContainer::~CNcsComposeViewContainer
   181 // Destructor
   190 // Destructor
   182 // ---------------------------------------------------------------------------
   191 // ---------------------------------------------------------------------------
   183 //
   192 //
   184 CNcsComposeViewContainer::~CNcsComposeViewContainer()
   193 CNcsComposeViewContainer::~CNcsComposeViewContainer()
   185     {
   194     {
   186     FUNC_LOG;
   195     FUNC_LOG;
       
   196     
       
   197     if ( iAsyncTextFormatter )
       
   198         {
       
   199         iAsyncTextFormatter->Cancel();
       
   200         delete iAsyncTextFormatter;
       
   201         }
       
   202     
   187     if ( iContactHandler )
   203     if ( iContactHandler )
   188         {
   204         {
   189         iContactHandler->ClearObservers();
   205         iContactHandler->ClearObservers();
   190         }
   206         }
   191 	delete iHeader;
   207 	delete iHeader;
   501     if ( ret == EKeyWasNotConsumed )
   517     if ( ret == EKeyWasNotConsumed )
   502         {
   518         {
   503         if ( iFocused )
   519         if ( iFocused )
   504             ret = iFocused->OfferKeyEventL( aKeyEvent, aType );
   520             ret = iFocused->OfferKeyEventL( aKeyEvent, aType );
   505 
   521 
   506         if( aType == EEventKeyUp )
   522         iView.HandleContainerChangeRequiringToolbarRefresh();
   507         	iView.HandleContainerChangeRequiringToolbarRefresh();
       
   508         
   523         
   509         // Report user activity to auto saver if editor field handled the
   524         // Report user activity to auto saver if editor field handled the
   510         // event. In case of message field (body text), EKeyWasConsumed
   525         // event. In case of message field (body text), EKeyWasConsumed
   511         // condition does not come true because AknFep consumes EKeyEvent
   526         // condition does not come true because AknFep consumes EKeyEvent
   512         // and calls HandleEdwinEventL. This OfferKeyEventL gets only
   527         // and calls HandleEdwinEventL. This OfferKeyEventL gets only
   736 
   751 
   737     const TInt headerLineCount( iHeader->LayoutLineCount() );
   752     const TInt headerLineCount( iHeader->LayoutLineCount() );
   738     const TPoint headerPos( 
   753     const TPoint headerPos( 
   739             NcsUtility::HeaderControlPosition( cmailPaneRect, 0 ) );
   754             NcsUtility::HeaderControlPosition( cmailPaneRect, 0 ) );
   740     cmailPaneRect.Move( 0, iHeader->Position().iY - headerPos.iY );
   755     cmailPaneRect.Move( 0, iHeader->Position().iY - headerPos.iY );
       
   756     iCmailPaneRect = cmailPaneRect;
   741 
   757 
   742     NcsUtility::LayoutHeaderControl( 
   758     NcsUtility::LayoutHeaderControl( 
   743             iHeader, cmailPaneRect, 0, headerLineCount );
   759             iHeader, cmailPaneRect, 0, headerLineCount );
   744 
   760 
   745     // do not used stored headerLineCount, because relayout above may grow or
   761     // do not used stored headerLineCount, because relayout above may grow or
   746     // shrink edit fields
   762     // shrink edit fields
   747     NcsUtility::LayoutBodyEdwin( 
   763     NcsUtility::LayoutBodyEdwin( 
   748             iMessageField, cmailPaneRect, iHeader->LayoutLineCount(), 
   764             iMessageField, cmailPaneRect, iHeader->LayoutLineCount(), 
   749             iMessageField->LineCount(), iSeparatorLineYPos );
   765             iMessageField->LineCount(), iSeparatorLineYPos );
   750     TRAP_IGNORE( iMessageField->FormatAllTextNowL() );
   766     
       
   767     // we don't need format again when format was already done
       
   768     // during creation of forward/reply message
       
   769     if ( !iSwitchOffFormattingText )
       
   770         {
       
   771         TRAP_IGNORE( iMessageField->FormatAllTextNowL() );
       
   772         }
   751 
   773 
   752     iMessageField->UpdateFontSize();
   774     iMessageField->UpdateFontSize();
   753 
   775 
   754     TInt readOnlyQuoteFieldHeight( 0 );
   776     TInt readOnlyQuoteFieldHeight( 0 );
   755     if ( iReadOnlyQuoteField->TextLength() )
   777     if ( iReadOnlyQuoteField->TextLength() )
   757         TInt dummySeparatorPos;
   779         TInt dummySeparatorPos;
   758         NcsUtility::LayoutBodyEdwin(
   780         NcsUtility::LayoutBodyEdwin(
   759                 iReadOnlyQuoteField, cmailPaneRect, 
   781                 iReadOnlyQuoteField, cmailPaneRect, 
   760                 iHeader->LayoutLineCount() + iMessageField->LineCount(), 
   782                 iHeader->LayoutLineCount() + iMessageField->LineCount(), 
   761                 iReadOnlyQuoteField->LineCount(), dummySeparatorPos );
   783                 iReadOnlyQuoteField->LineCount(), dummySeparatorPos );
   762         TRAP_IGNORE( iReadOnlyQuoteField->FormatAllTextNowL() );
   784         // we don't need format again when format was already done
       
   785 		// during creation of forward/reply message
       
   786         if ( !iSwitchOffFormattingText )
       
   787             {
       
   788             TRAP_IGNORE( iReadOnlyQuoteField->FormatAllTextNowL() );
       
   789             }
   763         iReadOnlyQuoteField->UpdateFontSize();
   790         iReadOnlyQuoteField->UpdateFontSize();
   764         readOnlyQuoteFieldHeight = iReadOnlyQuoteField->Rect().Height();
   791         readOnlyQuoteFieldHeight = iReadOnlyQuoteField->Rect().Height();
   765         }
   792         }
   766 
   793 
   767     iBgContext->SetRect( Rect() );
   794     iBgContext->SetRect( Rect() );
   780     if ( iMessageEditorMinHeigth > messageLineHeigth )
   807     if ( iMessageEditorMinHeigth > messageLineHeigth )
   781         {
   808         {
   782         TSize newSize( iMessageField->Size().iWidth,
   809         TSize newSize( iMessageField->Size().iWidth,
   783                        Max( iMessageField->Size().iHeight, 
   810                        Max( iMessageField->Size().iHeight, 
   784                             iMessageEditorMinHeigth ) );
   811                             iMessageEditorMinHeigth ) );
   785             
   812 
   786         iMessageField->SetSize( newSize );
   813         if ( !iSwitchOffFormattingText ) 
       
   814             {
       
   815             iMessageField->SetSize( newSize );
       
   816             }
   787         }
   817         }
   788     else
   818     else
   789         {
   819         {
   790         iMessageEditorMinHeigth = messageLineHeigth;
   820         iMessageEditorMinHeigth = messageLineHeigth;
   791         }
   821         }
   860     iReadOnlyQuoteField->ActivateL();
   890     iReadOnlyQuoteField->ActivateL();
   861     iReadOnlyQuoteField->SetCursorPosL( 0, EFalse );
   891     iReadOnlyQuoteField->SetCursorPosL( 0, EFalse );
   862 
   892 
   863     // Recalculate the size of the body field
   893     // Recalculate the size of the body field
   864     SizeChanged();
   894     SizeChanged();
       
   895     }
       
   896 
       
   897 // -----------------------------------------------------------------------------
       
   898 // CNcsComposeViewContainer::SetBodyContentAsyncL()
       
   899 // -----------------------------------------------------------------------------
       
   900 //
       
   901 void CNcsComposeViewContainer::SetBodyContentAsyncL( const TDesC& aMessage,
       
   902     const TDesC& aReadOnlyQuote )
       
   903     {
       
   904     FUNC_LOG;
       
   905     delete iReadOnlyQuote;
       
   906     iReadOnlyQuote = NULL;
       
   907     if ( aReadOnlyQuote.Length() )
       
   908         {
       
   909         iReadOnlyQuote = aReadOnlyQuote.AllocL();
       
   910         }
       
   911 
       
   912     RMemReadStream inputStream( aMessage.Ptr(), aMessage.Size() );
       
   913     CleanupClosePushL( inputStream );
       
   914     iMessageField->RichText()->ImportTextL( 0, inputStream,
       
   915         CPlainText::EOrganiseByParagraph );
       
   916     CleanupStack::PopAndDestroy( &inputStream );
       
   917     
       
   918 
       
   919     // Activating the field will set the control to the end of the text
       
   920     iMessageField->ActivateL();
       
   921     iMessageField->SetCursorPosL( 0, EFalse );
       
   922     
       
   923     iProcessedField = iMessageField;
       
   924     
       
   925 	iAsyncTextFormatter = CFSAsyncTextFormatter::NewL();
       
   926     iAsyncTextFormatter->StartFormatting( iMessageField->TextLayout(), this );
       
   927         
       
   928     // callback from AO: FormatAllTextCompleteL
       
   929 }
       
   930 
       
   931 // -----------------------------------------------------------------------------
       
   932 // CNcsComposeViewContainer::FormatAllTextCancelled()
       
   933 // -----------------------------------------------------------------------------
       
   934 //
       
   935 void CNcsComposeViewContainer::FormatAllTextCancelled()
       
   936 	{
       
   937 	iView.SetBodyContentComplete();
       
   938 	}
       
   939 
       
   940 // -----------------------------------------------------------------------------
       
   941 // CNcsComposeViewContainer::FormatAllTextComplete()
       
   942 // -----------------------------------------------------------------------------
       
   943 //
       
   944 void CNcsComposeViewContainer::FormatAllTextComplete()
       
   945 	{
       
   946     if ( iReadOnlyQuote && iProcessedField == iMessageField )
       
   947         {
       
   948         iProcessedField = iReadOnlyQuoteField;
       
   949         if ( iReadOnlyQuote )
       
   950             {
       
   951 			TInt dummySeparatorPos;
       
   952 			NcsUtility::LayoutBodyEdwin( iReadOnlyQuoteField, iCmailPaneRect, 
       
   953 					iHeader->LayoutLineCount() + iMessageField->LineCount(),
       
   954 					iReadOnlyQuoteField->LineCount(), dummySeparatorPos );
       
   955 	
       
   956 			RMemReadStream inputStream;
       
   957             inputStream.Open( iReadOnlyQuote->Ptr(), iReadOnlyQuote->Size() );
       
   958             TRAP_IGNORE( iReadOnlyQuoteField->RichText()->ImportTextL( 0, inputStream,
       
   959                     CPlainText::EOrganiseByParagraph ) );
       
   960             inputStream.Close();
       
   961             
       
   962             // Activating the field will set the control to the end of the text
       
   963             TRAP_IGNORE( iReadOnlyQuoteField->ActivateL() );
       
   964             TRAP_IGNORE( iReadOnlyQuoteField->SetCursorPosL( 0, EFalse ) );
       
   965             
       
   966             if ( !iAsyncTextFormatter )
       
   967                 {
       
   968                 TRAP_IGNORE( iAsyncTextFormatter = CFSAsyncTextFormatter::NewL() );
       
   969                 }
       
   970             iAsyncTextFormatter->StartFormatting( 
       
   971                     iReadOnlyQuoteField->TextLayout(), this );
       
   972             }
       
   973         }
       
   974     else
       
   975         {
       
   976         // Recalculate the size of the body field
       
   977         iSwitchOffFormattingText = ETrue;
       
   978         SizeChanged();
       
   979         iSwitchOffFormattingText = EFalse;
       
   980         
       
   981         iView.SetBodyContentComplete();
       
   982         }
   865     }
   983     }
   866 
   984 
   867 // -----------------------------------------------------------------------------
   985 // -----------------------------------------------------------------------------
   868 // CNcsComposeViewContainer::GetBodyContentLC()
   986 // CNcsComposeViewContainer::GetBodyContentLC()
   869 // -----------------------------------------------------------------------------
   987 // -----------------------------------------------------------------------------
  1040 
  1158 
  1041     if ( aEdwin == iMessageField ) 
  1159     if ( aEdwin == iMessageField ) 
  1042         {
  1160         {
  1043         if ( aDesirableEdwinSize.iHeight >= iMessageEditorMinHeigth )
  1161         if ( aDesirableEdwinSize.iHeight >= iMessageEditorMinHeigth )
  1044             {
  1162             {
       
  1163             if ( !iSwitchOffFormattingText )
       
  1164                 {
       
  1165                 aEdwin->SetSize( aDesirableEdwinSize );
       
  1166                 }
       
  1167             }        
       
  1168         }
       
  1169     else
       
  1170         {
       
  1171         if ( !iSwitchOffFormattingText )
       
  1172             {
  1045             aEdwin->SetSize( aDesirableEdwinSize );
  1173             aEdwin->SetSize( aDesirableEdwinSize );
  1046             }        
  1174             }
  1047         }
       
  1048     else
       
  1049         {
       
  1050         aEdwin->SetSize( aDesirableEdwinSize );
       
  1051         }
  1175         }
  1052     if ( aEdwin == iMessageField )
  1176     if ( aEdwin == iMessageField )
  1053         {
  1177         {
  1054         // move the quote field below the body field
  1178         // move the quote field below the body field
  1055         TPoint quotePos = iMessageField->Position();
  1179         TPoint quotePos = iMessageField->Position();
  1964     const TPoint& aNewPosition, TBool aDrawNow, TUint /*aFlags*/ )
  2088     const TPoint& aNewPosition, TBool aDrawNow, TUint /*aFlags*/ )
  1965     {
  2089     {
  1966     FUNC_LOG;
  2090     FUNC_LOG;
  1967     TInt scrollOffset = aNewPosition.iY - iVisibleAreaHeight / 2;
  2091     TInt scrollOffset = aNewPosition.iY - iVisibleAreaHeight / 2;
  1968 
  2092 
  1969 	// when the composer view is overlapped by other view for instance task switcher or screensaver
  2093     // when the composer view is overlapped by other view for instance task switcher or screensaver
  1970 	// physics sends a faulty event to move the composer view down. 
  2094     // physics sends a faulty event to move the composer view down. 
  1971 	// This action is ignored here.	
  2095     // This action is ignored here.	
  1972 	if (aNewPosition.iY != 0)
  2096     if (aNewPosition.iY != 0)
  1973 		{    	
  2097         {
  1974     Scroll( scrollOffset, aDrawNow );
  2098         Scroll( scrollOffset, aDrawNow );
  1975     }
  2099         }
  1976 	}
  2100     }
  1977 
  2101 
  1978 // -----------------------------------------------------------------------------
  2102 // -----------------------------------------------------------------------------
  1979 // CNcsComposeViewContainer::PhysicEmulationEnded
  2103 // CNcsComposeViewContainer::PhysicEmulationEnded
  1980 // From MAknPhysicsObserver
  2104 // From MAknPhysicsObserver
  1981 // -----------------------------------------------------------------------------
  2105 // -----------------------------------------------------------------------------
  2008 TBool CNcsComposeViewContainer::IsRemoteSearchInprogress() const
  2132 TBool CNcsComposeViewContainer::IsRemoteSearchInprogress() const
  2009     {
  2133     {
  2010     FUNC_LOG;
  2134     FUNC_LOG;
  2011     return iHeader->IsRemoteSearchInprogress();
  2135     return iHeader->IsRemoteSearchInprogress();
  2012     }
  2136     }
  2013 
       
  2014 // -----------------------------------------------------------------------------
       
  2015 // CNcsComposeViewContainer::DoUpdateSubjectL
       
  2016 // -----------------------------------------------------------------------------
       
  2017 //
       
  2018 void CNcsComposeViewContainer::DoUpdateSubjectL()
       
  2019     {
       
  2020     FUNC_LOG;
       
  2021     // fix for ESLX-7Y4C2V, dissapearing subject
       
  2022     // get copy of subject
       
  2023     HBufC* subjectCopy = GetSubjectLC();
       
  2024     iHeader->SetFocus( EFalse, EDrawNow );
       
  2025     // get subject after focus lost
       
  2026     HBufC* subject = GetSubjectLC();
       
  2027     // restore subject from copy if necessary
       
  2028     if ( subject->Length() != subjectCopy->Length() )
       
  2029         {
       
  2030         iHeader->SetSubjectL( *subjectCopy );
       
  2031         }
       
  2032 
       
  2033     // restore focus
       
  2034     iHeader->SetFocus( ETrue, EDrawNow );
       
  2035     CleanupStack::PopAndDestroy( 2, subjectCopy );
       
  2036     }